OpenRouter
The openrouter provider offers native integration with OpenRouter, providing access to 300+ AI models through a unified API.
Basic Example
client<llm> MyClient {
provider openrouter
options {
model "openai/gpt-4o-mini"
}
}
note
You can also use openai-generic with OpenRouter by manually setting the base_url. The openrouter provider simplifies this with sensible defaults.
BAML-Specific Options
| Option | Type | Default | Description |
|---|---|---|---|
api_key | string | env.OPENROUTER_API_KEY | API key |
base_url | string | https://openrouter.ai/api/v1 | API base URL |
model | string | (required) | Model in provider/model-name format |
Available Models
| Model | Description |
|---|---|
openai/gpt-4o-mini | Fast, cost-effective |
anthropic/claude-3.5-sonnet | Claude 3.5 Sonnet |
anthropic/claude-3-haiku | Fast Claude variant |
google/gemini-2.0-flash-001 | Gemini 2.0 Flash |
meta-llama/llama-3.1-70b-instruct | Llama 3.1 70B |
See OpenRouter Models for the complete list.
Model Variants
OpenRouter supports routing variants (e.g., :nitro for high-throughput):
client<llm> NitroClient {
provider openrouter
options {
model "meta-llama/llama-3.1-70b-instruct:nitro"
}
}
App Attribution
OpenRouter supports headers for app attribution:
| Header | Description |
|---|---|
X-Title | App name for openrouter.ai rankings |
HTTP-Referer | Site URL for rankings |
client<llm> OpenRouterWithAttribution {
provider openrouter
options {
model "anthropic/claude-3-haiku"
headers {
"X-Title" "My App"
"HTTP-Referer" "https://myapp.com"
}
}
}