---
title: "OpenAI-Compatible LLM API Migration in 3 Lines of Code | Inference.net"
description: "Migrate OpenAI Python, Node, Anthropic SDK, LiteLLM, and curl to Inference.net in 3 lines. Compare live model pricing, 1M context, and US ZDR."
url: "https://inference.net/guides/openai-compatible-llm-api-migration/"
---

Guide Published December 06, 2026 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**](https://inference.net/company/)

## Migrate in 3 Lines of Code

Point your OpenAI SDK, Anthropic SDK, or LiteLLM config at https://api.inference.net/v1 to call open-weight and frontier models on one key.

## 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 protocol | Global base URL | US-only hosted base URL | Notes |
| --- | --- | --- | --- |
| OpenAI Chat Completions (`/v1/chat/completions`) | `https://api.inference.net/v1` | `https://us.api.inference.net/v1` | Standard OpenAI Python and TypeScript SDKs |
| OpenAI Responses (`/v1/responses`) | `https://api.inference.net/v1` | `https://us.api.inference.net/v1` | Supported across live catalog models and Codex CLI |
| Native Anthropic Messages (`/v1/messages`) | `https://api.inference.net` | `https://us.api.inference.net` | Omit `/v1`; SDKs append `/v1/messages` automatically |
| OpenAI Batch & Files (`/v1/batches`, `/v1/files`) | `https://batch.inference.net/v1` | Not applicable | Up 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](https://inference.net/dashboard/api-keys/) (or [register](https://inference.net/register/) first) and export `INFERENCE_API_KEY`.

### 1. OpenAI Python SDK

python

```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

```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

```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

```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](https://inference.net/docs/integrations/litellm/).

### 5. Plain `curl`

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 ID | Best migration role | Context / max output | Fresh input ($/1M) | Cached read ($/1M) | Output ($/1M) | US-hosted ZDR |
| --- | --- | --- | --- | --- | --- | --- |
| [`deepseek-v4.1-flash-1017`](https://inference.net/models/deepseek-v4-1-flash-1017/) | Default coding, agents, high-volume chat | 1,040,000 / 393,216 | `$0.08` | `$0.007` | `$0.635` | Yes (`us.api.inference.net`) |
| [`glm-5.3-flash`](https://inference.net/models/glm-5-3-flash/) | Output-heavy generation, image + video | 1,048,576 / 262,144 | `$0.10` | `$0.03` | `$0.35` | Yes (`us.api.inference.net`) |
| [`glm-5.3`](https://inference.net/models/glm-5-3/) | Deep reasoning and long code generation | 1,048,576 / 943,718 | `$0.084` | `$0.079` | `$3.00` | Yes (`us.api.inference.net`) |
| [`moonshotai/kimi-k3.1-pro`](https://inference.net/models/kimi-k3-1-pro/) | Frontier open-weight reasoning and architecture | 1,048,576 / 1,048,576 | `$1.80` | `$0.198` | `$9.00` | Yes (`us.api.inference.net`) |
| [`inference-net/schematron-v2-turbo`](https://inference.net/models/schematron-v2-turbo/) | High-throughput HTML-to-JSON extraction | 128,000 / 8,192 | `$0.03` | `$0.03` | `$0.15` | Yes (`us.api.inference.net`) |
| [`gpt-4.1`](https://inference.net/models/gpt-4-1/) | Reference closed-weight baseline | 1,047,576 / 32,768 | `$2.00` | `$0.50` | `$8.00` | External route |
| [`gpt-5.4`](https://inference.net/models/gpt-5-4/) | Frontier closed-weight baseline | 1,050,000 / 128,000 | `$2.50` (`<= 272K` in)* | `$0.25` (`<= 272K` in)* | `$15.00` (`<= 272K` in)* | External route |
| [`claude-sonnet-4-6`](https://inference.net/models/claude-sonnet-4-6/) | Anthropic baseline on one key | 1,000,000 / 128,000 | `$3.00` | `$0.30` | `$15.00` | External 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](https://inference.net/models/).

## 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](https://inference.net/guides/prompt-caching-llm-api-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](https://inference.net/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](https://inference.net/docs/api/async/batch/).

## 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](https://inference.net/docs/api/quickstart/#2-proxy-through-the-inferencenet-gateway).

## 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](https://inference.net/models/) 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](https://inference.net/docs/integrations/claude-code/), [Cursor](https://inference.net/docs/integrations/cursor/), [Cline](https://inference.net/docs/integrations/cline/), [Roo Code](https://inference.net/docs/integrations/roo-code/), [OpenCode](https://inference.net/docs/integrations/opencode/), [LiteLLM](https://inference.net/docs/integrations/litellm/), [LangChain](https://inference.net/docs/integrations/langchain/), and [Vercel AI SDK](https://inference.net/docs/integrations/vercel-ai-sdk/) are documented in the [Integrations hub](https://inference.net/docs/integrations/).

## Related resources

- **Model catalog & hubs:** [Full Model Catalog](https://inference.net/models/) · [DeepSeek API](https://inference.net/models/deepseek/) · [Kimi API](https://inference.net/models/kimi/) · [GLM API](https://inference.net/models/glm/) · [Schematron API](https://inference.net/models/schematron/)
- **Integrations & docs:** [Integrations Hub](https://inference.net/docs/integrations/) · [API Quickstart](https://inference.net/docs/api/quickstart/) · [Anthropic SDK](https://inference.net/docs/api/anthropic-sdk/) · [Batch API](https://inference.net/docs/api/async/batch/)
- **Pricing & comparison guides:** [Prompt Caching Guide](https://inference.net/guides/prompt-caching-llm-api-guide/) · [Cheapest LLM API](https://inference.net/guides/cheapest-llm-api/) · [Inference.net vs OpenAI API](https://inference.net/compare/inference-net-vs-openai-api/) · [Inference.net vs OpenRouter](https://inference.net/compare/inference-net-vs-openrouter/)

### Swap your base URL and ship in minutes

Create a free Inference.net API key to call DeepSeek V4.1 Flash, GLM-5.3, Kimi K3.1 Pro, and Schematron through the OpenAI and Anthropic SDKs you already use.

[Create API key](https://inference.net/register/?model=deepseek-v4.1-flash-1017)

Estimate Your Inference Bill

## Calculate your monthly LLM API & prompt-cache spend

Compare live input, cached-read, and output token pricing across every open-weight and frontier model on Inference.net with 0% markup.

[Open pricing calculator](https://inference.net/tools/llm-pricing-calculator/) [Explore model catalog](https://inference.net/models/)

## Related reading & models

[Back to all guides](https://inference.net/guides/)

[Guide December 06, 2026 **Prompt Caching for LLM APIs: Math, Keys, and Code** Cut multi-turn LLM API spend by 44%+ with prompt caching. Compare 40-turn cache math on DeepSeek V4.1, Kimi K3.1 Pro, and GLM-5.3 with SDK code. Read more](https://inference.net/guides/prompt-caching-llm-api-guide/) [Guide December 06, 2026 **Kimi K3 Pricing: K3.1 Pro, K3, Fast & K2.6 API Rates** Live Kimi K3 and Kimi K3.1 Pro API pricing per 1M tokens on Inference.net, with 1M-context specs, 40-turn prompt-cache math, and SDK quickstarts. Read more](https://inference.net/guides/kimi-k3-pricing/) [Guide December 05, 2026 **DeepSeek API Pricing: Live Rates, Caching Math, and Models** Live DeepSeek API pricing per 1M tokens for V4.1 Flash, V4 Pro, Cyber, and V3.2 on Inference.net, with prompt caching math and copy-paste code snippets. Read more](https://inference.net/guides/deepseek-api-pricing/) [Article February 21, 2026 **LLM API Pricing Comparison 2026: Live Rates** Compare 2026 LLM API pricing across DeepSeek V4.1 Flash ($0.103/$0.60), Kimi K3.1 Pro, GLM-5.3, GPT, and Claude, plus $0.007/1M prompt cache savings. Read more](https://inference.net/content/llm-api-pricing-comparison/)

[**Explore serverless models** Compare open-weight and frontier models, context windows, and per-token pricing.](https://inference.net/models/) [**Inference Pass plans** Predictable monthly access for coding agents and high-volume OpenAI-compatible API workloads.](https://inference.net/subscription/)
