Skip to main content
Definable provides unified media classes for handling images, audio, video, and files. These work consistently across all models and agents that support multimodal input and output.

Image

from definable.media import Image

# From URL
image = Image(url="https://example.com/photo.jpg")

# From file
image = Image(filepath="/path/to/photo.png")

# From raw bytes
image = Image(content=raw_bytes, format="jpeg")

# From base64
image = Image.from_base64(base64_string, format="png")

Image Parameters

ParameterTypeDescription
urlstrImage URL
filepathstrLocal file path
contentbytesRaw image bytes
formatstrImage format (jpeg, png, gif, webp)
mime_typestrMIME type (auto-detected from format)
detailstrAnalysis detail: "low", "high", or "auto"

Image Output Fields

When a model generates an image:
FieldDescription
original_promptThe prompt used for generation
revised_promptThe revised prompt (if the model modified it)
alt_textGenerated alt text

Audio

from definable.media import Audio

# From file
audio = Audio(filepath="/path/to/recording.mp3")

# From URL
audio = Audio(url="https://example.com/audio.wav")

# From bytes
audio = Audio(content=raw_bytes, format="wav")

Audio Parameters

ParameterTypeDescription
urlstrAudio URL
filepathstrLocal file path
contentbytesRaw audio bytes
formatstrAudio format (mp3, wav, flac, ogg)
durationfloatDuration in seconds
sample_rateintSample rate in Hz
channelsintNumber of audio channels
transcriptstrText transcript (for audio output)

Video

from definable.media import Video

# From file
video = Video(filepath="/path/to/clip.mp4")

# From URL
video = Video(url="https://example.com/video.mp4")

Video Parameters

ParameterTypeDescription
urlstrVideo URL
filepathstrLocal file path
contentbytesRaw video bytes
formatstrVideo format (mp4, webm)
durationfloatDuration in seconds
widthintWidth in pixels
heightintHeight in pixels

File

from definable.media import File

# From file
file = File(filepath="/path/to/report.pdf", mime_type="application/pdf")

# From URL
file = File(url="https://example.com/data.json", mime_type="application/json")

File Parameters

ParameterTypeDescription
urlstrFile URL
filepathstrLocal file path
contentbytesRaw file bytes
mime_typestrMIME type (required for validation)
filenamestrOriginal filename
sizeintFile size in bytes
externalAnyProvider-specific file object

Common Methods

All media types share these methods:
MethodDescription
get_content_bytes()Read the content as bytes
to_base64()Encode content as base64 string
to_dict()Serialize to dictionary
from_base64(data, format)Create from base64 string

Using with Models

Pass media in messages:
response = model.invoke(messages=[{
    "role": "user",
    "content": "Describe what you see and hear.",
    "images": [Image(url="https://example.com/photo.jpg")],
    "audio": [Audio(filepath="recording.mp3")],
}])

Using with Agents

Pass media directly to agent runs:
output = agent.run(
    "Analyze this document and image.",
    images=[Image(filepath="chart.png")],
    files=[File(filepath="data.csv", mime_type="text/csv")],
)
Each media type requires exactly one content source (url, filepath, or content). Providing none or multiple sources raises a validation error. The File type additionally supports an external source for provider-specific file objects.