Skip to main content

Media Types

BAML functions can accept image, audio, PDF, and video inputs for multimodal processing. Create media objects from URLs, base64 data, or browser-specific sources.

Overview​

TypeUse Case
ImageImage analysis, OCR, visual question answering
AudioTranscription, audio analysis
PdfDocument analysis, extraction
VideoVideo understanding (Google, Vertex, Bedrock only)

Image​

from baml_py import Image
from baml_client import b

# From URL
img = Image.from_url("https://example.com/image.png")
res = await b.AnalyzeImage(img=img)

# From Base64
img = Image.from_base64("image/png", "iVB0xyz...")
res = await b.AnalyzeImage(img=img)

Image API​

MethodTypeDescription
from_url(url, media_type?)StaticCreate from URL
from_base64(media_type, base64)StaticCreate from Base64
fromFile(file)Static (Browser)Create from File object
fromBlob(blob, media_type?)Static (Browser)Create from Blob
is_url()InstanceCheck if stored as URL
as_url()InstanceGet URL (throws if not URL)
as_base64()InstanceGet [base64, media_type]

Audio​

from baml_py import Audio
from baml_client import b

# From URL
audio = Audio.from_url("https://example.com/audio.ogg")
res = await b.TranscribeAudio(audio=audio)

# From Base64
audio = Audio.from_base64("audio/ogg", "iVB0xyz...")
res = await b.TranscribeAudio(audio=audio)

Audio API​

MethodTypeDescription
from_url(url, media_type?)StaticCreate from URL
from_base64(media_type, base64)StaticCreate from Base64
fromFile(file)Static (Browser)Create from File object
fromBlob(blob, media_type?)Static (Browser)Create from Blob
is_url()InstanceCheck if stored as URL
as_url()InstanceGet URL (throws if not URL)
as_base64()InstanceGet [base64, media_type]

PDF​

warning

Some models require PDFs in the user message, not system. Many websites block direct PDF fetching.

from baml_py import Pdf
from baml_client import b

# From URL
pdf = Pdf.from_url("https://example.com/document.pdf")
res = await b.AnalyzePdf(pdf=pdf)

# From Base64
pdf = Pdf.from_base64("JVBERi0K...")
res = await b.AnalyzePdf(pdf=pdf)

Testing PDFs in Playground​

function AnalyzePdf(myPdf: pdf) -> string {
client GPT4o
prompt #"
Summarize this PDF: {{myPdf}}
"#
}

test PdfFileTest {
functions [AnalyzePdf]
args {
myPdf {
file "../documents/report.pdf"
}
}
}

PDF API​

MethodTypeDescription
from_url(url)StaticCreate from URL
from_base64(base64)StaticCreate from Base64
fromFile(file)Static (Browser)Create from File object
fromBlob(blob)Static (Browser)Create from Blob
is_url()InstanceCheck if stored as URL
as_url()InstanceGet URL (throws if not URL)
as_base64()InstanceGet [base64, media_type]

Video​

warning

Direct video input is only supported by Google Gemini, Google Vertex AI, and AWS Bedrock. Other providers require frame extraction or transcripts.

from baml_py import Video
from baml_client import b

# From URL
video = Video.from_url("https://example.com/video.mp4")
res = await b.AnalyzeVideo(video=video)

# From Base64
video = Video.from_base64("video/mp4", "AAAAGGZ0eXBpc29t...")
res = await b.AnalyzeVideo(video=video)

# S3 for AWS Bedrock
bedrock_video = Video.from_url(
"s3://bucket/path/video.mp4", media_type="video/mp4"
)
res = await b.TestAwsVideoDescribe(video_input=bedrock_video)

Video API​

MethodTypeDescription
from_url(url, media_type?)StaticCreate from URL
from_base64(media_type, base64)StaticCreate from Base64
fromFile(file)Static (Browser)Create from File object
fromBlob(blob, media_type?)Static (Browser)Create from Blob
is_url()InstanceCheck if stored as URL
as_url()InstanceGet URL (throws if not URL)
as_base64()InstanceGet [base64, media_type]

URL Handling​

BAML automatically handles URL-to-base64 conversion based on provider requirements. Configure via media_url_handler in client options.

Default Behavior by Provider​

ProviderImageAudioPDFVideo
OpenAIsend_urlsend_base64send_urlsend_url
Anthropicsend_urlsend_urlsend_base64send_url
Google AIsend_base64_unless_google_urlsend_urlsend_urlsend_url
Vertex AIsend_url_add_mime_typesend_url_add_mime_typesend_urlsend_url
AWS Bedrocksend_base64send_base64send_base64send_url

Custom Configuration​

client<llm> MyClient {
provider openai
options {
model "gpt-4o"
api_key env.OPENAI_API_KEY
media_url_handler {
image "send_base64"
audio "send_url"
pdf "send_base64"
video "send_url"
}
}
}

Available Modes​

  • send_base64 - Fetch and convert to base64
  • send_url - Keep URL as-is
  • send_url_add_mime_type - Keep URL, add MIME type info
  • send_base64_unless_google_url - Keep gs:// URLs, convert others

Model Compatibility​

PDF Support​

ProviderSupportNotes
AnthropicYesURL or base64
AWS BedrockYesBase64 or S3 URI only
Google GeminiYesBase64 or file upload
OpenAIYesBase64 only (since March 2025)
Vertex AIYesBase64 or gs:// URI

Video Support​

ProviderSupportNotes
AnthropicNoUse frame extraction
AWS BedrockYesBase64 or S3 URI
Google GeminiYesBase64, file upload, or YouTube URL
OpenAINoUse frame extraction
Vertex AIYesgs:// URI, HTTP URL, YouTube, or base64

See Also​