base_url to the gateway, authenticate to to11 with the x-to11-authorization header, keep passing your provider key as the SDK’s api_key, and name the provider in the model string — openai::gpt-4o, where openai is the routing identifier of your OpenAI provider in to11. See Naming the provider in a request. The rest of your code stays the same.
Python
Install the SDK if you haven’t already:base_url to your gateway:
TypeScript / Node.js
Streaming
Addstream: true to receive the response incrementally. The gateway streams chunks back as they arrive from the provider, and the call is traced the same as a non-streaming one.
Providers the OpenAI SDK reaches
The gateway forwards your request to the provider as you wrote it and does not convert between wire formats. The OpenAI SDK therefore reaches only providers that speak the OpenAI format:client.chat.completions(/v1/chat/completions) — OpenAI, xAI, and the OpenAI-compatible providers, including Google Gemini, Google Vertex AI, and Cohere through their OpenAI-compatible endpoints.client.responses(/v1/responses) — OpenAI and xAI.
anthropic::claude-sonnet-4-6, is rejected with 400 Bad Request and the x-to11-error-code: cross_dialect header before anything is sent to the provider. See Which SDK to call a provider with.
Tool calling
Tool calling works identically to direct OpenAI usage:tools array reaches the provider unchanged.
Environment variable configuration
If you prefer not to hard-code the base URL, use theOPENAI_BASE_URL environment variable: