fern/03-reference/baml_client/client-option.mdx
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().
result = await b.ExtractResume("...", baml_options={"client": "openai/gpt-4o-mini"})
result = await b.ExtractResume("...", baml_options={"client": "openrouter/meta-llama/llama-3.1-70b-instruct"})
result = await b.ExtractResume("...", baml_options={"client": "MyCustomClient"})
my_b = b.with_options(client="openai/gpt-4o-mini") result1 = await my_b.ExtractResume("...") result2 = await my_b.ExtractInvoice("...")
</Tab>
<Tab title="TypeScript" language="typescript">
```typescript
import { b } from "baml_client"
// Use shorthand provider/model syntax
const result = await b.ExtractResume("...", { client: "openai/gpt-4o-mini" })
// Use OpenRouter for open-source models
const result2 = await b.ExtractResume("...", { client: "openrouter/meta-llama/llama-3.1-70b-instruct" })
// Or reference a client defined in your .baml files
const result3 = await b.ExtractResume("...", { client: "MyCustomClient" })
// Use withOptions to set for multiple calls
const myB = b.withOptions({ client: "openai/gpt-4o-mini" })
const res1 = await myB.ExtractResume("...")
const res2 = await myB.ExtractInvoice("...")
import ( "context" b "example.com/myproject/baml_client" )
func main() { ctx := context.Background()
// Use shorthand provider/model syntax
result, err := b.ExtractResume(ctx, "...", b.WithClient("openai/gpt-4o-mini"))
// Use OpenRouter for open-source models
result, err = b.ExtractResume(ctx, "...", b.WithClient("openrouter/meta-llama/llama-3.1-70b-instruct"))
// Or reference a client defined in your .baml files
result, err = b.ExtractResume(ctx, "...", b.WithClient("MyCustomClient"))
}
</Tab>
<Tab title="Rust" language="rust">
```rust
use myproject::baml_client::sync_client::B;
fn main() {
// Use shorthand provider/model syntax
let result = B.ExtractResume
.with_client("openai/gpt-4o-mini")
.call("...")
.unwrap();
// Use OpenRouter for open-source models
let result = B.ExtractResume
.with_client("openrouter/meta-llama/llama-3.1-70b-instruct")
.call("...")
.unwrap();
// Or reference a client defined in your .baml files
let result = B.ExtractResume
.with_client("MyCustomClient")
.call("...")
.unwrap();
}
Use the client option when you want to:
.baml filesIf you provide both client and client_registry, the client option takes precedence:
cr = ClientRegistry() cr.set_primary("ModelA")
result = await b.ExtractResume("...", baml_options={ "client": "ModelB", "client_registry": cr })
</Tab>
<Tab title="TypeScript" language="typescript">
```typescript
import { ClientRegistry } from "@boundaryml/baml"
const cr = new ClientRegistry()
cr.setPrimary("ModelA")
// "ModelB" will be used, not "ModelA"
const result = await b.ExtractResume("...", {
client: "ModelB",
clientRegistry: cr
})
cr := baml.NewClientRegistry() cr.SetPrimaryClient("ModelA")
// "ModelB" will be used, not "ModelA" result, err := b.ExtractResume(ctx, "...", b.WithClient("ModelB"), b.WithClientRegistry(cr))
</Tab>
<Tab title="Rust" language="rust">
```rust
use baml::ClientRegistry;
use myproject::baml_client::sync_client::B;
let mut registry = ClientRegistry::new();
registry.set_primary_client("ModelA");
// "ModelB" will be used, not "ModelA"
let result = B.ExtractResume
.with_client("ModelB")
.with_client_registry(®istry)
.call("...")
.unwrap();
The client value can be:
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 modelsClient 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.
| Feature | client option | ClientRegistry |
|---|---|---|
| Set primary client | Yes | Yes (set_primary) |
| Add custom clients | No | Yes (add_llm_client) |
| Override client options | No | Yes |
| Simplicity | Simple string | More complex |
Use client for simple overrides. Use ClientRegistry when you need to add new clients or customize client options at runtime.