OpenAI-Compatible APIs: The Easiest Way to Switch Between AI Models

LLM DevelopmentUpdated
OpenAI-Compatible APIs: The Easiest Way to Switch Between AI Models

An OpenAI-compatible API is a model server that accepts the same requests as OpenAI's Chat Completions API. If your code already uses an OpenAI SDK, you switch to another model or provider by changing three values: the base URL, the API key and the model id. Your prompts, streaming code and tool definitions stay as they are.

That is the short answer. The longer one is that "compatible" describes the request format, not the model behind it. This guide covers what carries over when you switch, what does not, and a checklist that catches the differences before your users do.

What an OpenAI-compatible API is

The format is small. You send a POST request to /v1/chat/completions with a JSON body that names a model and carries a list of messages, each with a role: system, user, assistant or tool. You authenticate with a bearer key. The reply comes back as JSON with the model's message inside choices.

So many tools were written against this format that it became the common interface for language models. Open-source inference servers such as vLLM, llama.cpp and Ollama expose it, and so do most hosting providers. That is why nearly every AI tool, from coding agents to workflow builders, has a "base URL" field in its settings.

What the format usually covers:

Part of the APIWhat it doesSupport outside OpenAI
Chat completionsSends messages, returns the replyThe core; every compatible server has it
StreamingReturns the reply piece by piece as it is generatedAlmost always
Tool callsLets the model ask your code to run a functionDepends on the server and the model
Images inside messagesSends a picture along with the textOnly on models with vision
Model listLists the model ids the server offersMost servers
Responses API, Assistants, file storage, fine-tuningFeatures of OpenAI's own platformOften missing

The last row matters. "OpenAI-compatible" nearly always means "Chat Completions-compatible". If your application depends on platform features beyond chat, check them one by one before you plan a move.

Switch models by changing three values

With the OpenAI Python SDK, the only lines that change are the client setup and the model id:

from openai import OpenAI

client = OpenAI(
    base_url="https://YOUR-POD-ENDPOINT/v1",
    api_key="YOUR_API_KEY",
)

response = client.chat.completions.create(
    model="YOUR_MODEL_ID",  # copy the model id from your console
    messages=[
        {"role": "system", "content": "You answer in two sentences."},
        {"role": "user", "content": "What does an inference server do?"},
    ],
)
print(response.choices[0].message.content)

Without an SDK, the same request is one HTTP call, which works from any language:

curl https://YOUR-POD-ENDPOINT/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [{"role": "user", "content": "What does an inference server do?"}]
  }'

The official OpenAI SDKs also read the base URL and the key from environment variables, so many applications switch without a code change:

export OPENAI_BASE_URL="https://YOUR-POD-ENDPOINT/v1"
export OPENAI_API_KEY="YOUR_API_KEY"

Keep all three values in configuration, not in code. Then moving to a different model is a deploy setting, and so is moving back.

Streaming and tool calls carry over

Streaming is the same flag on every compatible server. The reply arrives in small pieces and you print them as they come:

stream = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "Explain what a context window is."}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

Tool calls use the same tools field. You describe a function, the model answers with the function name and arguments, and your code runs it:

tools = [{
    "type": "function",
    "function": {
        "name": "get_order_status",
        "description": "Look up the status of an order by its id.",
        "parameters": {
            "type": "object",
            "properties": {"order_id": {"type": "string"}},
            "required": ["order_id"],
        },
    },
}]

response = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "Where is order ORD-8821?"}],
    tools=tools,
)
print(response.choices[0].message.tool_calls)

You then append the function's result as a tool message and call the model again. That loop is identical on any server that supports tool calls. A full worked example is in create an AI customer support agent without OpenAI APIs.

Where "compatible" stops

The request format is shared. The model's behaviour is not. These are the differences that cause real bugs after a switch.

Model ids. Every server names its models its own way. An id that works on one endpoint returns "model not found" on another. Read the id from the provider's console or its model list, and never hard-code it.

Sampling settings. Each model family is tuned for its own temperature and top_p. Carrying the settings over from your old model is a common cause of worse output after a switch. Some settings, such as top_k, are not named arguments in the OpenAI SDK. You pass them through extra_body:

response = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "Refactor this function: ..."}],
    temperature=0.6,
    top_p=0.95,
    extra_body={"top_k": 20},
)

Reasoning controls. Many current models think before they answer and accept a reasoning_effort field, but the accepted values differ from model to model. These are the settings published for some of the models in our catalog, by their makers or by the authors of the builds:

ModelAccepted reasoning effortPublished sampling
Qwen3.8-27B Uncensoredlow, medium, xhightemperature 1.0, top_p 0.95, top_k 20 with thinking
GLM-5.3-Flash Uncensoredlow or high; anything else means maxtemperature 1.0, top_p 0.95
DeepSeek V4.1 Flash Uncensoredlow, high (the default), maxtemperature 1.0, top_p 1.0
MiniMax-M3.1-Flashlow, medium, high, xhigh, maxtemperature 1.0, top_p 0.95
Kimi K3.1 Prolow, high, maxtemperature 1.0, top_p 0.95

