NewKimi K3.1 Pro is now availableTry it now
GuidePublished 5 min read

OpenAI-Compatible LLM API Migration in 3 Lines of Code

Migrate OpenAI Python, Node, Anthropic SDK, LiteLLM, and curl to Inference.net in 3 lines. Compare live model pricing, 1M context, and US ZDR.

Inference.net

Direct answer: how to migrate to an OpenAI-compatible LLM API

To migrate an existing OpenAI application to Inference.net, change exactly three values: set base_url (baseURL in Node) to https://api.inference.net/v1 (or https://us.api.inference.net/v1 for US-only hosted inference), swap api_key to your INFERENCE_API_KEY, and set model to a live model ID from GET https://api.inference.net/v1/models (such as deepseek-v4.1-flash-1017, glm-5.3, or moonshotai/kimi-k3.1-pro). Your existing messages, tools, response_format, streaming loops, and usage parsing stay unchanged. Applications built on the Anthropic SDK can make the same 3-line swap to https://api.inference.net using native POST /v1/messages with zero proxy.

Endpoint map: one key across four wire formats

Wire protocolGlobal base URLUS-only hosted base URLNotes
OpenAI Chat Completions (/v1/chat/completions)https://api.inference.net/v1https://us.api.inference.net/v1Standard OpenAI Python and TypeScript SDKs
OpenAI Responses (/v1/responses)https://api.inference.net/v1https://us.api.inference.net/v1Supported across live catalog models and Codex CLI
Native Anthropic Messages (/v1/messages)https://api.inference.nethttps://us.api.inference.netOmit /v1; SDKs append /v1/messages automatically
OpenAI Batch & Files (/v1/batches, /v1/files)https://batch.inference.net/v1Not applicableUp to 1,000,000 requests/file, 25%+ discount; requires credit key with ZDR disabled

3-line drop-in migration snippets

Create a key in API keys (or register first) and export INFERENCE_API_KEY.

1. OpenAI Python SDK

python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.inference.net/v1",       # Line 1: swap base URL
    api_key=os.environ["INFERENCE_API_KEY"],       # Line 2: swap API key
)

response = client.chat.completions.create(
    model="deepseek-v4.1-flash-1017",              # Line 3: pick a live model ID
    messages=[{"role": "user", "content": "Write a SQL query to find duplicate emails."}],
    stream=True,
    stream_options={"include_usage": True},
)

for chunk in response:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

2. OpenAI Node / TypeScript SDK

typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.inference.net/v1",         // Line 1: swap base URL
  apiKey: process.env.INFERENCE_API_KEY,           // Line 2: swap API key
});

const stream = await client.chat.completions.create({
  model: "deepseek-v4.1-flash-1017",               // Line 3: pick a live model ID
  messages: [{ role: "user", content: "Write a SQL query to find duplicate emails." }],
  stream: true,
  stream_options: { include_usage: true },
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

3. Native Anthropic SDK (/v1/messages)

Inference.net translates Anthropic Messages payloads directly into open-weight serverless models without a middleman proxy:

typescript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "https://api.inference.net",            // Line 1: omit /v1
  apiKey: null,
  authToken: process.env.INFERENCE_API_KEY,        // Line 2: pass Inference.net key
});

const message = await client.messages.create({
  model: "deepseek-v4.1-flash-1017",               // Line 3: pick any messages-capable model
  max_tokens: 1024,
  messages: [{ role: "user", content: "Summarize the tradeoffs of cursor pagination." }],
});

console.log(message.content);

4. LiteLLM Python SDK and Proxy

Prefix every Inference.net model ID with openai/ so LiteLLM routes it through its OpenAI-compatible adapter and strips only the leading openai/ prefix:

python
import os
from litellm import completion

response = completion(
    model="openai/deepseek-v4.1-flash-1017",
    api_base="https://api.inference.net/v1",
    api_key=os.environ["INFERENCE_API_KEY"],
    messages=[{"role": "user", "content": "Explain idempotency keys in two sentences."}],
)

print(response.choices[0].message.content)

For multi-model fallback routing, health checks, and additional_drop_params: ["prompt_cache_key"] on DeepSeek routes, see the full LiteLLM integration guide.

5. Plain curl

curl
curl -sS https://api.inference.net/v1/chat/completions \
  -H "Authorization: Bearer $INFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4.1-flash-1017",
    "messages": [{"role": "user", "content": "Return a JSON object with status ok."}],
    "response_format": {"type": "json_object"}
  }'

Live catalog pricing: drop-in model replacements

Every model ID, context limit, and per-1M-token rate below was verified directly against GET https://api.inference.net/v1/models on 2026-12-06. All listed models expose chat, responses, and messages endpoints:

