For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Help on Discord
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
    • Overview
  • baml-cli
    • init
    • generate
    • test
    • serve
    • dev
    • fmt
  • Language Reference
    • Types
    • function
    • test
    • template_string
    • client<llm>
    • class
    • enum
    • generator
  • Generated baml_client
    • with_options(..)
    • AbortSignal / Cancellation
    • Collector
    • logging / env vars
    • AsyncClient / SyncClient
    • TypeBuilder
    • ClientRegistry
    • client Option
    • OnTick
    • Multimodal
    • Image
    • Audio
    • Pdf
    • Video
  • Attributes
    • What are attributes?
    • @alias / @@alias
    • @description / @@description
    • @skip
    • @assert
    • @check
    • Jinja in Attributes
    • @@dynamic
  • LLM Client Providers
    • Overview
    • AWS Bedrock
    • Anthropic
    • Google AI: Gemini
    • Google: Vertex
    • OpenAI
    • OpenAI Responses API
    • OpenAI from Azure
    • OpenRouter
    • openai-generic
    • Microsoft Foundry (openai-generic)
    • Cerebras (openai-generic)
    • Groq (openai-generic)
    • Hugging Face (openai-generic)
    • Keywords AI (openai-generic)
    • Llama API (openai-generic)
    • Litellm (openai-generic)
    • LM Studio (openai-generic)
    • Ollama (openai-generic)
    • Vercel AI Gateway (openai-generic)
    • Tinfoil (openai-generic)
    • TogetherAI (openai-generic)
    • Unify AI (openai-generic)
    • vLLM (openai-generic)
  • LLM Client Strategies
    • Timeout Configuration
    • Retry Policy
    • Fallback
    • Round Robin
  • Prompt Syntax
    • What is jinja?
    • Jinja Filters
    • ctx.output_format
    • ctx.client
    • _.role
    • Variables
    • Conditionals
    • Loops
  • Editor Extension Settings
    • baml.cliPath
    • baml.generateCodeOnSave
    • baml.enablePlaygroundProxy
    • baml.syncExtensionToGeneratorVersion
Help on Discord
LogoLogo
On this page
  • OpenRouter-specific options
  • App attribution headers
LLM Client Providers

openrouter

Was this page helpful?
Edit this page
Previous

openai-generic

Next
Built with

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.