The same word can mean different things. Send "medium" to GLM-5.3-Flash Uncensored and you get maximum effort, because that build treats anything other than low or high as max. AI effort levels explained covers when each level is worth its extra tokens.

Context window. On our pods, Qwen3.8-27B Uncensored and Gemma4-26B-A4B Uncensored serve 256K tokens, while GLM-5.3-Flash Uncensored, DeepSeek V4.1 Flash Uncensored and Nemotron 3.5 Super Uncensored serve 1M. A prompt that fits one model overflows another. Why context length matters shows what fits in each size.

Token counts. Each model family has its own tokenizer, so the same text is a different number of tokens on a different model. Output limits and context estimates that were tuned for one model need rechecking on the next.

Tool-call quality. The format is the same everywhere. How reliably a model picks the right tool and fills in valid arguments is a property of the model. Test with your own tools, not a demo function.

Chat Completions versus the Responses API. Some newer tools default to OpenAI's Responses API. Most self-hosted servers speak Chat Completions, so those tools need one setting changed before they connect. The OpenAI Agents SDK is the usual example; the best AI agent frameworks for startups covers it.

Content filtering. Hosted per-token APIs usually run a content filter in front of the model. On a dedicated pod nothing sits in front of it. A request that was blocked before may now be answered, and the reverse can happen when you move the other way. AI chatbot guardrails vs your own GPU explains the difference.

Does an OpenAI-compatible API lower your costs?

Not by itself. The format is only an interface. What it gives you is the ability to choose where the model runs, and that choice sets the bill.

Hosted per-token APIs charge for every token the model reads and writes. Cost follows usage: low when you use little, high when an agent loops all night. A dedicated GPU is billed for time. Cost is fixed for the hours you rent, whatever passes through the model.

Neither is cheaper in every case. Per-token billing suits light or irregular use. Time billing suits steady or heavy use, long prompts and agent loops that resend a growing history on every step. Token anxiety is real works through how to find your break-even point, and Gemma 4 26B API vs self-hosted looks at the same question for one model.

Because both sides speak the same API, you can test this with real traffic. Point a share of your requests at the new endpoint for a week and compare.

A checklist for switching

  1. Move the base URL, API key and model id into configuration.
  2. List every API feature your application uses: chat, streaming, tool calls, images, structured output. Confirm each one on the new server.
  3. Replace the sampling settings with the ones published for the new model.
  4. Check the reasoning controls: the accepted values, the default, and how many output tokens thinking may use.
  5. Compare the context window with your longest real prompt, counted in the new model's tokens.
  6. Run your own test prompts, including the tool calls, and compare the answers side by side.
  7. Check what the new endpoint filters or does not filter, and add your own checks where your product needs them.
  8. Keep the old configuration so you can switch back in one step.

Where OpenLLM Buddy fits

OpenLLM Buddy Self Deploy rents you a dedicated GPU pod running one open model. Your console shows a base URL ending in /v1, an API key and the model id. The pod answers chat completions with streaming and tool calls, so the samples above run against it unchanged. Nobody else shares the pod, and prompts and outputs stay on it. You pay for pod time in packs of 11 hours, 24 hours, 1 week or 1 month, with no per-token billing.

Two models run on a single GPU and are the usual starting point. Gemma4-26B-A4B Uncensored generates 175 tokens per second on one RTX 5090 on our pods. Qwen3.8-27B Uncensored generates 79 tokens per second on the same GPU and scores higher on its maker's coding benchmarks; its request examples are in the Qwen3.8 27B Uncensored API guide. The larger models with a 1M-token context run on multi-GPU pods. The best uncensored open AI models you can deploy compares the whole catalog.

If you connect a tool instead of your own code, the integration guides show where the base URL and key go.

Deploy a model with an OpenAI-compatible API

FAQ

What is an OpenAI-compatible API?

It is a model server that accepts the same request format as OpenAI's Chat Completions API. Code and tools written for that format can talk to it after you change the base URL, the API key and the model id.

Can I use the OpenAI SDK with other models?

Yes. The official SDKs let you set a base URL, so they work with any server that implements the Chat Completions format, including self-hosted open models. You also need that server's own key and model id.

Is an OpenAI-compatible API the same as the OpenAI API?

No. It shares the request and response format for chat, streaming and usually tool calls, but the model behind it is different and platform features such as the Responses API or file storage are often absent. Sampling settings, reasoning controls and context limits also differ per model.

Do OpenAI-compatible APIs support streaming and tool calling?

Streaming is supported by almost every compatible server. Tool calling depends on both the server and the model, so check it for the exact model you plan to use and test it with your own tools.

Does switching to an OpenAI-compatible API save money?

The API format does not change the price. Savings come from where the model runs: a dedicated GPU billed by time can cost less than per-token billing when usage is steady or heavy, and more when usage is light.

More to read

Other recent articles from our blog.