Model IDBest migration roleContext / max outputFresh input ($/1M)Cached read ($/1M)Output ($/1M)US-hosted ZDR
deepseek-v4.1-flash-1017Default coding, agents, high-volume chat1,040,000 / 393,216$0.08$0.007$0.635Yes (us.api.inference.net)
glm-5.3-flashOutput-heavy generation, image + video1,048,576 / 262,144$0.10$0.03$0.35Yes (us.api.inference.net)
glm-5.3Deep reasoning and long code generation1,048,576 / 943,718$0.084$0.079$3.00Yes (us.api.inference.net)
moonshotai/kimi-k3.1-proFrontier open-weight reasoning and architecture1,048,576 / 1,048,576$1.80$0.198$9.00Yes (us.api.inference.net)
inference-net/schematron-v2-turboHigh-throughput HTML-to-JSON extraction128,000 / 8,192$0.03$0.03$0.15Yes (us.api.inference.net)
gpt-4.1Reference closed-weight baseline1,047,576 / 32,768$2.00$0.50$8.00External route
gpt-5.4Frontier closed-weight baseline1,050,000 / 128,000$2.50 (<= 272K in)*$0.25 (<= 272K in)*$15.00 (<= 272K in)*External route
claude-sonnet-4-6Anthropic baseline on one key1,000,000 / 128,000$3.00$0.30$15.00External route

*gpt-5.4 base rates apply below 272,000 input tokens. Requests above 272,000 input tokens bill at the long-context tier: $5.00/1M input, $0.50/1M cached read, and $22.50/1M output. Browse all live models, capabilities, and rate sheets in the model catalog.

Production migration checklist (avoiding 4 common gotchas)

  1. Match prompt-cache parameters per family: Pass prompt_cache_key on glm-5.3, glm-5.3-flash, and OpenAI models, and omit prompt_cache_key on deepseek-v4.1-flash-1017 and deepseek-v4.1-flash (DeepSeek uses implicit prefix caching and may reject requests with prompt_cache_key). See the Prompt Caching Guide.
  2. Respect temperature behavior on reasoning models: glm-5.3 and glm-5.3-flash always think and sample at 1.0 regardless of your temperature parameter. deepseek-v4.1-flash-1017 samples at 1.0 when thinking is active and respects your temperature when reasoning_effort is set to "none".
  3. Verify ZDR and regional endpoints before cutover: Eligible Inference.net-hosted, non-ad models (deepseek-v4.1-flash-1017, glm-5.3, glm-5.3-flash, moonshotai/kimi-k3.1-pro, inference-net/schematron-v2-turbo) run with default Zero Data Retention and accept traffic on https://us.api.inference.net/v1. Third-party-routed models (gpt-5.4, claude-sonnet-4-6) return 400 region_not_supported on us.api.inference.net and follow upstream retention terms on api.inference.net.
  4. Use dedicated Batch base URL for offline jobs: Route OpenAI Batch and Files calls to https://batch.inference.net/v1 using a credit-billing API key with team ZDR disabled (ZDR-enabled teams receive 403 Forbidden on /v1/batches and /v1/files). See Batch API docs.

Need to keep an existing OpenAI or Anthropic key during rollout?

If you want unified logging, task tagging (x-inference-task-id, x-inference-environment), and gradual traffic shifting before moving billing over, pass x-inference-provider and x-inference-provider-api-key headers to https://api.inference.net/v1 to proxy through the Inference.net Gateway with your own provider key. Gateway passthrough requires a credit-billing Inference.net API key; Inference Pass plan keys do not support x-inference-provider / x-inference-provider-api-key passthrough. See API quickstart.

Frequently asked questions

Do OpenAI tools, response_format, and streaming work without code changes?

Yes. Tool calling (tools and tool_choice), structured outputs (response_format with json_object or json_schema), and Server-Sent Events streaming (stream: true with stream_options: {"include_usage": true}) follow the standard OpenAI schema on supported catalog models.

Why did my Anthropic SDK call return 404 after changing baseURL?

The Anthropic SDK appends /v1/messages automatically. Set baseURL to https://api.inference.net (or https://us.api.inference.net) without a trailing /v1.

How do I verify which models are supported on us.api.inference.net?

Look for the US badge in the model catalog or inspect hosted US models such as deepseek-v4.1-flash-1017, glm-5.3, glm-5.3-flash, moonshotai/kimi-k3, moonshotai/kimi-k3.1-pro, and inference-net/schematron-v2-turbo. Requests sent to us.api.inference.net stay in US data centers end-to-end and never fall back to external providers.

Can I connect coding editors and frameworks without custom code?

Yes. Ready-to-copy configs for Claude Code, Cursor, Cline, Roo Code, OpenCode, LiteLLM, LangChain, and Vercel AI SDK are documented in the Integrations hub.

Related reading & models

Back to all guides