> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pipecat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenRouter

> LLM service implementation using OpenRouter's API with OpenAI-compatible interface

## Overview

`OpenRouterLLMService` provides access to OpenRouter's language models through an OpenAI-compatible interface. It inherits from `OpenAILLMService` and supports streaming responses, function calling, and context management with access to multiple model providers through a single API.

<CardGroup cols={2}>
  <Card title="OpenRouter LLM API Reference" icon="code" href="https://reference-server.pipecat.ai/en/latest/api/pipecat.services.openrouter.llm.html">
    Pipecat's API methods for OpenRouter integration
  </Card>

  <Card title="Example Implementation" icon="play" href="https://github.com/pipecat-ai/pipecat/blob/main/examples/function-calling/function-calling-openrouter.py">
    Complete example with function calling
  </Card>

  <Card title="OpenRouter Documentation" icon="book" href="https://openrouter.ai/docs/api-reference/chat-completion">
    Official OpenRouter API documentation and features
  </Card>

  <Card title="OpenRouter Platform" icon="microphone" href="https://openrouter.ai/">
    Access multiple model providers and manage API keys
  </Card>
</CardGroup>

## Installation

To use OpenRouter services, install the required dependencies:

```bash theme={null}
uv add "pipecat-ai[openrouter]"
```

## Prerequisites

### OpenRouter Account Setup

Before using OpenRouter LLM services, you need:

1. **OpenRouter Account**: Sign up at [OpenRouter](https://openrouter.ai/)
2. **API Key**: Generate an API key from your account dashboard
3. **Model Selection**: Choose from hundreds of available models from different providers
4. **Credits**: Add credits to your account for model usage

### Required Environment Variables

* `OPENROUTER_API_KEY`: Your OpenRouter API key for authentication

## Configuration

<ParamField path="api_key" type="str" default="None">
  OpenRouter API key for authentication. If not provided, the client will
  attempt to read from environment variables.
</ParamField>

<ParamField path="model" type="str" default="None" deprecated>
  *Deprecated in v0.0.105. Use
  `settings=OpenRouterLLMService.Settings(model=...)` instead.*
</ParamField>

<ParamField path="settings" type="OpenRouterLLMService.Settings" default="None">
  Runtime-configurable settings. See [Settings](#settings) below.
</ParamField>

<ParamField path="base_url" type="str" default="https://openrouter.ai/api/v1">
  Base URL for OpenRouter API endpoint.
</ParamField>

### Settings

Runtime-configurable settings passed via the `settings` constructor argument using `OpenRouterLLMService.Settings(...)`. These can be updated mid-conversation with `LLMUpdateSettingsFrame`. See [Service Settings](/pipecat/fundamentals/service-settings) for details.

This service uses the same settings as `OpenAILLMService`. See [OpenAI LLM Settings](/api-reference/server/services/llm/openai#settings) for the full parameter reference.

## Usage

### Basic Setup

```python theme={null}
import os
from pipecat.services.openrouter import OpenRouterLLMService

llm = OpenRouterLLMService(
    api_key=os.getenv("OPENROUTER_API_KEY"),
    model="openai/gpt-4o-2024-11-20",
)
```

### With a Different Provider Model

```python theme={null}
from pipecat.services.openrouter import OpenRouterLLMService

llm = OpenRouterLLMService(
    api_key=os.getenv("OPENROUTER_API_KEY"),
    settings=OpenRouterLLMService.Settings(
        model="anthropic/claude-sonnet-4-20250514",
        temperature=0.7,
        max_completion_tokens=1024,
    ),
)
```

## Notes

* OpenRouter model identifiers use the `provider/model` format (e.g., `openai/gpt-4o`, `anthropic/claude-sonnet-4-20250514`, `google/gemini-pro`).
* When using Gemini models through OpenRouter, the service automatically handles the constraint that only one system message is allowed by converting additional system messages to user messages.

<Tip>
  The `InputParams` / `params=` pattern is deprecated as of v0.0.105. Use
  `Settings` / `settings=` instead. See the [Service Settings
  guide](/pipecat/fundamentals/service-settings) for migration details.
</Tip>
