- 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>:
Browse the full catalog for hundreds more. Any model tagged
: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: top_p defaults to None, so only temperature is sent (some providers reject both), and reasoning_effort is forwarded on models that support extended reasoning. (thinking_tokens only takes effect together with reasoning_enabled=True.)
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 is a list of role/content messages, one per agent in the order of candidates, 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