DEV Community

Mattias chaw
Mattias chaw

Posted on

Migrating from OpenAI to AIWave: Zero-Downtime Switch Guide

Migrating from OpenAI to AIWave: Zero-Downtime Switch Guide

Switching AI providers doesn't have to be risky. AIWave's API is fully OpenAI-compatible, which means your migration is mostly a config change 鈥?not a rewrite. This guide covers the exact steps, code patterns, and gotchas.

The 3-Line Migration

If you're using the OpenAI Python SDK, here's the entire migration:

import openai

client = openai.OpenAI(
    api_key="your-aiwave-api-key",        # line 1: new key
    base_url="https://aiwave.live/v1",     # line 2: new endpoint
    # model="deepseek-v4-pro"             # line 3: pick your model
)
Enter fullscreen mode Exit fullscreen mode

That's it. Every client.chat.completions.create() call works identically. No SDK changes, no response parsing updates, no schema migration.

Environment Variable Setup

For production, use environment variables so you can swap providers without code changes:

# .env file
OPENAI_API_KEY=sk-your-aiwave-key
OPENAI_BASE_URL=https://aiwave.live/v1
AIWAVE_DEFAULT_MODEL=deepseek-v4-pro
Enter fullscreen mode Exit fullscreen mode
# app.py
import os
import openai

client = openai.OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),
    base_url=os.environ.get("OPENAI_BASE_URL", "https://api.openai.com/v1"),
)

def chat(prompt: str, model: str | None = None) -> str:
    model = model or os.environ.get("AIWAVE_DEFAULT_MODEL", "gpt-4o")
    response = client.chat.completions.create(
        model=model,
        messages=[{"role": "user", "content": prompt}],
    )
    return response.choices[0].message.content
Enter fullscreen mode Exit fullscreen mode

Now you can switch between OpenAI and AIWave by changing a single environment variable 鈥?no deploy required.

Multi-Language SDK Examples

Python (openai SDK)

from openai import OpenAI

client = OpenAI(base_url="https://aiwave.live/v1", api_key="sk-...")

response = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[
        {"role": "system", "content": "You are a code reviewer."},
        {"role": "user", "content": "Review this Python function for bugs:\n```

python\ndef divide(a, b):\n    return a / b\n

```"}
    ],
    temperature=0.2,
)

print(response.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

Node.js (openai SDK)

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.AIWAVE_API_KEY,
  baseURL: "https://aiwave.live/v1",
});

const response = await client.chat.completions.create({
  model: "deepseek-v4-pro",
  messages: [
    { role: "system", content: "You are a code reviewer." },
    { role: "user", content: "Review this function for bugs:\nfunction divide(a, b) { return a / b; }" },
  ],
  temperature: 0.2,
});

console.log(response.choices[0].message.content);
Enter fullscreen mode Exit fullscreen mode

cURL (no SDK)

curl https://aiwave.live/v1/chat/completions \
  -H "Authorization: Bearer sk-your-aiwave-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "messages": [
      {"role": "user", "content": "Explain async/await in Python in 3 sentences."}
    ],
    "temperature": 0.3
  }'
Enter fullscreen mode Exit fullscreen mode

Fallback Pattern: Dual-Provider Resilience

For production systems, implement a fallback so you're never dependent on a single provider:

import openai
import os
import logging

logger = logging.getLogger(__name__)

PRIMARY_BASE = "https://aiwave.live/v1"
FALLBACK_BASE = "https://api.openai.com/v1"
PRIMARY_KEY = os.environ["AIWAVE_API_KEY"]
FALLBACK_KEY = os.environ.get("OPENAI_API_KEY")

def create_client(base_url: str, api_key: str) -> openai.OpenAI:
    return openai.OpenAI(base_url=base_url, api_key=api_key)

def chat_with_fallback(
    messages: list,
    model: str = "deepseek-v4-pro",
    fallback_model: str = "gpt-4o",
    max_retries: int = 2,
) -> str:
    """Try AIWave first, fall back to OpenAI on failure."""
    primary = create_client(PRIMARY_BASE, PRIMARY_KEY)
    fallback = create_client(FALLBACK_BASE, FALLBACK_KEY)

    # Primary attempt with retries
    for attempt in range(max_retries):
        try:
            response = primary.chat.completions.create(
                model=model, messages=messages, timeout=30
            )
            return response.choices[0].message.content
        except openai.APIError as e:
            logger.warning(f"AIWave attempt {attempt + 1} failed: {e}")
            if attempt == max_retries - 1:
                break

    # Fallback to OpenAI
    logger.info("Falling back to OpenAI")
    response = fallback.chat.completions.create(
        model=fallback_model, messages=messages, timeout=30
    )
    return response.choices[0].message.content
Enter fullscreen mode Exit fullscreen mode

This pattern gives you the cost savings of AIWave with the safety net of OpenAI. In practice, AIWave's Singapore-hosted infrastructure has excellent uptime, but the fallback ensures zero downtime regardless.

Model Mapping

When switching from OpenAI to AIWave, here's a practical model mapping:

OpenAI Model AIWave Equivalent Why
GPT-4o deepseek-v4-pro Better benchmarks, 7.7x cheaper, 1M context
GPT-4o Mini deepseek-v4-flash 13x cheaper, 1M context
GPT-3.5 Turbo deepseek-chat Similar quality at lower cost
o1-preview deepseek-r1 Reasoning-focused, different architecture
鈥? glm-4.7-flash Budget option for simple tasks

FAQ

Q: Will my streaming responses work the same way?
Yes. AIWave supports stream=True with identical SSE format. No changes needed.

Q: Are function calling and tool use supported?
Yes. The tools parameter works the same way. AIWave passes tool definitions through to the underlying model.

Q: What about embeddings and image generation?
AIWave supports the standard /v1/embeddings endpoint. Image generation varies by model 鈥?check the models page for current capabilities.

Q: Is my data secure?
AIWave hosts infrastructure in Singapore. Data is not used for training. Full details are in the privacy policy at aiwave.live.

Q: Can I use multiple models in the same application?
Absolutely. Since the API is compatible, you can route different tasks to different models through the same client 鈥?just change the model parameter per request.

Q: What about rate limits?
Rate limits depend on your account tier and the specific model. Budget models have generous limits for development. Premium models scale with your account level. Check pricing for details.

Q: Do I need to change my response parsing code?
No. The response schema is identical to OpenAI's: choices[0].message.content, usage.prompt_tokens, usage.completion_tokens 鈥?all the same.

Migration Checklist

  • [ ] Get AIWave API key from aiwave.live
  • [ ] Set base_url to https://aiwave.live/v1
  • [ ] Test with ernie-4.0-turbo-8k ($0.001/1M) first
  • [ ] Verify streaming works with your existing code
  • [ ] Update model names in your config
  • [ ] Implement fallback pattern for production
  • [ ] Monitor latency and costs for one week
  • [ ] Adjust model selection based on real-world quality

The entire migration can happen in under an hour for most applications. The risk is near zero, and the cost savings start immediately.


Create your AIWave account and start migrating with $5 free credit. Browse all 60+ models to find your optimal setup. Join Discord for migration support from the community.

Top comments (0)