On this page
To switch from the OpenAI API to open models, set OPENAI_BASE_URL and OPENAI_API_KEY to an open-model host, then change the model name. The official Python and Node SDKs read both variables, so your code stays the same. DeepSeek V4.1 Flash on NanoGPT costs $0.039 in, $0.40 out per million tokens. Boost does the same switch at a flat monthly price.
Why one URL is enough
Most open-model hosts copy OpenAI’s API: same routes, same request body, same response shape. The OpenAI SDK only needs to know where to send the request. Both official SDKs read that from the OPENAI_BASE_URL environment variable when you don’t pass one in code, per the Python README and the Node client source. The key comes from OPENAI_API_KEY the same way.
So you change three things: the base URL, the key and the model name.
Base URLs, model names and prices
Prices per million tokens, input / output, linked to each host’s pricing page.
| Host | OPENAI_BASE_URL |
DeepSeek V4.1 Flash model name | Price per 1M | Qwen3.8-27B model name |
|---|---|---|---|---|
| NanoGPT | https://api.nano-gpt.com/api/v1 |
deepseek/deepseek-v4.1-flash |
$0.039 / $0.40 | qwen/qwen3.8-27b |
| Hugging Face | https://router.huggingface.co/v1 |
deepseek-ai/DeepSeek-V4.1-Flash:cheapest |
from $0.051 / $0.567 | Qwen/Qwen3.8-27B:cheapest |
| OpenRouter | https://openrouter.ai/api/v1 |
deepseek/deepseek-v4.1-flash |
$0.051 / $0.567 + 5.5% fee | qwen/qwen3.8-27b |
| DeepInfra | https://api.deepinfra.com/v1/openai |
deepseek-ai/DeepSeek-V4.1-Flash |
$0.14 / $0.42 | Qwen/Qwen3.8-27B |
| DeepSeek API | https://api.deepseek.com |
deepseek-flash |
$0.30 / $1.20 peak | Not served |
| Off Grid AI Boost | Arrives with your key | Arrives with your key | Flat plan from $4.99 a month, usage worth twice the price | Arrives with your key |
| Off Grid AI Desktop, on your computer | http://127.0.0.1:7878/v1 |
The model you load | Free | The model you load |
Base URLs come from each host’s docs: NanoGPT, Hugging Face, OpenRouter, DeepInfra and DeepSeek. The local Off Grid AI Desktop address is covered in running local models behind an OpenAI-compatible API.
Switch in four steps
1. Point the SDK at the new host
export OPENAI_BASE_URL=https://api.nano-gpt.com/api/v1
export OPENAI_API_KEY=<your NanoGPT key>
2. Change the model name
Your code needs no new imports and no new client. Only the model string changes.
from openai import OpenAI
client = OpenAI() # reads OPENAI_BASE_URL and OPENAI_API_KEY
response = client.chat.completions.create(
model="deepseek/deepseek-v4.1-flash",
messages=[{"role": "user", "content": "Write a haiku about base URLs."}],
)
print(response.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI(); // reads OPENAI_BASE_URL and OPENAI_API_KEY
const response = await client.chat.completions.create({
model: "deepseek/deepseek-v4.1-flash",
messages: [{ role: "user", content: "Write a haiku about base URLs." }],
});
console.log(response.choices[0].message.content);
Save the JavaScript as switch.mjs and run it with node switch.mjs after npm install openai. Prefer settings in code? Pass base_url= in Python or baseURL: in JavaScript when you create the client; the value wins over the environment variable.
3. Test with one request
curl "$OPENAI_BASE_URL/chat/completions" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "deepseek/deepseek-v4.1-flash", "messages": [{"role": "user", "content": "Hello"}]}'
A JSON reply with a choices array means the URL, key and model name are right.
4. Check the routes you use
Chat completions is the route every host here serves. Check the rest before you switch production traffic:
- Responses API. DeepInfra says Responses clients can use its same base URL, and OpenRouter’s quickstart uses
responses.create. Hugging Face’s OpenAI endpoint is chat completions only. - Embeddings, images and speech. These need a model of that kind on the host. Hugging Face serves them through its own clients, not the OpenAI endpoint.
- Reasoning switches. Extra fields go in
extra_bodyin Python. DeepSeek’s docs turn on thinking withextra_body={"thinking": {"type": "enabled"}}.
What switching saves
Say your app sends 50M input and 10M output tokens a month on DeepSeek V4.1 Flash.
| Host | Arithmetic | Month |
|---|---|---|
| NanoGPT | 50 × $0.039 + 10 × $0.40 = $1.95 + $4.00 | $5.95 |
| Hugging Face, lowest route | 50 × $0.051 + 10 × $0.567 = $2.55 + $5.67 | $8.22 |
| DeepInfra | 50 × $0.14 + 10 × $0.42 = $7.00 + $4.20 | $11.20 |
| DeepSeek API, peak | 50 × $0.30 + 10 × $1.20 = $15.00 + $12.00 | $27.00 |
| Boost Starter or Pro, cohort 1 | Flat, with $9.99 or $19.99 of usage included | $4.99 or $9.99 |
The per-token hosts win at low, steady volume. A flat plan wins when the volume moves, because the bill doesn’t. Every model and host is ranked on the API price index, and the full table is in cheapest OpenRouter alternatives.
Switch to Off Grid AI Boost
Boost is one OpenAI-compatible key for open models, covering text, vision, speech, voice, embeddings, image and video. The page names Qwen 3.8 and DeepSeek V4.1 Flash. The switch is the same three lines:
export OPENAI_BASE_URL=$BOOST_BASE_URL # arrives with your key
export OPENAI_API_KEY=$BOOST_API_KEY
# then set model= to the Boost model name for Qwen or DeepSeek
Plans are flat: Starter $4.99, Pro $9.99 or Max $49.99 a month for cohort 1, half the regular price for as long as you stay. Each includes usage worth its full regular price every month, and you can top up any time. “We don’t keep your prompts or train on them.” The serving code will be open source, so you can move to your own hardware later. And the same open models run in the free Off Grid AI apps on your own phone or computer.
Boost is a pre-order. Your key and base URL arrive by email in January 2027, and your plan starts that day; if it misses January, you get all your money back. Need to switch today? Use NanoGPT or DeepInfra now and change two variables in January.
Not working? Symptom, check, fix
| Symptom | Check | Fix |
|---|---|---|
| Requests still reach OpenAI | base_url is hard-coded in the client |
Remove it, or set it to the new host |
| 404 on every call | The base URL ends in /chat/completions, or misses /v1 or /api/v1 |
Copy the base URL exactly from the table |
| “Model not found” | Model names differ per host | Use the host’s name, like deepseek-ai/DeepSeek-V4.1-Flash on DeepInfra |
| 401 | The old OpenAI key is still in OPENAI_API_KEY |
Export the new host’s key |
responses.create fails |
The host doesn’t serve the Responses API | Use chat.completions.create, or a host that serves Responses |
| Python rejects an unknown argument | A host-specific field like thinking |
Pass it in extra_body |
FAQ
What is an OpenAI-compatible API?
An API that accepts the same requests and returns the same responses as OpenAI’s, usually the /chat/completions route. You call it with the official OpenAI SDK by changing the base URL, the key and the model name.
How do I change the base URL in the OpenAI SDK?
Set the OPENAI_BASE_URL environment variable, which both the Python and Node SDKs read, or pass base_url in Python or baseURL in JavaScript when you create the client.
What is the base URL for DeepSeek’s API?
https://api.deepseek.com for the OpenAI format, with the model name deepseek-flash for DeepSeek V4.1 Flash. DeepSeek also serves an Anthropic format at https://api.deepseek.com/anthropic.
Will my existing OpenAI code work unchanged? Chat completions calls do once you change the base URL and model name. Check the routes you use: Hugging Face’s OpenAI-compatible endpoint is chat completions only, while DeepInfra says Responses API clients can use its same base URL.
Can I switch to Off Grid AI Boost the same way?
Yes. Boost is one OpenAI-compatible key for open models, so you change OPENAI_BASE_URL, OPENAI_API_KEY and the model name. It’s a pre-order, and the base URL arrives with your key in January 2027.
For a DeepSeek-specific walkthrough, see calling the DeepSeek API with the OpenAI SDK.