Skip to main content

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 RunConfig for Runner.run(...) and Runner.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)

  1. Create or open your project and install dependencies:
uv add openai-agents openrouter-oai-agentsdk
  1. Set your OpenRouter API key:
export OPENROUTER_API_KEY="sk-or-v1-..."
  1. 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)
  1. Run it:
uv run python main.py

What each line does:

  1. Agent(...) defines behavior and the model you want.
  2. create_openrouter_run_config() wires OpenRouter as the provider.
  3. Runner.run_sync(...) executes one request using that provider.
  4. result.final_output prints 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 one
  • OPENROUTER_BASE_URL: defaults to https://openrouter.ai/api/v1
  • OPENROUTER_HTTP_REFERER: app/site URL for OpenRouter attribution
  • OPENROUTER_X_TITLE: app title for OpenRouter attribution
  • OPENROUTER_DISABLE_TRACING: true by default

Common errors

  • OPENROUTER_API_KEY is not set: export OPENROUTER_API_KEY before running.
  • No model provided: set Agent(model=...) or set OPENROUTER_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)

Source distribution for openrouter-oai-agentsdk 0.1.2
File Size Uploaded
openrouter_oai_agentsdk-0.1.2.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openrouter-oai-agentsdk 0.1.2
File Interpreter ABI Platform
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}

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page