Skip to main content

OpenRouter model provider integration for the OpenAI Agents SDK.

Project description

openrouter-oai-agentsdk

OpenRouter provider utilities for the OpenAI Agents SDK.

Install

uv add openrouter-oai-agentsdk

Or:

pip install openrouter-oai-agentsdk

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

Quick start

import asyncio

from openai.types.responses import ResponseTextDeltaEvent
from openai.types.shared import Reasoning

from agents import Agent, ModelSettings, Runner
from openrouter_oai_agentsdk import create_openrouter_run_config


def agent_settings(*, thinking: bool) -> ModelSettings:
    return ModelSettings(reasoning=None if thinking else Reasoning(effort="none"))


agent = Agent(
    name="Math Tutor",
    instructions=(
        "You provide help with math problems. "
        "Explain your reasoning at each step and include examples."
    ),
    model="z-ai/glm-5",
    model_settings=agent_settings(thinking=False),
)


async def main() -> None:
    result = Runner.run_streamed(
        agent,
        "How to calculate the fall rate for something?",
        run_config=create_openrouter_run_config(),
    )
    async for event in result.stream_events():
        if event.type == "raw_response_event" and isinstance(
            event.data, ResponseTextDeltaEvent
        ):
            print(event.data.delta, end="", flush=True)
    print()


if __name__ == "__main__":
    asyncio.run(main())

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 with uv

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"

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__)"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openrouter_oai_agentsdk-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openrouter_oai_agentsdk-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file openrouter_oai_agentsdk-0.1.0.tar.gz.

File metadata

  • Download URL: openrouter_oai_agentsdk-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for openrouter_oai_agentsdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 70122f71d7bf88044d93286c13d7a492951140be0220c4dd490719299331147c
MD5 2f0552ba11826e9847ca94abc9dd29fb
BLAKE2b-256 0f0efca8578e15f9f6b4a4073b81a9f8c7817e8e8419d06d16b1bebdd7bb4636

See more details on using hashes here.

File details

Details for the file openrouter_oai_agentsdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: openrouter_oai_agentsdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for openrouter_oai_agentsdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e347191c0b0a3a53aea5b717e66f2eeae95fcb89a87e461efae83638409ccd81
MD5 7469414817dcb3ec11f10b6a57bae891
BLAKE2b-256 1f70c56356e31fbbb2e1e2bf14d847cff7fe369dd229c02728cb1b03134a598e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page