client Option

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

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:

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.