DEV Community

Daniel Dong
Daniel Dong

Posted on

Why I Stopped Calling AI APIs Directly

Three months ago I had 5 different AI integrations. Today I have one. Here's why I switched to a unified API proxy.

Three months ago, my codebase had this mess:

# Don't do this (like I did)
if model == "gpt-4":
    response = openai.ChatCompletion.create(...)
elif model == "claude":
    response = anthropic.Completion.create(...)
elif model == "deepseek":
    response = requests.post("https://api.deepseek.com/v1/...", ...)
# ... 5 more if/else blocks
Enter fullscreen mode Exit fullscreen mode

Every new model meant:

New SDK
New error handling
New rate limit logic
New response parsing
I spent more time maintaining API integrations than building features.

The Fix: One API, One Format
I switched to an OpenAI-compatible proxy (AIBridge). Now my code looks like this:

client = OpenAI(
    api_key="mb-your-key",
    base_url="https://aibridge-api.com/v1"
)

# Same code, different model
for model in ["deepseek-v4-pro", "qwen3-235b-a22b", "glm-4-plus"]:
    response = client.chat.completions.create(
        model=model,
        messages=[{"role": "user", "content": "Hello"}]
    )
    print(f"{model}: {response.choices[0].message.content}")
Enter fullscreen mode Exit fullscreen mode

That's it. No if/else. No multiple SDKs. No different response formats.

What I Got Back
Time: Spent 3 days refactoring, saved 2 weeks of maintenance
Flexibility: Can test 14 models by changing one string
Reliability: Built-in fallback across providers
Sanity: No more AttributeError: 'Completion' object has no attribute...
Try It
If your code has more than one AI provider integration, you're doing it wrong.

Get a free API key:
aibridge-api.com

mainpage

models

playground

pricing

Top comments (0)