- A single agent running on an OpenRouter model.
- A group chat where agents on different OpenRouter models discuss a topic.
- A concurrent workflow that fans the same task out to several OpenRouter models at once.
Installation
Environment Setup
Model Naming
OpenRouter model names follow the patternopenrouter/<provider>/<model>:
| Model | model_name |
|---|---|
| Claude Opus 4.8 | "openrouter/anthropic/claude-opus-4-8" |
| GPT-5.4 | "openrouter/openai/gpt-5.4" |
| Gemini 2.5 Pro | "openrouter/google/gemini-2.5-pro" |
| Llama 3.3 70B | "openrouter/meta-llama/llama-3.3-70b-instruct" |
| GLM 5.2 | "openrouter/z-ai/glm-5.2" |
| DeepSeek R1 | "openrouter/deepseek/deepseek-r1" |
| Tencent Hunyuan 3 (free) | "openrouter/tencent/hy3:free" |
:free costs nothing to call — great for prototyping.
1. Single Agent
The smallest useful program: oneAgent on one OpenRouter model. Note the OpenRouter-friendly defaults — set top_p=None so temperature is sent alone (some providers reject both), and use reasoning_effort/thinking_tokens on models that support extended reasoning.
model_name at any entry from the table above (e.g. "openrouter/anthropic/claude-opus-4-8" or "openrouter/tencent/hy3:free").
Streaming
Addstreaming_on=True to print tokens as they arrive:
2. Group Chat Across Providers
GroupChat runs a turn-based, self-selecting room: every agent silently bids on how much it wants to speak, and the single highest bidder above threshold takes the floor each turn. Because OpenRouter exposes every provider through one key, you can seat agents backed by different model families at the same table — here Claude, GLM, and Llama debate together.
Each agent uses max_loops=1 and persistent_memory=False so every speaking decision is a clean single-shot call. The respond tool each agent needs to bid is injected automatically (auto_equip=True by default).
output_type="list":
role (the agent name, or "User" for the seed task) and content. Raise threshold for a more selective room; lower it for a livelier one. See the Group Chat Example for more patterns.
3. Concurrent Workflow (A/B Testing Models)
ConcurrentWorkflow runs every agent in parallel on the same task and returns all responses together. Since OpenRouter puts every model behind one key, this is the cleanest way to A/B test model quality, latency, and style side by side.
results maps agent name → response so you can compare answers directly. Add or remove models by editing the candidates list — no other code changes needed.
Production Defaults
For anything beyond a quick script, pin sensible defaults:Next Steps
- Building Agents with OpenRouter — the provider reference page
- Group Chat Example — deeper group chat patterns
- Concurrent Workflow — the full concurrent architecture guide
- Model Providers Overview