Switching Between LLM Models
BAML supports getting structured output from all major LLM providers and OpenAI-API compatible open-source models. This guide shows you how to switch between different models and providers.Quick Switching with Inline Syntax
The fastest way to switch models is using the inlineclient syntax:
openai/*requiresOPENAI_API_KEYanthropic/*requiresANTHROPIC_API_KEYgoogle-ai/*requiresGOOGLE_API_KEY
Supported Inline Providers
Named Clients for Customization
For more control over model parameters, define named clients:Common Client Options
Runtime Client Selection
Switch models at runtime using the Client Registry:- Python
- TypeScript
Simple Client Override
For quick overrides without creating a full ClientRegistry:Comparing Model Performance
Test multiple models with the same prompt:Model Selection Best Practices
Begin development with a fast, inexpensive model like
gpt-5-mini to iterate quickly on your prompts.Combine multiple models for reliability (see retries and fallbacks).
Provider-Specific Features
OpenAI Responses API
Use the Responses API for improved structured outputs:Anthropic Prompt Caching
Enable prompt caching for cost savings:Custom Headers
Add provider-specific headers:Next Steps
- Learn about streaming responses for real-time feedback
- Set up retries and fallbacks for production resilience
- Explore error handling strategies