Agent framework

OrcaRouter tools in OpenAI Agents SDK

Wrap each OrcaRouter tool in a FunctionTool with its own JSON schema and run it from an Agents SDK agent, with the model served through OrcaRouter too.

Details

Kind
Agent framework
Connects through
Function calling

Set it up

  1. Install the packages: pip install openai-agents httpx.
  2. Set ORCAROUTER_API_KEY to an API key from your OrcaRouter console.
  3. Load tools for a task with the helper below and pass them to your Agent.

Code

Load OrcaRouter tools
# orcarouter_tools.py
import json
import os

import httpx
from agents import FunctionTool

BASE = "https://api.orcarouter.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['ORCAROUTER_API_KEY']}"}


def _invoker(name):
    async def invoke(ctx, args: str) -> str:
        async with httpx.AsyncClient(timeout=120) as client:
            r = await client.post(f"{BASE}/v1/tools/{name}/run", json={"input": json.loads(args or "{}")}, headers=HEADERS)
        return r.text

    return invoke


def orcarouter_tools(query, limit=5):
    found = httpx.post(f"{BASE}/v1/tools/discover", json={"q": query, "limit": limit}, headers=HEADERS, timeout=30)
    found.raise_for_status()
    ids = ",".join(tool["id"] for tool in found.json()["data"]["results"])
    if not ids:
        return []
    fns = httpx.get(f"{BASE}/v1/tools/functions", params={"ids": ids, "format": "openai"}, headers=HEADERS, timeout=30)
    fns.raise_for_status()
    return [
        FunctionTool(
            name=spec["function"]["name"],
            description=spec["function"]["description"],
            params_json_schema=spec["function"]["parameters"],
            on_invoke_tool=_invoker(spec["function"]["name"]),
            strict_json_schema=False,
        )
        for spec in fns.json()["data"]["tools"]
    ]
Run an agent on OrcaRouter
import os

from agents import Agent, Runner, set_default_openai_api, set_default_openai_client, set_tracing_disabled
from openai import AsyncOpenAI
from orcarouter_tools import orcarouter_tools

set_default_openai_client(AsyncOpenAI(base_url="https://api.orcarouter.ai/v1", api_key=os.environ["ORCAROUTER_API_KEY"]))
set_default_openai_api("chat_completions")
set_tracing_disabled(True)

agent = Agent(
    name="Social researcher",
    instructions="Answer with figures from the tools.",
    model="openai/gpt-5-mini",
    tools=orcarouter_tools("tiktok user profile"),
)
result = Runner.run_sync(agent, "How many followers does @nasa have on TikTok?")
print(result.final_output)

Recipes to try with OpenAI Agents SDK

© 2026 OrcaRouter

For Providers

Run an inference platform? Get your models on OrcaRouter.

providers@orcarouter.ai

Join our community

Discordsupport@orcarouter.aiXLinkedInGitHubYouTube