Skip to main content

AI Gateway

Overview

OpenAI Agents SDK enables powerful AI-driven automation through structured conversations and tool calling. Connecting the Agents SDK to Orq.ai’s AI Gateway transforms experimental agents into production-ready systems with enterprise-grade capabilities.

Key Benefits

Orq.ai’s AI Gateway enhances OpenAI Agents with:

Complete Observability

Track every agent step, tool use, and interaction with detailed traces and analytics

Built-in Reliability

Automatic fallbacks, retries, and load balancing for production resilience

Cost Optimization

Real-time cost tracking and spend management across all AI operations

Multi-Provider Access

Access 300+ LLMs and 20+ providers through a single, unified integration

Prerequisites

Before integrating OpenAI Agents SDK with Orq.ai, ensure the following are in place:
  • An Orq.ai account and API Key
  • Python 3.9 or higher
  • OpenAI Agents SDK installed
To set up an API key, see API keys & Endpoints.

Installation

Install the OpenAI Agents SDK:
pip install openai-agents openai

Configuration

Configure OpenAI Agents SDK to use Orq.ai’s AI Gateway by setting a custom AsyncOpenAI client:
Python
from openai import AsyncOpenAI
from agents import set_default_openai_client, set_tracing_disabled
import os

# Configure OpenAI client with Orq.ai AI Gateway
client = AsyncOpenAI(
    api_key=os.getenv("ORQ_API_KEY"),
    base_url="https://api.orq.ai/v3/router"
)

# Disable the SDK's built-in OpenAI tracing exporter for gateway-only use
set_tracing_disabled(True)

# Set as default client for all agents
set_default_openai_client(client)
base_url: https://api.orq.ai/v3/router

Built-in OpenAI Tracing

The OpenAI Agents SDK includes built-in tracing that exports to OpenAI’s hosted Traces dashboard by default. When you use Orq.ai’s AI Gateway with ORQ_API_KEY and do not configure OpenAI tracing credentials, the SDK can print No API key provided for OpenAI tracing exporter. Exports will be skipped.
Do not set OPENAI_API_KEY only to silence this warning. That sends SDK traces to OpenAI’s dashboard instead of Orq.ai. Disable the SDK’s built-in OpenAI tracing for gateway-only use when agent traces in Orq.ai are not needed.
export OPENAI_AGENTS_DISABLE_TRACING=1
Or disable it in code:
import { setTracingDisabled } from "@openai/agents";

setTracingDisabled(true);

Basic Agent Example

Here’s a complete example of creating and running an OpenAI agent through Orq.ai:
Python
from openai import AsyncOpenAI
from agents import Agent, Runner, set_default_openai_client, set_tracing_disabled
import os

# Configure client with Orq.ai AI Gateway
client = AsyncOpenAI(
    api_key=os.getenv("ORQ_API_KEY"),
    base_url="https://api.orq.ai/v3/router"
)
set_tracing_disabled(True)
set_default_openai_client(client)

# Create agent
agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant that explains complex concepts simply."
)

# Run the agent
result = Runner.run_sync(agent, "Explain quantum computing in simple terms")
print(result.final_output)

Agent with Tools

OpenAI Agents can use tools while routing through Orq.ai:
Python
from openai import AsyncOpenAI
from agents import Agent, Runner, set_default_openai_client, set_tracing_disabled, function_tool
import os

# Configure client
client = AsyncOpenAI(
    api_key=os.getenv("ORQ_API_KEY"),
    base_url="https://api.orq.ai/v3/router"
)
set_tracing_disabled(True)
set_default_openai_client(client)

# Define a tool using the @function_tool decorator
@function_tool
def get_weather(location: str) -> str:
    """Get the current weather for a location."""
    return f"The weather in {location} is sunny and 72°F"

# Create agent with tools
agent = Agent(
    name="Weather Assistant",
    instructions="You are a weather assistant. Use the get_weather function to provide weather information.",
    tools=[get_weather]
)

# Run agent with tool access
result = Runner.run_sync(agent, "What's the weather in San Francisco?")
print(result.final_output)

Model Selection

With Orq.ai, any supported model from 20+ providers can be used:
Python
from openai import AsyncOpenAI
from agents import Agent, Runner, set_default_openai_client, set_tracing_disabled
import os

# Configure client
client = AsyncOpenAI(
    api_key=os.getenv("ORQ_API_KEY"),
    base_url="https://api.orq.ai/v3/router"
)
set_tracing_disabled(True)
set_default_openai_client(client)

# Use Claude
claude_agent = Agent(
    name="Claude Assistant",
    model="anthropic/claude-sonnet-4-6",
    instructions="You are a helpful assistant."
)

# Use Gemini
gemini_agent = Agent(
    name="Gemini Assistant",
    model="google-ai/gemini-2.5-flash",
    instructions="You are a helpful assistant."
)

# Use any other model
groq_agent = Agent(
    name="Groq Assistant",
    model="groq/llama-3.3-70b-versatile",
    instructions="You are a helpful assistant."
)

# Run with different models
result = Runner.run_sync(claude_agent, "Explain machine learning")
print(result.final_output)