Migrate from OpenAI to AnAiApi in 3 Lines (Keep Your Code)
Switching LLM providers usually means rewriting clients, re-reading docs, and re-testing everything. With AnAiApi it's three lines: change the base URL and the key, keep the rest. Here's the exact swap — and why it's worth doing.
The 3-line change
If you already use the OpenAI Python SDK, this is the whole diff:
from openai import OpenAI
client = OpenAI(
api_key="YOUR_ANAI_API_KEY", # 1. your AnAiApi key
base_url="https://www.anaiapi.com/v1" # 2. point at AnAiApi
)
# 3. same call shape — just pick a model
resp = client.chat.completions.create(
model="deepseek-v4-pro",
messages=[{"role": "user", "content": "Hello!"}]
)
That's it. Your retries, streaming, function-calling and message format all stay the same — OpenAI's client just talks to a different endpoint.
cURL
curl https://www.anaiapi.com/v1/chat/completions \
-H "Authorization: Bearer $ANAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"deepseek-v4-pro","messages":[{"role":"user","content":"Hello!"}]}'
Node.js
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_ANAI_API_KEY",
baseURL: "https://www.anaiapi.com/v1"
});
What stays the same vs. what changes
| Stays the same | Changes |
|---|---|
| SDK & request format | base_url |
| Streaming / function calling | API key |
| Your existing app code | model name (pick from the list below) |
Why developers actually switch
AnAiApi is an OpenAI-compatible gateway to China's strongest models, billed in USD. Two reasons teams move:
- Cost. DeepSeek-V4-Pro is ~80% cheaper per output token than GPT-4o, and the Flash tier is ~94% cheaper — same code, far lower bill.
- Model choice. Access DeepSeek, Moonshot Kimi, Zhipu GLM and MiniMax through one integration, no separate Chinese accounts.
| Model (via AnAiApi) | Input $/1M | Output $/1M |
|---|---|---|
| DeepSeek-V4-Pro | $0.88 | $1.76 |
| DeepSeek-V4-Flash | $0.28 | $0.56 |
| Kimi-K3 | $6.79 | $33.95 |
| Zhipu GLM-4.5 | $1.08 | $3.94 |
| MiniMax-M3 | $1.24 | $4.96 |
| OpenAI GPT-4o (ref) | $2.50 | $10.00 |
Models you can call today
deepseek-v4-pro deepseek-v4-flash kimi-k3 glm-4.5 MiniMax-M3
Swap the model field to route between them — or build multi-model fallback without extra integrations. The full list is in the API documentation.
Switch in 3 lines — free
Keep your OpenAI code. Cut your bill. Get free starter credits.
Create free accountFAQ
Do I need to rewrite my app?
No. Keep the OpenAI SDK; only change base_url and the API key. Message format, streaming and tool calls are unchanged.
Which model should I start with?
deepseek-v4-pro for quality, deepseek-v4-flash for cheap high-volume calls. Swap anytime.