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
  • Quick Start
  • When to Use
  • Precedence
  • Valid Client Names
  • Comparison with ClientRegistry
  • Related Topics
Generated baml_client

client Option

Was this page helpful?
Edit this page
Previous

OnTick

Next
Built with

Added in 0.216.0

The client option provides a simple way to override which LLM client a function uses at runtime. It’s a shorthand for creating a ClientRegistry and calling set_primary().

Quick Start

Python
TypeScript
Go
Rust
1from baml_client import b
2
3# Use shorthand provider/model syntax
4result = await b.ExtractResume("...", baml_options={"client": "openai/gpt-4o-mini"})
5
6# Use OpenRouter for open-source models
7result = await b.ExtractResume("...", baml_options={"client": "openrouter/meta-llama/llama-3.1-70b-instruct"})
8
9# Or reference a client defined in your .baml files
10result = await b.ExtractResume("...", baml_options={"client": "MyCustomClient"})
11
12# Use with_options to set for multiple calls
13my_b = b.with_options(client="openai/gpt-4o-mini")
14result1 = await my_b.ExtractResume("...")
15result2 = await my_b.ExtractInvoice("...")

When to Use

Use the client option when you want to:

  • Quickly switch between different LLM providers or models
  • A/B test different models
  • Use different clients for different environments (dev vs prod)
  • Override the default client defined in your .baml files

Precedence

If you provide both client and client_registry, the client option takes precedence:

Python
TypeScript
Go
Rust
1from baml_py import ClientRegistry
2
3cr = ClientRegistry()
4cr.set_primary("ModelA")
5
6# "ModelB" will be used, not "ModelA"
7result = await b.ExtractResume("...", baml_options={
8 "client": "ModelB",
9 "client_registry": cr
10})

Valid Client Names

The client value can be:

  1. Shorthand provider/model syntax - Use provider/model format for quick access:

    • "openai/gpt-4o-mini" - OpenAI models
    • "anthropic/claude-sonnet-4-20250514" - Anthropic models
    • "openrouter/meta-llama/llama-3.1-70b-instruct" - OpenRouter models
    • "google-ai/gemini-2.0-flash" - Google AI models
  2. Client defined in .baml files - Reference by name (e.g., "MyCustomClient")

If the client name is not found, you’ll get a runtime error when the function is called.

Comparison with ClientRegistry

Featureclient optionClientRegistry
Set primary clientYesYes (set_primary)
Add custom clientsNoYes (add_llm_client)
Override client optionsNoYes
SimplicitySimple stringMore complex

Use client for simple overrides. Use ClientRegistry when you need to add new clients or customize client options at runtime.

Related Topics

  • ClientRegistry - For advanced client configuration
  • with_options - Set default options for a client