> Version notice: This site documents BAML v0, the legacy DSL. BAML v1 is a separate, fully featured programming language in public beta. If the user intends to use BAML v1, ignore this site's content and use the BAML v1 documentation instead. If the intended version is unclear, clarify it before using this page.
> For clean Markdown of any page, append .md to the page URL. For the complete documentation index, see https://docs.boundaryml.com/llms.txt. For MCP access, connect to https://docs.boundaryml.com/_mcp/server.

# openrouter

The `openrouter` provider offers native integration with [OpenRouter](https://openrouter.ai), a unified API gateway providing access to 300+ AI models from OpenAI, Anthropic, Google, Meta, and others through a single interface.

Example:

**`BAML`**

```baml BAML
client<llm> MyClient {
  provider openrouter
  options {
    model "openai/gpt-4o-mini"
  }
}
```

> **Note**
>
> You can also use [`openai-generic`](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`](openai-generic) with OpenRouter-specific defaults. See [`openai-generic`](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`** `string` — required

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

| 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-3.5-flash`           | Gemini 3.5 Flash     |
| `meta-llama/llama-3.1-70b-instruct` | Llama 3.1 70B        |

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

**`BAML`**

```baml BAML
client<llm> NitroClient {
  provider openrouter
  options {
    model "meta-llama/llama-3.1-70b-instruct:nitro"
  }
}
```

For the complete list, see [OpenRouter Models](https://openrouter.ai/models).

---

## App attribution headers

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

| Header         | Description                                    |
| -------------- | ---------------------------------------------- |
| `X-Title`      | Your app name, shown on openrouter.ai rankings |
| `HTTP-Referer` | Your site URL for rankings and attribution     |

**`BAML`**

```baml BAML
client<llm> OpenRouterWithAttribution {
  provider openrouter
  options {
    model "anthropic/claude-3-haiku"
    headers {
      "X-Title" "My App"
      "HTTP-Referer" "https://myapp.com"
    }
  }
}
```

For all other options (`temperature`, `max_tokens`, `headers`, etc.), see [`openai-generic`](openai-generic) and the [OpenRouter API documentation](https://openrouter.ai/docs/api/reference/overview).