OpenAI SDK: what it is and why it works with more than GPT models
The OpenAI SDK is an ordinary wrapper around an HTTP API. That is why you can point it at another address and use Claude, Gemini or DeepSeek without changing your code. Here is how, and where the limits are.
5 min · · development · API keys
The OpenAI SDK is an official library that simplifies calling the OpenAI API from code. Instead of assembling HTTP requests by hand, you call functions, and the library builds the request, adds the key, parses the response and retries on temporary failures. Below we explain what the OpenAI SDK is, which languages it covers, and why it can talk not only to GPT but also to Claude, Gemini and DeepSeek after changing one parameter.
Library details are based on their official GitHub READMEs (openai-python and openai-node) and OpenAI guides at the time of checking: language version requirements change there, so verify them at install time.
What an SDK does
Under the hood any API request is HTTP: an address, an authorization header and a JSON body. The SDK takes over the routine:
- adds the
Authorization: Bearer ...header; - builds the path, for example
/chat/completions, from the base address; - turns the JSON response into objects with type hints;
- parses streaming responses (SSE);
- retries on temporary errors and raises typed exceptions.
Keep in mind: the SDK knows nothing about models. It simply sends the request to the address you set, so it is called the "OpenAI SDK", but in practice it is a client for the "OpenAI-compatible API" protocol.
Which languages it covers
OpenAI has official libraries for Python (per the README, Python 3.10 or newer is required), and TypeScript and JavaScript (Node.js 22 and 24 LTS, 22 being the minimum; Deno and Bun are also stated), while OpenAI's guides give examples for Go, Java, C# and Ruby. Installing in Python and Node.js:
pip install openai
npm install openaiFor languages without an official library an ordinary HTTP client is enough: the request format is the same, you only need to build the JSON and pass the authorization header.
How it works with more than GPT models
The client accepts an optional base_url parameter (baseURL in Node.js). If you do not set it, requests go to OpenAI's address. If you set a gateway address, they go there. The request format stays the same; only the model and key change.
from openai import OpenAI
client = OpenAI(
base_url="https://api.zukko.pro/v1",
api_key="fetch_your_key",
)
for model in ["claude-sonnet-5-5", "gpt-6.1-sol", "deepseek-v4.1-flash"]:
r = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "Explain what a token is in one sentence"}],
max_tokens=200,
)
print(model, "->", r.choices[0].message.content, "| tokens:", r.usage.total_tokens)The same code in Node.js:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.zukko.pro/v1",
apiKey: process.env.ZUKKO_API_KEY,
});
const r = await client.chat.completions.create({
model: "claude-sonnet-5-5",
messages: [{ role: "user", content: "Hello" }],
});
console.log(r.choices[0].message.content);You can also avoid code changes: the libraries read the OPENAI_BASE_URL and OPENAI_API_KEY environment variables. Then OpenAI() with no arguments already points at the gateway.
export OPENAI_BASE_URL="https://api.zukko.pro/v1"
export OPENAI_API_KEY="fetch_your_key"The address for the OpenAI format always ends in /v1, one of the most common sources of mistakes; see base URL with or without /v1. More about the standard itself is in OpenAI compatible API.
Where this approach has limits
Compatibility covers the shape of requests, not everything the OpenAI platform can do. Check in advance:
- Which endpoints the gateway has. At Zukko these are
POST /v1/chat/completions,POST /v1/responsesandGET /v1/models. SDK methods for files, batch processing or embeddings will call addresses that the gateway documentation does not list. - Which parameters a particular model accepts. The shape is the same, but support for individual parameters (for example,
temperatureor tool calling) depends on the model: if a request is rejected, read the error text and drop the extra parameter. - Cache for Claude. In the OpenAI format the gateway cannot see how much of the input came from cache for Claude, and the whole input is billed at the input price. The cache discount comes from the Anthropic format (
/v1/messages), for which you use the official Anthropic SDK with the addresshttps://api.zukko.prowithout/v1. For GPT models the cache is visible in both formats. More in the limits and cache docs. - Streaming responses. The last piece of the stream contains
usageand an emptychoicesarray, so checkif chunk.choices:beforechunk.choices[0].
Error handling
The SDK turns HTTP errors into exceptions. In Python the main classes live in the openai namespace:
import openai
try:
r = client.chat.completions.create(
model="gpt-6.1-sol",
messages=[{"role": "user", "content": "Hello"}],
)
except openai.AuthenticationError:
print("401: check the key")
except openai.RateLimitError:
print("429: key limit or provider restriction, retry later")
except openai.APIStatusError as e:
print("API error:", e.status_code)
except openai.APIConnectionError:
print("No connection to the server")Gateway codes: 401 wrong key, 402 not enough balance, 403 model_not_allowed_for_key, 404 model_not_found, 413 request too large, 429 key limit or provider restriction, 503 provider unavailable or model switched off. A 402 lands in the general APIStatusError with a status_code field. The library also has its own automatic retries (the max_retries parameter): choose their number to fit your task.
What a call costs
Take a request with 1000 input tokens and 500 output tokens. Formula: input × input price + output × output price, prices as of October 18, 2026.
| Model | Calculation | Total |
|---|---|---|
claude-sonnet-5-5 (0.4 / 2) | 1000 × 0.4 / 1M + 500 × 2 / 1M = 0.0004 + 0.001 | $0.0014 |
gpt-6.1-sol (0.27 / 1.32) | 0.00027 + 0.00066 | $0.00093 |
deepseek-v4.1-flash (0.013 / 0.038) | 0.000013 + 0.000019 | $0.000032 |
Which model suits your task is decided by testing and your data, not by price. The current list and prices: GET https://api.zukko.pro/v1/models or the "Models" page in your account.
More complete Python examples are collected in the Python documentation.
FAQ
Does the OpenAI SDK work only with OpenAI?
No. It is a client for the OpenAI-compatible protocol. If a server supports the same request format, you can point the library at it through base_url.
Do I pay for the SDK itself?
No, the library is free and open. You pay for tokens to whoever's API you call.
What should I use for Claude: the OpenAI SDK or the Anthropic SDK?
If you want the cache discount, use the Anthropic SDK and the Anthropic format. If one codebase for all models matters more, the OpenAI SDK works, but for Claude the whole input is billed at the input price.
How do I check that the connection works?
Call client.models.list() or GET /v1/models, then send a short request. Create a key in your account; access from Russia goes through the gateway, with payment by SBP, MasterCard or crypto.
zukko
Pay 25×
less
for Claude Code & ChatGPT
One fetch_* key and base URL api.zukko.pro — for Cursor, Claude Code, Codex, and any SDK.
Related articles
- Your Own Neural Network Proxy on Node.js: Keep the API Key Off the FrontendA small Express server between your frontend and the model API: the key stays on the server, and models, request size and rate are capped.
- DeepSeek API in Python: Requests, Streaming, JSON and Error HandlingReady code for DeepSeek V4.1 Flash and V4 Pro on the OpenAI SDK: a request, streaming, JSON parsing and careful error handling.
- Gemini API in Python: requests via the OpenAI SDK and OpenAI formatA working Gemini API example in Python with no extra library: change base_url in the OpenAI SDK, add streaming and JSON, and compare with google-genai.
- Anthropic SDK for Python: base_url, key and a first request via a gatewayThe official anthropic package for Python just needs a different address. We cover base_url, the key, streaming, token counting, caching and errors.