Orq MCP is live: Use natural language to interrogate traces, spot regressions, and experiment your way to optimal AI configurations. Available in Claude Desktop, Claude Code, Cursor, and more. Start now →
Use the AI Gateway with OpenAI SDK. Replace OpenAI base URL with Orq.ai for routing, caching, monitoring, and multi-provider fallback capabilities.
AI Gateway
Route your LLM calls through the AI Gateway with a single base URL change. Zero vendor lock-in: always run on the best model at the lowest cost for your use case.
Observability
Instrument your code with OpenTelemetry to capture traces, logs, and metrics for every LLM call, agent step, and tool use.
The OpenAI SDK provides powerful tools for building AI applications with GPT models. By connecting the SDK to Orq.ai’s AI Gateway, you transform your OpenAI integration into a production-ready system with enterprise-grade capabilities, complete observability, and access to 300+ models across 20+ providers.
While using the OpenAI SDK, set the Base URL to the AI Gateway to feed calls through our API without changing any other part of your code.Using the Orq.ai AI Gateway, you benefit from Platform Traces and Cost and Usage Monitoring, keeping full compatibility and a unified API with all models while using the OpenAI SDK.
import OpenAI from "openai";const openai = new OpenAI({ baseURL: "https://api.orq.ai/v3/router", apiKey: process.env.ORQ_API_KEY,});const stream = await openai.responses.create({ model: "openai/gpt-4o", input: "Write a short story about robots.", stream: true,});for await (const event of stream) { if (event.type === "response.output_text.delta") { process.stdout.write(event.delta); }}
Integrate OpenAI SDK with Orq.ai’s observability to gain complete insights into model performance, token usage, API latency, and conversation flows using OpenTelemetry.
The examples below use the Chat Completions endpoint. OpenTelemetry instrumentation works identically with the Responses API: replace client.chat.completions.create(...) with client.responses.create(...).
from openai import OpenAIfrom opentelemetry import traceimport osclient = OpenAI( base_url="https://api.orq.ai/v3/router", api_key=os.environ.get("ORQ_API_KEY"),)tracer = trace.get_tracer(__name__)def analyze_document(document: str): with tracer.start_as_current_span("document-analysis") as span: span.set_attribute("document.length", len(document)) # Prepare prompt prompt = f"Analyze this text: {document}" with tracer.start_as_current_span("prepare-prompt") as prep_span: prep_span.set_attribute("prompt.length", len(prompt)) # Model inference with tracer.start_as_current_span("model-inference") as inf_span: inf_span.set_attribute("model", "gpt-4o") response = client.chat.completions.create( model="openai/gpt-4o", messages=[{"role": "user", "content": prompt}] ) inf_span.set_attribute("tokens.total", response.usage.total_tokens) # Process result with tracer.start_as_current_span("process-result") as proc_span: result = response.choices[0].message.content proc_span.set_attribute("result.length", len(result)) return resultanalysis = analyze_document("Machine learning is a subset of AI.")print(analysis)