For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Help on Discord
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
    • Overview
  • baml-cli
    • init
    • generate
    • test
    • serve
    • dev
    • fmt
  • Language Reference
    • Types
    • function
    • test
    • template_string
    • client<llm>
    • class
    • enum
    • generator
  • Generated baml_client
    • with_options(..)
    • AbortSignal / Cancellation
    • Collector
    • logging / env vars
    • AsyncClient / SyncClient
    • TypeBuilder
    • ClientRegistry
    • client Option
    • OnTick
    • Multimodal
    • Image
    • Audio
    • Pdf
    • Video
  • Attributes
    • What are attributes?
    • @alias / @@alias
    • @description / @@description
    • @skip
    • @assert
    • @check
    • Jinja in Attributes
    • @@dynamic
  • LLM Client Providers
    • Overview
    • AWS Bedrock
    • Anthropic
    • Google AI: Gemini
    • Google: Vertex
    • OpenAI
    • OpenAI Responses API
    • OpenAI from Azure
    • OpenRouter
    • openai-generic
    • Microsoft Foundry (openai-generic)
    • Cerebras (openai-generic)
    • Groq (openai-generic)
    • Hugging Face (openai-generic)
    • Keywords AI (openai-generic)
    • Llama API (openai-generic)
    • Litellm (openai-generic)
    • LM Studio (openai-generic)
    • Ollama (openai-generic)
    • Vercel AI Gateway (openai-generic)
    • Tinfoil (openai-generic)
    • TogetherAI (openai-generic)
    • Unify AI (openai-generic)
    • vLLM (openai-generic)
  • LLM Client Strategies
    • Timeout Configuration
    • Retry Policy
    • Fallback
    • Round Robin
  • Prompt Syntax
    • What is jinja?
    • Jinja Filters
    • ctx.output_format
    • ctx.client
    • _.role
    • Variables
    • Conditionals
    • Loops
  • Editor Extension Settings
    • baml.cliPath
    • baml.generateCodeOnSave
    • baml.enablePlaygroundProxy
    • baml.syncExtensionToGeneratorVersion
Help on Discord
LogoLogo
On this page
  • Usage Examples
  • API Reference
  • Static Methods
  • Instance Methods
  • Static Methods
  • Instance Methods
  • Static Methods
  • Instance Methods
  • Static Methods
  • URL Handling
Generated baml_client

Image

Was this page helpful?
Edit this page
Previous

Audio

Next
Built with

Image values to BAML functions can be created in client libraries. This document explains how to use these functions both at compile time and runtime to handle image data. For more details, refer to image types.

Usage Examples

1from baml_py import Image
2from baml_client import b
3
4async def test_image_input():
5 # Create an Image from a URL
6 img = Image.from_url("https://upload.wikimedia.org/wikipedia/en/4/4d/Shrek_%28character%29.png")
7 res = await b.TestImageInput(img=img)
8
9 # Create an Image from Base64 data
10 image_b64 = "iVB0xyz..."
11 img = Image.from_base64("image/png", image_b64)
12 res = await b.TestImageInput(img=img)

API Reference

Python
TypeScript
Go
Rust
Ruby

Static Methods

from_url
(url: str, media_type: Optional[str] = None) -> Image

Creates an Image object from a URL. Optionally specify the media type, otherwise it will be inferred from the URL.

from_base64
(media_type: str, base64: str) -> Image

Creates an Image object using Base64 encoded data along with the given MIME type.

Instance Methods

is_url
() -> bool

Check if the image is stored as a URL.

as_url
() -> str

Get the URL of the image if it’s stored as a URL. Raises an exception if the image is not stored as a URL.

as_base64
() -> list[str]

Get the base64 data and media type if the image is stored as base64. Returns [base64_data, media_type]. Raises an exception if the image is not stored as base64.

baml_serialize
() -> dict

Convert the image to a dictionary representation. Returns either {"url": str} or {"base64": str, "media_type": str}.

URL Handling

When you create an Image using from_url, BAML processes the URL according to your client’s media_url_handler configuration:

  • OpenAI: By default keeps URLs as-is (send_url). Set to send_base64 to convert to base64.
  • Anthropic: By default keeps URLs as-is (send_url). The provider accepts both formats.
  • Google AI: By default uses send_base64_unless_google_url to preserve gs:// URLs while converting others.
  • Vertex AI: By default uses send_url_add_mime_type to include MIME type information.
  • AWS Bedrock: By default converts to base64 (send_base64).

You can override these defaults in your client configuration. See the provider-specific documentation linked above for details.