If your app already uses the official OpenAI SDK, moving it to another OpenAI-compatible endpoint usually means changing two settings: the base URL and the API key. Usually you also change the model name. You don’t need a new SDK or a rewrite. This tutorial shows the change in Python, Node and curl, plus LangChain and the Vercel AI SDK. It also covers the things that tend to break, and how to roll the change out safely.
The examples use One AI API Key’s endpoint, https://api.oneaiapikey.com/v1, and gpt-6.1-sol as the model. The same steps work for any compatible provider.
What a base URL is
The SDK builds every request URL by adding a path to the base URL. The default base is https://api.openai.com/v1, so a chat request goes to https://api.openai.com/v1/chat/completions. Change the base to https://api.oneaiapikey.com/v1 and the same call goes to https://api.oneaiapikey.com/v1/chat/completions. The request body, the response shape and your code don’t change.
The /v1 is part of the base URL for OpenAI-format clients. Most “404 Not Found” errors after a switch come from leaving it out, or from adding it twice.
Step 1: How do I find everything I need to change?
Find everything to change by listing every place the old provider is set up before editing. Hardcoded URLs and model names tend to hide in scripts, tests and config files:
# Every place the old provider is configured or a model is named
git grep -n -E "api\.openai\.com|OPENAI_BASE_URL|base_url|baseURL|model\s*[=:]" -- . ':!*.lock'Step 2: How do I switch with environment variables only?
Setting two environment variables switches an app that creates its client with no arguments, with no code changes. Both official SDKs read two environment variables when you create a client with no arguments: OPENAI_API_KEY and OPENAI_BASE_URL. If your code uses OpenAI() or new OpenAI() with no options, setting the variables is the whole switch:
# macOS / Linux (bash, zsh)
export OPENAI_BASE_URL=https://api.oneaiapikey.com/v1
export OPENAI_API_KEY=sk-your-one ai api key-key
# Windows PowerShell
$env:OPENAI_BASE_URL = "https://api.oneaiapikey.com/v1"
$env:OPENAI_API_KEY = "sk-your-one ai api key-key"from openai import OpenAI
# With no arguments the SDK reads OPENAI_API_KEY and OPENAI_BASE_URL.
client = OpenAI()One caution: don’t put these in your shell profile. Many tools on a developer machine use the OpenAI SDK and read the same variables. If you set them globally, all of those tools switch providers. Put them in the project’s .env file or the deployment’s environment instead.
Step 3: How do I verify with curl before touching the app?
Verify with two curl requests, which tell you whether the key, the URL and the model ID are right. Test these before debugging your own code:
# 1. Does the key work, and which model IDs can it call?
curl -s $OPENAI_BASE_URL/models -H "Authorization: Bearer $OPENAI_API_KEY"
# 2. One real completion
curl -s $OPENAI_BASE_URL/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-6.1-sol", "max_tokens": 50, "messages": [{"role": "user", "content": "Say ok"}]}'The first call lists the model IDs your key can use. The second should return a short completion with a usage block. If both work, any later failure is in your app’s configuration, not in the account.
Step 4: How do I make it explicit in code?
Pass the base URL and key in code, read from your own variable names. For anything beyond a quick test, pass the settings in code, read from your own variable names. It makes the dependency visible, avoids the global-variable problem above, and lets you change the model without a deploy.
import os
from openai import OpenAI
# Your own variable names: nothing else on the machine reads them by accident.
client = OpenAI(
base_url=os.environ.get("LLM_BASE_URL", "https://api.oneaiapikey.com/v1"),
api_key=os.environ["LLM_API_KEY"],
timeout=120, # seconds; reasoning models can think for a while
max_retries=2,
)
MODEL = os.environ.get("LLM_MODEL", "gpt-6.1-sol")
resp = client.chat.completions.create(
model=MODEL,
max_tokens=300,
messages=[{"role": "user", "content": "Name three uses for a base URL setting."}],
)
print(resp.choices[0].message.content)
print(resp.usage)import OpenAI from "openai";
// new OpenAI() with no options also reads OPENAI_API_KEY and OPENAI_BASE_URL.
const client = new OpenAI({
baseURL: process.env.LLM_BASE_URL ?? "https://api.oneaiapikey.com/v1",
apiKey: process.env.LLM_API_KEY,
timeout: 120_000, // milliseconds
maxRetries: 2,
});
const MODEL = process.env.LLM_MODEL ?? "gpt-6.1-sol";
const resp = await client.chat.completions.create({
model: MODEL,
max_tokens: 300,
messages: [{ role: "user", content: "Name three uses for a base URL setting." }],
});
console.log(resp.choices[0].message.content, resp.usage);AsyncOpenAI in Python takes the same base_url and api_key arguments.
How do I switch LangChain and the Vercel AI SDK?
LangChain and the Vercel AI SDK both accept a base URL, because most frameworks pass it through to the SDK underneath:
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gpt-6.1-sol",
base_url="https://api.oneaiapikey.com/v1",
api_key=os.environ["LLM_API_KEY"],
max_tokens=300,
)
print(llm.invoke("Say ok").content)import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";
const gateway = createOpenAI({
baseURL: "https://api.oneaiapikey.com/v1",
apiKey: process.env.LLM_API_KEY,
});
// .chat() uses /chat/completions, the most widely supported endpoint.
const { text } = await generateText({
model: gateway.chat("gpt-6.1-sol"),
prompt: "Say ok",
});Step 5: Do I need to change the model IDs?
Yes, because model names are not portable between providers. An ID that exists at OpenAI may not exist on another endpoint, and the request will fail with a model error. These are the IDs One AI API Key serves through the OpenAI format today, with current rates per 1M tokens:
| Model ID | Name | Input | Output |
|---|---|---|---|
stepaudio-3-chat-preview:free | StepAudio 3 Chat Preview | $0.00 | $0.00 |
step-5:free | Step 5 | $0.00 | $0.00 |
gpt-6-luna:free | GPT-6 Luna | $0.00 | $0.00 |
nvidia-deepseek-v4-1-flash:free | DeepSeek V4.1 Flash | $0.00 | $0.00 |
minimaxai-minimax-m3-1-flash:free | MiniMax M3.1 Flash | $0.00 | $0.00 |
deepseek-v4-flash-0731-thinking:free | DeepSeek V4 Flash 0731 Thinking | $0.00 | $0.00 |
deepseek-v4-flash-0731:free | DeepSeek V4 Flash 0731 | $0.00 | $0.00 |
deepseek-v4-flash-0731-1:free | DeepSeek V4 Flash 0731 | $0.00 | $0.00 |
beam-1-0:free | Beam 1.0 | $0.00 | $0.00 |
qwen-qwen3.8-27b:free | Qwen3.8 27B | $0.00 | $0.00 |
qwen3.8-27b-uncensored:free | Qwen3.8-27B Uncensored | $0.00 | $0.00 |
dealignai-glm-5.3-flash-uncensored-fp8:free | GLM 5.3 Flash Uncensored | $0.00 | $0.00 |
nvidia-nemotron-3-ultra-550b-a55b:free | Nemotron 3 Ultra 550B | $0.00 | $0.00 |
z-ai-glm-5.3:free | GLM 5.3 | $0.00 | $0.00 |
deepseek-deepseek-v4.1-flash:free | DeepSeek V4.1 Flash | $0.00 | $0.00 |
z-ai-glm-5.3-flash:free | GLM 5.3 Flash | $0.00 | $0.00 |
ernie-5.5-flash-preview:free | ERNIE 5.5 Flash Preview | $0.00 | $0.00 |
glm-4.6v-flash:free | GLM 4.6V Flash | $0.00 | $0.00 |
glm-4.7-flash:free | GLM 4.7 Flash | $0.00 | $0.00 |
hy4-flash:free | Hy4 Flash | $0.00 | $0.00 |
dealignai-deepseek-v4.1-flash-uncensored-fp8:free | DeepSeek V4.1 Flash Uncensored | $0.00 | $0.00 |
dealignai-glm-5.3-uncensored-fp8:free | GLM 5.3 Uncensored | $0.00 | $0.00 |
moonshotai-kimi-k3.1-pro:free | Kimi K3.1 Pro | $0.00 | $0.00 |
deepseek-v4-flash:free | DeepSeek V4 Flash | $0.00 | $0.00 |
ernie-5.5-flash-preview-1:free | ERNIE 5.5 Flash Preview | $0.00 | $0.00 |
ernie-5.5-flash-preview-2:free | ERNIE 5.5 Flash Preview | $0.00 | $0.00 |
gemma-4-31b-it:free | Gemma 4 31B | $0.00 | $0.00 |
gemma4-31b:free | Gemma 4 31B Alt | $0.00 | $0.00 |
laguna-xs-2.1:free | Laguna XS 2.1 | $0.00 | $0.00 |
lfm-3-1-7b:free | LFM 3.1 7B | $0.00 | $0.00 |
longcat-2.5:free | LongCat 2.5 | $0.00 | $0.00 |
laguna-xs-2.1-1:free | Laguna XS 2.1 | $0.00 | $0.00 |
laguna-xs-2.1-uncensored:free | Laguna XS 2.1 Uncensored | $0.00 | $0.00 |
llama-3.3-70b-instruct:free | Llama 3.3 70B Instruct | $0.00 | $0.00 |
nemotron-3-nano-omni-30b-a3b-reasoning:free | Nemotron 3 Nano Omni 30B Reasoning | $0.00 | $0.00 |
nemotron-3.5-super-vl:free | Nemotron 3.5 Super VL | $0.00 | $0.00 |
nemotron-3-5-lightning:free | Nemotron 3.5 Lightning | $0.00 | $0.00 |
nvidia-nemotron-3-ultra-550b-a55b-1:free | Nemotron 3 Ultra 550B | $0.00 | $0.00 |
solar-mini4:free | Solar Mini 4 | $0.00 | $0.00 |
nemotron-3-ultra-550b-a55b-uncensored:free | Nemotron 3 Ultra 550B Uncensored | $0.00 | $0.00 |
jais-3-mova-36b-a4b:free | Jais 3 Mova 36B | $0.00 | $0.00 |
nvidia-mistral-large-4-1t-a52b:free | Mistral Large 4 | $0.00 | $0.00 |
k2-horizon-375b-a23b-uncensored:free | K2 Horizon 375B Uncensored | $0.00 | $0.00 |
k2-horizon-375b-a23b:free | K2 Horizon 375B | $0.00 | $0.00 |
glm-4.6v-flash-1:free | GLM 4.6V Flash | $0.00 | $0.00 |
glm-4.7-flash-1:free | GLM 4.7 Flash | $0.00 | $0.00 |
grok-4.7-fast:free | Grok 4.7 Fast | $0.00 | $0.00 |
roleplay-chat:free | Roleplay Chat | $0.00 | $0.00 |
Read the model from configuration, as in the examples above, rather than hardcoding it in each call. The next time you switch, it’s a config change.
What tends to break after the switch, and how do you fix it?
The common breakages after a switch are a wrong /v1 in the base URL, a leftover old key, an unknown model ID, an unsupported parameter, a short timeout and a firewall that blocks the new host.
| Symptom | Likely cause | Fix |
|---|---|---|
404 Not Found |
Base URL without /v1, or with /v1/v1 |
The base URL ends in /v1 with no trailing path |
401 Unauthorized |
The old OpenAI key is still loaded, often from a shell profile or a CI secret | Print the key’s first 6 characters at startup and compare |
| Model not found | An old model ID | Use an ID from GET /v1/models |
400 on a parameter |
A parameter the target model doesn’t support | Remove it. Reasoning models often want max_completion_tokens instead of max_tokens |
| Timeouts on long answers | Client timeout shorter than generation time | Raise the timeout, or stream the response |
| Connection refused in production | Outbound firewall or proxy allows only the old host | Add the new API host to the allowlist |
Some endpoints are specific to one provider. Files, fine-tuning, batch jobs, Assistants, and audio or image generation are not part of what One AI API Key serves. The API reference lists the endpoints we do support: chat completions, responses, messages, models and embeddings. If your app uses OpenAI-only endpoints, keep a separate client for them on OpenAI and move only the chat traffic.
OpenAI account settings such as organization and project IDs (OPENAI_ORG_ID, OPENAI_PROJECT_ID) belong to your OpenAI account. Unset them for the new client so they aren’t sent to a provider that doesn’t know them.
Step 6: How do I roll it out gradually?
Roll it out one environment at a time, because the switch is just configuration:
- Local and staging first. Run your test suite and a small set of real prompts. Compare quality, latency and the
usagenumbers with what you had before. - Production behind a flag. Keep the old values in the deployment config and switch with an environment variable, so rolling back is a redeploy, not a code change.
- Watch the first day. Track error rates by status code and compare spend in the usage log with your estimate.
If you also use coding agents, the same base URL idea applies to them. The Claude Code setup guide and the agent kits cover tool-specific settings.
Checklist
- The base URL includes
/v1and nothing after it. - The key is loaded from a project-level secret, not a shell profile.
curlto/modelsand/chat/completionsboth work with that key.- Every model ID in code and config exists on the new endpoint.
- OpenAI-only endpoints stay on a separate client.
- The rollout can be reversed by changing configuration.