Back to Baml

Media Url Handler

fern/snippets/media-url-handler.mdx

0.222.02.1 KB
Original Source

media_url_handler

Controls how media URLs are processed before sending to the provider. This allows you to override the default behavior for handling images, audio, PDFs, and videos.

baml
client<llm> MyClient {
  provider openai
  options {
    media_url_handler {
      image "send_base64"                    // Options: send_base64 | send_url | send_url_add_mime_type | send_base64_unless_google_url
      audio "send_url"
      pdf "send_url_add_mime_type"
      video "send_url"
    }
  }
}

Options

Each media type can be configured with one of these modes:

  • send_base64 - Always download URLs and convert to base64 data URIs
  • send_url - Pass URLs through unchanged to the provider
  • send_url_add_mime_type - Ensure MIME type is present (may require downloading to detect)
  • send_base64_unless_google_url - Only process non-gs:// URLs (keep Google Cloud Storage URLs as-is)

Provider Defaults

If not specified, each provider uses these defaults:

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
Azure OpenAIsend_urlsend_base64send_urlsend_url

When to Use

  • Use send_base64 when your provider doesn't support external URLs and you need to embed media content
  • Use send_url when your provider handles URL fetching and you want to avoid the overhead of base64 conversion
  • Use send_url_add_mime_type when your provider requires MIME type information (e.g., Vertex AI)
  • Use send_base64_unless_google_url when working with Google Cloud Storage and want to preserve gs:// URLs
<Warning> URL fetching happens at request time and may add latency. Consider caching or pre-converting frequently used media when using `send_base64` mode. </Warning>