cookbook/90_models/openrouter/README.md
Note: Fork and clone this repository if needed
python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate
OPENROUTER_API_KEYexport OPENROUTER_API_KEY=***
pip install -U openai agno
The chat/ folder contains examples using the OpenRouter Chat API.
# Streaming
python cookbook/90_models/openrouter/chat/basic_stream.py
# Non-streaming
python cookbook/90_models/openrouter/chat/basic.py
# Async
python cookbook/90_models/openrouter/chat/async_basic.py
# Tool use
python cookbook/90_models/openrouter/chat/tool_use.py
# Async tool use
python cookbook/90_models/openrouter/chat/async_tool_use.py
# Structured output
python cookbook/90_models/openrouter/chat/structured_output.py
python cookbook/90_models/openrouter/chat/dynamic_model_router.py
The responses/ folder contains examples using the OpenRouter Responses API (beta).
# Basic
python cookbook/90_models/openrouter/responses/basic.py
# Streaming
python cookbook/90_models/openrouter/responses/stream.py
# Async
python cookbook/90_models/openrouter/responses/async_basic.py
# Tool use
python cookbook/90_models/openrouter/responses/tool_use.py
# Structured output
python cookbook/90_models/openrouter/responses/structured_output.py
OpenRouter supports automatic fallback to alternative models if the primary model fails:
python cookbook/90_models/openrouter/responses/fallback.py