openrouter

The openrouter provider offers native integration with OpenRouter, a unified API gateway providing access to 300+ AI models from OpenAI, Anthropic, Google, Meta, and others through a single interface.

Example:

BAML
1client<llm> MyClient {
2 provider openrouter
3 options {
4 model "openai/gpt-4o-mini"
5 }
6}

You can also use openai-generic with OpenRouter by manually setting the base_url. The openrouter provider simplifies this by providing sensible defaults.

OpenRouter-specific options

The openrouter provider extends openai-generic with OpenRouter-specific defaults. See openai-generic for the full list of supported options.

api_key
string

Default: env.OPENROUTER_API_KEY

base_url
string

Default: https://openrouter.ai/api/v1

model
stringRequired

The model to use, in OpenRouter’s provider/model-name format.

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

OpenRouter supports model variants for routing preferences (e.g., :nitro for high-throughput):

BAML
1client<llm> NitroClient {
2 provider openrouter
3 options {
4 model "meta-llama/llama-3.1-70b-instruct:nitro"
5 }
6}

For the complete list, see OpenRouter Models.

App attribution headers

OpenRouter supports optional headers for app attribution. Pass these via the headers option:

HeaderDescription
X-TitleYour app name, shown on openrouter.ai rankings
HTTP-RefererYour site URL for rankings and attribution
BAML
1client<llm> OpenRouterWithAttribution {
2 provider openrouter
3 options {
4 model "anthropic/claude-3-haiku"
5 headers {
6 "X-Title" "My App"
7 "HTTP-Referer" "https://myapp.com"
8 }
9 }
10}

For all other options (temperature, max_tokens, headers, etc.), see openai-generic and the OpenRouter API documentation.