OpenAI SDK & Codex
The gateway is OpenAI-compatible, so the official OpenAI SDKs work by changing two values: the base URL and the API key. Model names become your catalog aliases.
Python
from openai import OpenAI
client = OpenAI(
base_url="https://aam.example.com/v1",
api_key="sk-your-virtual-key",
)
response = client.chat.completions.create(
model="fast", # a catalog alias, not a vendor model id
messages=[{"role": "user", "content": "hello"}],
)
Streaming, tool/function calling, response_format, vision content, and every other parameter work as usual — to an OpenAI-protocol deployment the body passes through losslessly, including parameters the gateway has never heard of.
JavaScript / TypeScript
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://aam.example.com/v1",
apiKey: process.env.AAM_VIRTUAL_KEY,
});
const response = await client.chat.completions.create({
model: "fast",
messages: [{ role: "user", content: "hello" }],
});
Environment variables only
Most OpenAI-SDK-based tools respect the standard variables, so you can often integrate without touching code:
export OPENAI_BASE_URL="https://aam.example.com/v1"
export OPENAI_API_KEY="sk-your-virtual-key"
OpenAI Codex
Codex speaks the Responses wire format, which the gateway serves natively at /v1/responses. In your Codex configuration set the provider's base URL to the gateway, use a virtual key as the API key, and:
- set
wire_api = "responses"for the provider, and - point it at an alias whose deployment is a tool-use-capable model.
To an openai-protocol deployment the Responses body passes through losslessly, so Codex works unchanged; routed to another vendor it is translated (see Gateway API — Responses for the translate-path limits).
What the gateway adds, invisibly
Nothing in your client changes, but every call now gets: virtual-key auth instead of a shared vendor key, routing with load balancing and failover, budgets and rate limits, guardrail screening (including inline on streams), and a durable audit record.
Troubleshooting
401— the virtual key is unknown, expired, suspended, or revoked. Check Operate ▸ Virtual keys.404on the model — themodelvalue must be a registered alias; list them withGET /v1/models.429— over budget or rate-limited; the response carriesRetry-Afterfor rate limits.