openrouter-oai-agentsdk
Use OpenRouter models inside the OpenAI Agents SDK without changing your agent architecture.
This package provides:
- an OpenRouter-backed
ModelProvider - a ready-to-use
RunConfigforRunner.run(...)andRunner.run_streamed(...) - environment-based configuration with optional OpenRouter attribution headers
Install
uv add openrouter-oai-agentsdk
Or:
pip install openrouter-oai-agentsdk
What problem this solves
The OpenAI Agents SDK expects a model provider. This library plugs OpenRouter in as that provider, so you can keep using:
Agent(...)Runner.run(...)/Runner.run_streamed(...)ModelSettings(...)
Instead of wiring your own client/provider every time, you create one run config from this package and pass it to Runner.
Quick start (step by step)
- Create or open your project and install dependencies:
uv add openai-agents openrouter-oai-agentsdk
- Set your OpenRouter API key:
export OPENROUTER_API_KEY="sk-or-v1-..."
- Create
main.py:
from agents import Agent, Runner
from openrouter_oai_agentsdk import create_openrouter_run_config
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant.",
model="openai/gpt-4o-mini",
)
result = Runner.run_sync(
agent,
"In one sentence, what is gravity?",
run_config=create_openrouter_run_config(),
)
print(result.final_output)
- Run it:
uv run python main.py
What each line does:
Agent(...)defines behavior and the model you want.create_openrouter_run_config()wires OpenRouter as the provider.Runner.run_sync(...)executes one request using that provider.result.final_outputprints the agent's final text response.
If you already set OPENROUTER_MODEL, you can omit model=... on Agent(...).
Next step: streaming (optional)
Use Runner.run_streamed(...) only when you want token-by-token output in real time. Start with run_sync first.
Usage patterns
Pattern A: zero-config run config from env
from openrouter_oai_agentsdk import OPENROUTER_RUN_CONFIG
from agents import Runner
# Pass OPENROUTER_RUN_CONFIG directly to Runner calls.
Pattern B: explicit settings in code
from openrouter_oai_agentsdk import OpenRouterSettings, create_openrouter_run_config
settings = OpenRouterSettings(
api_key="sk-or-v1-...",
fallback_model="openai/gpt-5-mini",
http_referer="https://your-app.example",
x_title="Your App Name",
)
run_config = create_openrouter_run_config(settings=settings)
Use this pattern when you want fully explicit config (service containers, tests, multi-tenant apps).
Environment variables
Required:
OPENROUTER_API_KEY: your OpenRouter key (sk-or-v1-...)
Optional:
OPENROUTER_MODEL: fallback model if an agent does not define oneOPENROUTER_BASE_URL: defaults tohttps://openrouter.ai/api/v1OPENROUTER_HTTP_REFERER: app/site URL for OpenRouter attributionOPENROUTER_X_TITLE: app title for OpenRouter attributionOPENROUTER_DISABLE_TRACING:trueby default
Common errors
OPENROUTER_API_KEY is not set: exportOPENROUTER_API_KEYbefore running.No model provided: setAgent(model=...)or setOPENROUTER_MODEL.
Import compatibility
The preferred import is:
from openrouter_oai_agentsdk import OPENROUTER_RUN_CONFIG
Legacy import path is still supported:
from openrouter_provider import OPENROUTER_RUN_CONFIG
Build and publish (maintainers)
Build distributions:
uv build --no-sources
Bump version:
uv version --bump patch
Publish to PyPI:
uv publish --token "$UV_PUBLISH_TOKEN"
Publish to a configured custom index:
uv publish --index testpypi --token "$UV_PUBLISH_TOKEN"
Trusted publishing from GitHub Actions is also supported via .github/workflows/publish.yml.
Verify install/import (without local project shadowing):
uv run --with openrouter-oai-agentsdk --no-project -- \
python -c "import openrouter_oai_agentsdk; print(openrouter_oai_agentsdk.__version__)"
Metadata
Release files for openrouter-oai-agentsdk 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| openrouter_oai_agentsdk-0.1.2.tar.gz | 6.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| openrouter_oai_agentsdk-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.9 kB
Release files / openrouter_oai_agentsdk-0.1.2.tar.gz
| Download URL | openrouter_oai_agentsdk-0.1.2.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be2a8eeaeefb832b1eac4954721ade170de62b1695b7f9511c45b399d1d45d4a
|
|
BLAKE2b-256 checksum How to use checksums |
3f597c44a0a84ddbc59eac02b8f0dc880b7906903db1a914560e2f4c102ba6d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / openrouter_oai_agentsdk-0.1.2-py3-none-any.whl
| Download URL | openrouter_oai_agentsdk-0.1.2-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c1f6d24cc7fc7ee95016b9872bdaa4180bdba2c346557bc6d361518d256eec8
|
|
BLAKE2b-256 checksum How to use checksums |
af8c3c10566618d7cc2a1b761b402177ebd49bef518fd5eb55cfc81ae89dd675
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|