one-key-sdk-migration-single-client · EN · 2026-11-04

One Key Replacing Six SDKs: Merging Separate Vendor Clients Into a Single OpenAI-Compatible Client

Consolidating multiple vendor SDKs into a single OpenAI-compatible client reduces dependency sprawl, unifies error handling, and simplifies key management. This tutorial walks through replacing six separate vendor clients with one client that points to an aggregator, highlighting the per-vendor quirks that disappear and the ones you must handle yourself, such as model-specific parameters and fallback logic.

Why Consolidate Vendor SDKs

Maintaining separate SDKs for each model vendor creates dependency bloat, inconsistent error handling, and scattered authentication logic. By routing all requests through a single OpenAI-compatible endpoint, you can use one client library to call models from multiple vendors.

The cost of six SDKs

  • Six dependency trees to audit and update
  • Six different authentication schemes
  • Six error-response formats to normalise
  • Six retry and timeout configurations to keep in sync

A single OpenAI-compatible client reduces this to one dependency, one key, and one error-handling path.

What the Aggregator Abstracts Away

When you point an OpenAI-compatible client at the aggregator, several per-vendor quirks disappear:

  • Authentication: One API key for all models, instead of separate keys for Claude, GPT, DeepSeek, Qwen, GLM, and Kimi.
  • Request format: All calls use the OpenAI chat completions schema. Vendor-specific REST paths and payload shapes are handled by the aggregator.
  • Response parsing: Responses follow the OpenAI format, so your existing parsing code works unchanged.
  • Error normalisation: The aggregator maps vendor-specific error codes to standard HTTP statuses and OpenAI-style error objects.
  • Retry and timeout logic: You can implement these once at the client level rather than per SDK.
  • Model discovery: You can query available models via a single endpoint, though the list depends on the aggregator.

What You Must Handle Yourself

While the aggregator removes many vendor-specific details, some quirks remain your responsibility:

  • Model-specific parameters: Not all models support the same parameters (e.g., temperature ranges, presence penalties, or tool-calling support). You need to know which parameters each model accepts.
  • Feature support: Some models may not support streaming, function calling, or certain content types. You must detect and handle these differences in your application.
  • Fallback logic: If a model is unavailable or fails, you must implement fallback to another model or retry logic yourself.
  • Token limits and context windows: These vary by model. Your client should enforce limits or let the API return errors.
  • Rate limiting: The aggregator may have its own rate limits, but you should still implement backoff and retry on 429 responses.

Implementation Steps

1. Remove vendor-specific dependencies

Uninstall or remove references to individual vendor SDKs from your project. Keep only the OpenAI-compatible client library.

2. Configure the client

Point the client to the aggregator's base URL and use your single API key. For example, with the OpenAI Python library:

from openai import OpenAI

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

3. Map models to vendor families

Create a mapping or configuration that associates each use case with a model ID. The aggregator uses model identifiers that may include vendor prefixes (e.g., claude-3-opus, gpt-4, deepseek-chat).

4. Handle model-specific capabilities

For each model you use, document its supported parameters and features. Consider a capability map:

model_capabilities = {
    "claude-3-opus": {"streaming": True, "tools": True, "max_tokens": 200000},
    "gpt-4": {"streaming": True, "tools": True, "max_tokens": 8192},
    # ...
}

Use this to conditionally enable features or adjust requests.

5. Implement unified error handling

Catch exceptions from the single client and handle standard HTTP status codes (401, 429, 500, etc.) with retry and backoff logic. The aggregator normalises vendor errors, so you can treat them uniformly.

6. Add fallback logic

If a model call fails after retries, fall back to an alternative model that supports the required capabilities. This logic is simpler with one client because you only need to change the model parameter.

Testing and Validation

  • Run your existing test suite against the new client to ensure parity.
  • Test error scenarios: invalid model, rate limiting, and vendor outages (simulated).
  • Verify that streaming and non-streaming responses both work.
  • Check that token usage and cost reporting match expectations (you pay official price × 1.3).

Conclusion

Replacing six vendor SDKs with one OpenAI-compatible client simplifies your codebase and reduces maintenance overhead. While the aggregator abstracts authentication, request format, and error normalisation, you still need to manage model-specific capabilities, fallback strategies, and rate limiting. With a single client and a capability map, you can confidently call models from multiple vendors without vendor lock-in.