Image / Audio / Pdf / Video

Media values as denoted more specifically in BAML.

Baml Type
image
audio
pdf
video

All media type values can be:

  • A URL
  • A base64 encoded string
  • A file path

For usage in Python / Typescript / etc, see baml_client > media.

Usage as a URL

1// Pass in an image type
2function DescribeImage(image: image) -> string {
3 client "openai/gpt-5-mini"
4 prompt #"
5 Describe the image.
6 {{ image }}
7 "#
8}
9
10test ImageDescriptionFromURL {
11 functions [DescribeImage]
12 args {
13 image {
14 url "https://upload.wikimedia.org/wikipedia/en/4/4d/Shrek_%28character%29.png"
15 }
16 }
17}
18
19test ImageDescriptionFromBase64 {
20 functions [DescribeImage]
21 args {
22 image {
23 media_type "image/png"
24 base64 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x/AAzmH+UlvRkwAAAAASUVORK5CYII="
25 }
26 }
27}
28
29test ImageDescriptionFromFile {
30 functions [DescribeImage]
31 args {
32 image {
33 file "./shrek.png"
34 }
35 }
36}
37
38## Controlling URL Processing
39
40You can control how BAML processes media URLs before sending them to providers using the `media_url_handler` configuration option:
41
42```baml
43client<llm> MyClient {
44 provider anthropic
45 options {
46 media_url_handler {
47 image "send_base64" // Convert URLs to base64
48 pdf "send_url" // Keep URLs as-is
49 }
50 }
51}

This allows you to override the default behavior for each provider and media type combination.