๐Ÿ”ง MIGRATION GUIDE ยท 3 minutes

From Anthropic SDK to OpenAI SDK: Migrate to NovAI Claude in 3 Lines

If your team is already using openai-python, you don't need to install anything new. Change the base URL, keep your code, save 50-65% on every call.

Home / Blog / OpenAI-Compatible Migration

TL;DR โ€” NovAI's Claude gateway is fully OpenAI-compatible. Python, Node.js, Go, LangChain, LlamaIndex, Dify, Cursor, Continue.dev โ€” they all work. You change one line (the base URL) and one line (the API key). Model names map 1:1 to Anthropic's naming: claude-opus-4-7, claude-sonnet-4-6, claude-haiku-4-5.

Why migrate?

If you are running production workloads on Anthropic's direct API, you are paying:

And that's before you factor in the fact that most Chinese developers can't access Anthropic directly without a proxy โ€” NovAI handles the upstream routing for you, with a China-mainland-friendly endpoint.

Already validated: We ran 4 waves of tests (connectivity, overhead audit, One-API billing formula, 6-scenario semantic checks). See the full report in We Found Claude at 65% Off in China โ€” And Proved It Actually Works.

Python โ€” the 3-line migration

Before (Anthropic SDK)

from anthropic import Anthropic

client = Anthropic(api_key="sk-ant-...")

resp = client.messages.create(
    model="claude-opus-4-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(resp.content[0].text)

After (OpenAI SDK โ†’ NovAI)

from openai import OpenAI

client = OpenAI(
+   api_key="sk-novai-...",          # your NovAI key
+   base_url="https://aiapi-pro.com/v1",  # that's it
)

resp = client.chat.completions.create(
+   model="claude-opus-4-7",          # use the 4.7 naming
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)

That's it. Three lines changed. No new SDK, no schema rewrite, no tool-calling translation. If you were already using OpenAI's SDK for GPT models, you literally just swap the base_url per request.

Node.js / TypeScript

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.NOVAI_API_KEY,
  baseURL: "https://aiapi-pro.com/v1",
});

const resp = await client.chat.completions.create({
  model: "claude-sonnet-4-6",
  messages: [{ role: "user", content: "Summarize this PR..." }],
  max_tokens: 2048,
});

console.log(resp.choices[0].message.content);

LangChain

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="claude-opus-4-7",
    api_key="sk-novai-...",
    base_url="https://aiapi-pro.com/v1",
    temperature=0.3,
)

result = llm.invoke("Write a SQL query that...")
print(result.content)

Dify / Cursor / Continue.dev

All three tools accept a custom "OpenAI-compatible" provider. Fill in:

FieldValue
Provider typeOpenAI-compatible
API Base URLhttps://aiapi-pro.com/v1
API KeyYour NovAI key (sk-novai-...)
Model nameclaude-opus-4-7 / claude-sonnet-4-6 / claude-haiku-4-5

Feature support matrix

FeatureStatusNotes
Chat completionsโœ… Full1:1 with OpenAI schema
Streaming (SSE)โœ… Fullstream=True works
Tool callingโœ… FullOpenAI tools format, auto-translated upstream
Vision (image input)โœ… FullPNG / JPEG URL or base64
JSON modeโœ… Fullresponse_format respected
1M context windowโœ… Opus 4.7 onlySonnet/Haiku: 200K
System promptโœ… FullPut it as role: system like OpenAI
Token counting note: Because the gateway normalizes between Anthropic and OpenAI formats, every call adds ~130 tokens (Opus) or ~413 tokens (Sonnet/Haiku) of format-conversion overhead. We audited this and it's already priced into our public rates โ€” what you see on the pricing page is what you pay end-to-end.

Environment variable setup

# .env
NOVAI_API_KEY=sk-novai-xxxxxxxxxxxxxxxxxx
NOVAI_BASE_URL=https://aiapi-pro.com/v1

# Python
import os
from openai import OpenAI
client = OpenAI(
    api_key=os.getenv("NOVAI_API_KEY"),
    base_url=os.getenv("NOVAI_BASE_URL"),
)

Rollback plan

Because the only real change is the base URL and the API key, rolling back is trivial. Wrap the client factory:

def make_client():
    if os.getenv("USE_NOVAI") == "1":
        return OpenAI(api_key=os.getenv("NOVAI_API_KEY"),
                      base_url="https://aiapi-pro.com/v1")
    return OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

# Flip one env var to switch providers per deployment.

Ready to cut your Claude bill in half?

Sign up in 30 seconds. Get $1 free credit. Test Opus 4.7, Sonnet 4.6, and Haiku 4.5 with your real workload before you commit.

Get free NovAI credits โ†’

Further reading