tbrownio
12/11/2025, 8:06 PMnikitoshina
12/11/2025, 8:15 PMpy
import os
from baml_py import ClientRegistry
# Create a new client registry
client_registry = ClientRegistry()
# Add an LLM client
client_registry.add_llm_client(
provider="openai-generic",
name="my_model_client",
options={
"model": "openai/gpt-4o-mini",
"api_key": os.getenv("OPENROUTER_API_KEY"),
"base_url": "https://openrouter.ai/api/v1",
},
)
# Set it as the primary client
client_registry.set_primary("my_model_client")
# Now use it with BAML functions
from baml_client import b
result = await b.SomeFunction(
arg="value",
baml_options=client_registry
)nikitoshina
12/11/2025, 8:16 PMnikitoshina
12/11/2025, 8:17 PMnikitoshina
12/11/2025, 8:18 PMtbrownio
12/11/2025, 8:27 PMnikitoshina
12/11/2025, 8:55 PMpy
client_registry = ClientRegistry()
baml_options = {"client_registry": client_registry}
# Switch to OpenRouterClient (defined in test.baml)
print("Using OpenRouterClient...")
client_registry.set_primary("OpenRouterClient")
result1 = await b.WriteStory(
prompt="Say hello",
baml_options=baml_options
)
print(f"Result: {result1}\n")nikitoshina
12/11/2025, 8:56 PMVaibhav (BAML 🐑)
12/11/2025, 10:47 PMset_primary on clients defined in .baml files!arindamkhaled
12/12/2025, 12:13 AManvith
12/12/2025, 2:25 AM