Skip to main content

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​

OptionTypeDefaultDescription
api_keystringenv.OPENROUTER_API_KEYAPI key
base_urlstringhttps://openrouter.ai/api/v1API base URL
modelstring(required)Model in provider/model-name format

Available Models​

ModelDescription
openai/gpt-4o-miniFast, cost-effective
anthropic/claude-3.5-sonnetClaude 3.5 Sonnet
anthropic/claude-3-haikuFast Claude variant
google/gemini-2.0-flash-001Gemini 2.0 Flash
meta-llama/llama-3.1-70b-instructLlama 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:

HeaderDescription
X-TitleApp name for openrouter.ai rankings
HTTP-RefererSite URL for rankings
client<llm> OpenRouterWithAttribution {
provider openrouter
options {
model "anthropic/claude-3-haiku"
headers {
"X-Title" "My App"
"HTTP-Referer" "https://myapp.com"
}
}
}

See Also​