sdk-python-openai-official · EN · 2026-10-14

Using the Official OpenAI Python SDK Against the Aggregator: What Still Works

Swap the base URL to point the official OpenAI Python SDK at a multi-model aggregator. Learn which client methods, retries, and streaming helpers keep working, and which provider-specific extras are silently dropped, so you can make an informed integration decision.

Why Use the Official OpenAI SDK with an Aggregator?

Many developers already use the official openai Python package in their projects. If you want to access multiple models (such as Claude, GPT, DeepSeek, Qwen, GLM, or Kimi) through a single API key and billing account, an aggregator can be a convenient option. The aggregator exposes an OpenAI-compatible endpoint, so you can often reuse your existing code with minimal changes.

This guide explains what still works when you point the official SDK at an aggregator, and what may silently stop working.

The Base URL Swap

The core change is redirecting the SDK from OpenAI's servers to the aggregator's endpoint. Instead of:

from openai import OpenAI
client = OpenAI(api_key="your-key")

You set the base_url parameter to the aggregator's URL:

from openai import OpenAI
client = OpenAI(
    api_key="your-aggregator-key",
    base_url="https://api.example-aggregator.com/v1"
)

That's it for basic setup. The SDK will send requests to the aggregator, which then routes them to the appropriate model backend.

What Still Works

Most standard chat completion features continue to function because the aggregator implements the OpenAI-compatible API surface.

Chat Completions

  • client.chat.completions.create() works for supported models.
  • Parameters like model, messages, temperature, maxtokens, topp, and stream are generally accepted.
  • Multi-turn conversations and system messages are handled as expected.

Streaming Helpers

  • Streaming responses via stream=True work, and the SDK's iterator interface (for chunk in stream:) still yields chunks.
  • The client.chat.completions.create(..., stream=True) returns an object you can iterate over, just like with OpenAI.
  • Helper methods like stream.to_records() (if using the openai package's streaming utilities) may or may not be supported depending on the aggregator's implementation.

Retries and Timeouts

The official SDK includes automatic retries for certain errors (e.g., rate limits, server errors) and configurable timeouts. These client-level behaviors are preserved because they are handled by the SDK itself, not the API.

  • You can set max_retries and timeout when creating the client.
  • The SDK will retry on connection errors and certain HTTP status codes.
  • However, the aggregator may have its own rate limits and error handling, so the retry logic may not behave identically to OpenAI's service.

Other Client Methods

  • client.models.list() may return a list of available models from the aggregator, but the format and content can differ.
  • client.embeddings.create() works if the aggregator supports embedding models and routes them correctly.
  • client.audio.transcriptions.create() and other audio endpoints may work if the aggregator supports them, but availability varies.

What Silently Drops

Provider-specific extras and some advanced OpenAI features may not be supported by the aggregator. These often fail silently or return unexpected results.

Provider-Specific Parameters

  • Parameters unique to certain providers (e.g., logprobs, logit_bias, or vendor-specific fields) may be ignored or cause errors.
  • Some models may not support all standard parameters (e.g., temperature might be ignored by certain reasoning models).
  • Tool calling (function calling) and JSON mode may work only for models that support them, and the aggregator may not validate or translate these uniformly.

Advanced OpenAI Features

  • Assistants API, Threads, and Runs are unlikely to be supported unless the aggregator explicitly implements them.
  • Fine-tuning endpoints are typically not available.
  • Files API and Batch API are often absent.
  • Realtime API and WebSocket-based streaming are usually not supported.

Response Metadata and Errors

  • Error messages may differ from OpenAI's, making debugging harder.
  • Response headers and request IDs may not match OpenAI's format.
  • Usage statistics (token counts) might be missing or inaccurate for some models.

Practical Tips

  • Test each model you plan to use with the specific features you need (streaming, tool calls, JSON mode) before committing.
  • Handle errors gracefully; the aggregator may return different error codes or messages.
  • Monitor your usage and costs, as pricing is based on the aggregator's rates (official price × 1.3 for users).
  • If you rely on advanced OpenAI features, check the aggregator's documentation for supported endpoints.

Conclusion

The official OpenAI Python SDK can be a convenient way to access multiple models through an aggregator with a simple base URL swap. Standard chat completions, streaming, and client-level retries generally work. However, provider-specific parameters and advanced OpenAI features often drop silently. Always verify that the aggregator supports the specific functionality your application requires.