0

OpenRouter Provider

OpenRouter Provider explains the cloud layer of MTPX with practical guidance for building inspectable, tool-using agents.

Op
OpenRouter Provider
Chapter 039ProvidersCloudIndex
01Orientation

OpenRouter Provider belongs to the providers track. The page breaks the idea into responsibilities, implementation rules, failure modes, and the signals you should expose in a product UI.

Use this when

Use this when you need to understand how openrouter provider affects a real MTPX agent before you wire it into an application.

  • What openrouter provider owns in the runtime.
  • How it connects to planning, tool execution, events, providers, or storage.
  • What to log, test, and expose to users when this layer is active.
  • Common mistakes that make agent systems hard to inspect.
02 / syntax starter
from mtp import Agent
from mtp.providers import Groq

agent = Agent.MTPAgent(
    provider=Groq(model="llama-3.3-70b-versatile"),
    tools=tools,
)
03 / manual

Read the system

The complete source manual—syntax, examples, linked references, edge cases, and implementation notes.

Documentation index ↗

OpenRouter provides a unified API to access 200+ models from multiple providers. One API key, many models.

Install

bashpip install "mtpx[openrouter]"

This installs the openai SDK (used for the OpenAI-compatible API):

bashpip install openai

API Key Setup

  1. Install dotenv support:
bash   pip install python-dotenv

Or with the MTP extra:

bash   pip install "mtpx[dotenv]"
  1. Create a .env file in your project root:
text   OPENROUTER_API_KEY=sk-or-your_key_here
  1. Load it in your code before creating the provider:
python   from mtp import Agent

   Agent.load_dotenv_if_available()  # reads .env file

Get an API key at openrouter.ai.

Option 2: System environment variable

bash# Linux/macOS
export OPENROUTER_API_KEY="sk-or-..."

# Windows PowerShell
$env:OPENROUTER_API_KEY="sk-or-..."

Quick Start

pythonfrom mtp import Agent
from mtp.providers import OpenRouter

Agent.load_dotenv_if_available()  # loads OPENROUTER_API_KEY from .env

provider = OpenRouter(model="qwen/qwen3.6-plus-preview:free")
tools = Agent.ToolRegistry()
agent = Agent(provider=provider, tools=tools)

reply = agent.run_loop("What is 25 * 4 + 10?")
print(reply)

Parameters

ParameterTypeDefaultDescription
modelstr"qwen/qwen3.6-plus-preview:free"OpenRouter model ID (format: provider/model)
api_keystr | NoneNoneAPI key (falls back to OPENROUTER_API_KEY env var)
site_urlstr | NoneNoneYour site URL (sent as HTTP-Referer header for rankings)
site_namestr | NoneNoneYour app name (sent as X-Title header)
temperaturefloat0.0Sampling temperature
tool_choicestr | dict"auto"Tool selection strategy
clientAny | NoneNonePre-configured openai.OpenAI client instance

Capabilities

CapabilityValue
Tool callingYes (model-dependent)
Parallel tool callsNo
Input modalitiestext, image, audio, video, file
StreamingFallback
Usage metricsRich
Reasoning metadataNo
Native asyncNo (uses thread fallback)
  • qwen/qwen3.6-plus-preview:free — Free, good tool calling (default)
  • anthropic/claude-3.5-sonnet — Best tool calling
  • google/gemini-2.0-flash — Fast, cheap
  • meta-llama/llama-3.3-70b-instruct — Good open-source option
  • deepseek/deepseek-chat — Strong reasoning

Full Example

pythonfrom mtp import Agent
from mtp.providers import OpenRouter

Agent.load_dotenv_if_available()

provider = OpenRouter(
    model="qwen/qwen3.6-plus-preview:free",
    site_url="https://myapp.com",
    site_name="My Agent App",
    temperature=0.0,
)

tools = Agent.ToolRegistry()
agent = Agent(provider=provider, tools=tools, debug_mode=True)

reply = agent.run_loop(
    "Calculate (25 * 4) + 10",
    max_rounds=3,
)
print(reply)

Notes

  • OpenRouter uses the OpenAI-compatible API at https://openrouter.ai/api/v1.
  • Model IDs use the format provider/model-name (e.g., anthropic/claude-3.5-sonnet).
  • Tool calling support and quality depends on the underlying model.
  • Free models are available with :free suffix.
  • The site_url and site_name parameters help with OpenRouter rankings and attribution.

Source

src/mtp/providers/openrouter_provider.py

01

Read

Understand where OpenRouter Provider sits in the agent loop before adding abstractions.

02

Wire

Connect the smallest useful provider, registry, store, or event stream first.

03

Observe

Expose events, logs, results, and failure states while the runtime is still moving.

04

Harden

Add policy, tests, retries, and audit traces after the behavior is visible.

Next docSambaNova Provider