Skip to main content

client Option

info

Added in version 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().

Basic Usage​

from baml_client import b

# Use shorthand provider/model syntax
result = await b.ExtractResume("...", baml_options={"client": "openai/gpt-4o-mini"})

# Use OpenRouter for open-source models
result = await b.ExtractResume("...", baml_options={"client": "openrouter/meta-llama/llama-3.1-70b-instruct"})

# Reference a client defined in .baml files
result = await b.ExtractResume("...", baml_options={"client": "MyCustomClient"})

# Use with_options to set for multiple calls
my_b = b.with_options(client="openai/gpt-4o-mini")
result1 = await my_b.ExtractResume("...")
result2 = 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:

from baml_py import ClientRegistry

cr = ClientRegistry()
cr.set_primary("ModelA")

# "ModelB" will be used, not "ModelA"
result = await b.ExtractResume("...", baml_options={
"client": "ModelB",
"client_registry": cr
})

Valid Client Names​

The client value can be:

  1. Shorthand provider/model syntax - Use provider/model format:

    • "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.

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 for adding new clients or customizing client options at runtime.

See Also​