Migrating from OpenAI to AIWave: Zero-Downtime Switch Guide

Jul 18 · Guide
AIWave Login

# Migrating from OpenAI to AIWave: Zero-Downtime Switch Guide

Switching AI providers doesn't have to be risky. [AIWave](https://aiwave.live/?utm_source=dev.to&utm_medium=organic&utm_campaign=SEO_ARTICLES)'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
)

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

# 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

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)

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);

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
  }'

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

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.

AIWave Homepage

Model Mapping

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

| OpenAI Model | AIWave Equivalent | Why |

|---------------|-------------------|-----|

| GPT-4o | [DeepSeek V4 Pro](https://aiwave.live/models/deepseek-v4-pro?utm_source=dev.to&utm_medium=organic&utm_campaign=SEO_ARTICLES) | Better benchmarks, 7.7x cheaper, 1M context |

| GPT-4o Mini | [DeepSeek V4 Flash](https://aiwave.live/models/deepseek-v4-flash?utm_source=dev.to&utm_medium=organic&utm_campaign=SEO_ARTICLES) | 13x cheaper, 1M context |

| GPT-3.5 Turbo | [DeepSeek Chat](https://aiwave.live/models/deepseek-chat?utm_source=dev.to&utm_medium=organic&utm_campaign=SEO_ARTICLES) | Similar quality at lower cost |

| o1-preview | [DeepSeek R1](https://aiwave.live/models/deepseek-r1?utm_source=dev.to&utm_medium=organic&utm_campaign=SEO_ARTICLES) | Reasoning-focused, different architecture |

| 鈥?| [GLM 4.7 Flash](https://aiwave.live/models/glm-4.7-flash?utm_source=dev.to&utm_medium=organic&utm_campaign=SEO_ARTICLES) | 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](https://aiwave.live/models/?utm_source=dev.to&utm_medium=organic&utm_campaign=SEO_ARTICLES) 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](https://aiwave.live/?utm_source=dev.to&utm_medium=organic&utm_campaign=SEO_ARTICLES).

**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](https://aiwave.live/pricing?utm_source=dev.to&utm_medium=organic&utm_campaign=SEO_ARTICLES) 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](https://aiwave.live/?utm_source=dev.to&utm_medium=organic&utm_campaign=SEO_ARTICLES)
  • [ ] Set `base_url` to `https://aiwave.live/v1`?utm_source=dev.to&utm_medium=organic&utm_campaign=SEO_ARTICLES
  • [ ] 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.

    Who Should Migrate?

    | Profile | Should You Migrate? | Why |

    |---------|---------------------|-----|

    | Startup using GPT-4o for chatbots | **Yes** | Save ~85% with DeepSeek V4 Pro at same or better quality |

    | Solo developer on a budget | **Yes** | GLM 4.7 Flash is free — zero cost for prototyping |

    | Enterprise with OpenAI contracts | **Evaluate** | Use the fallback pattern for gradual transition |

    | Teams building AI products | **Yes** | Switch models per-task for optimal cost/quality balance |

    | Researchers doing RAG | **Yes** | DeepSeek V4 Pro's 1M context window is a game-changer |

    Cost Savings Calculator

    # Real pricing from AIWave (per 1M tokens)
    openai_pricing = {"gpt-4o": {"input": 2.50, "output": 10.00}}
    aiwave_pricing = {"deepseek-v4-pro": {"input": 0.42, "output": 0.84}}
    
    # Your monthly usage
    monthly_input = 10_000_000   # 10M tokens
    monthly_output = 20_000_000  # 20M tokens
    
    openai_cost = (monthly_input / 1e6 * openai_pricing["gpt-4o"]["input"] +
                   monthly_output / 1e6 * openai_pricing["gpt-4o"]["output"])
    aiwave_cost = (monthly_input / 1e6 * aiwave_pricing["deepseek-v4-pro"]["input"] +
                   monthly_output / 1e6 * aiwave_pricing["deepseek-v4-pro"]["output"])
    
    print(f"OpenAI (GPT-4o):  ${openai_cost:,.2f}/month")
    print(f"AIWave (DeepSeek V4 Pro): ${aiwave_cost:,.2f}/month")
    print(f"Savings: ${openai_cost - aiwave_cost:,.2f}/month ({(1 - aiwave_cost/openai_cost)*100:.0f}%)")
    
    # Output:
    # OpenAI (GPT-4o):  $225.00/month
    # AIWave (DeepSeek V4 Pro): $21.00/month
    # Savings: $204.00/month (91%)

    ---

    Create your AIWave account

    ---

    *We're a small team behind AIWave. No VC money, no big marketing budget — just a few people who believe Chinese AI models should be accessible to everyone in the world. Your API calls keep this project alive. If you find value in what we're building, stick around. It means more than you know.*