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

# OpenRouter

> Use OpenRouter to access multiple AI providers with PraisonAI

## Environment Variables

Setting `MODEL_NAME=openrouter/anthropic/claude-3-5-sonnet` is enough — no need to set `OPENAI_BASE_URL`. The `OPENROUTER_API_KEY` environment variable is consulted; `OPENAI_API_KEY` is **not** used as a fallback.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import os
from praisonaiagents import Agent

os.environ["MODEL_NAME"] = "openrouter/anthropic/claude-3-5-sonnet"
os.environ["OPENROUTER_API_KEY"] = "your-openrouter-key"

agent = Agent(name="Router Agent", instructions="You access multiple providers")
```

## Models

Access 100+ models through OpenRouter. Format: `openrouter/provider/model`

* **Claude**: `openrouter/anthropic/claude-3.7-sonnet`
* **GPT-4**: `openrouter/openai/gpt-4o`
* **Gemini**: `openrouter/google/gemini-2.5-flash`
* **Llama**: `openrouter/meta-llama/llama-3.3-70b-instruct`
* **DeepSeek**: `openrouter/deepseek/deepseek-chat`

## Python

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# export OPENROUTER_API_KEY=your-api-key
from praisonaiagents import Agent

agent = Agent(
    instructions="You are a helpful assistant",
    llm="openrouter/anthropic/claude-3.7-sonnet"
)
agent.start("Explain quantum computing")
```

### With Tools

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# export OPENROUTER_API_KEY=your-api-key
from praisonaiagents import Agent

def translate(text: str, language: str) -> str:
    """Translate text to another language."""
    return f"Translated '{text}' to {language}"

agent = Agent(
    instructions="You are a translation assistant",
    llm="openrouter/openai/gpt-4o",
    tools=[translate]
)
agent.start("Translate 'Hello world' to Spanish")
```

### Multi-Agent

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# export OPENROUTER_API_KEY=your-api-key
from praisonaiagents import Agent, Task, AgentTeam

researcher = Agent(
    instructions="You research topics thoroughly",
    llm="openrouter/anthropic/claude-3.7-sonnet"
)
writer = Agent(
    instructions="You write clear summaries",
    llm="openrouter/openai/gpt-4o-mini"
)

task1 = Task(description="Research blockchain technology", agent=researcher)
task2 = Task(description="Write a beginner's guide", agent=writer)

agents = AgentTeam(agents=[researcher, writer], tasks=[task1, task2])
agents.start()
```

## CLI

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export OPENROUTER_API_KEY=your-api-key

# Basic prompt
python -m praisonai "Explain AI" --llm openrouter/anthropic/claude-3.7-sonnet

# With temperature
python -m praisonai "Write a poem" --llm openrouter/openai/gpt-4o --temperature 0.9

# Run agents.yaml
python -m praisonai
```

## YAML

```yaml theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
framework: praisonai
topic: Cross-provider AI research
agents:
  researcher:
    role: Research Analyst
    goal: Find comprehensive information
    instructions: You are an expert researcher
    llm:
      model: openrouter/anthropic/claude-3.7-sonnet
    tasks:
      research_task:
        description: Research the latest AI developments
        expected_output: Detailed research report

  writer:
    role: Content Writer
    goal: Create engaging content
    instructions: You write clear and engaging content
    llm:
      model: openrouter/openai/gpt-4o-mini
    tasks:
      write_task:
        description: Write a summary of the research
        expected_output: Well-written summary article
```

## Gateway Provider (Advanced)

The `or/` alias is shorthand for OpenRouter — e.g. `llm="or/gpt-4"` equals `openrouter/gpt-4`.

For custom headers, instance reuse, or programmatic setup, use `OpenRouterProvider`:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonai.llm import OpenRouterProvider
from praisonaiagents import Agent

provider = OpenRouterProvider("gpt-4", config={
    "extra_headers": {"X-Title": "My App"},
})
agent = Agent(name="assistant", llm=provider)
```

<Note>
  For LiteLLM Proxy, Custom Gateway, auto-registration, and multi-gateway patterns, see [LLM Gateways](/docs/features/llm-gateways).
</Note>
