EN ▾
Get API key

OpenAI Compatible API Explained for Developers

Updated

The phrase sounds like a brand, but it describes a request format. Here is what it covers, where compatibility stops, and how it relates to a hosted text-only API with its own model.

Key points

  • Compatible means the same HTTP paths, JSON fields, auth header and streaming format, not the same model or company.
  • Models, limits, prices and extra features still differ from provider to provider.
  • Switching usually means changing three values: base URL, key and model name.
  • Test streaming, tools and errors yourself before you rely on a claim of compatibility.
Identical connectors plugging into different sockets, each wired to a different machine

The plain-language definition

Here is the idea in one paragraph, openai compatible api explained without jargon. A service is OpenAI compatible when it accepts the same HTTP requests that OpenAI's own libraries send, and answers in the same JSON shape. Because of that, you can take code written for the OpenAI SDK, change where it sends requests, and it keeps working. The service behind the URL might be OpenAI, a cloud platform, a self-hosted server or a small independent provider. The format is shared; the model and the company are not.

Think of a power plug. A plug standard says nothing about what is on the other end of the wire. A kettle and a laptop charger use the same socket and do very different things. In the same way, two compatible APIs can run completely different models, with different strengths, prices and rules.

This site is one example. It exposes the format at https://api.openaicompatibleapi.com/v1 and serves a single open-weight text model, ID uncensored, run by an independent provider. It is not the official API of OpenAI or of any model maker, and it does not forward your request to other vendors.

Why this format became a common denominator

OpenAI's chat completions API shipped early, and a large number of tools, libraries and tutorials were built around it. When other providers and open-source servers appeared, copying the request format was the cheapest way to make existing tools work with them. Developers rarely want to rewrite a working integration just to try another model, so the format spread.

The result is a practical situation you can use today. Chat front ends, agent frameworks, IDE plugins, no-code automation tools and roleplay clients commonly include a field where you can enter a custom base URL and API key. SillyTavern, for example, lets you add an OpenAI-compatible endpoint. If the tool you use has such a field, it can probably talk to any compatible service.

The flip side is that the format is only a floor. It was designed around one vendor's features, so each provider decides how much of it to copy. That is why the next sections matter.

What a request and response look like

Everything starts with an HTTPS POST to a path that ends in /chat/completions. The base URL decides the host and prefix, and the client adds the rest.

curl -s https://api.openaicompatibleapi.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [
      {"role": "system", "content": "Answer in one short paragraph."},
      {"role": "user", "content": "What is an API key?"}
    ]
  }'

Four parts carry the contract:

  • The path. POST /v1/chat/completions to generate, GET /v1/models to list models.
  • The header. Authorization: Bearer followed by your key.
  • The body. A model string and a messages array of role and content pairs, plus optional settings such as temperature, top_p, stop and seed.
  • The reply. A JSON object where the answer is at choices[0].message.content and token counts are in usage.

Streaming follows the same logic. With "stream": true the server returns server-sent events, one JSON chunk per line, and the client joins the pieces. Tool calling and JSON mode are also fields in the same body. These are the pieces most compatible services implement, and this one supports all of them.

What stays the same and what changes

It helps to sort the differences into two lists before you plan a migration.

Usually the same

  • URL structure, JSON field names and the Bearer header.
  • The message roles and the way a conversation is sent as a full list each time.
  • The SSE streaming format and the final usage block.
  • The way tool calls come back and how results go in as role: "tool" messages.

Usually different

  • The model. Writing style, reasoning quality, languages, and willingness to answer sensitive topics vary a lot.
  • Context size. Here the window is 100,000 tokens, shared between prompt and completion. Other services use other sizes.
  • Limits. Here a full key gets 8 concurrent requests and 300 per minute, a trial key gets 2 and 60.
  • Extra endpoints. Many providers add images, audio, embeddings or fine-tuning. This one does not: it is text only.
  • Error details. Status codes mostly match, but names and messages may differ. Here a 429 carries the code rate_limited or concurrency.
  • Price and billing. Per-token rates, minimums and top-up rules are set by each provider.

This is why a claim of compatibility should be read as "your code will probably run" and not as "the results will match". A prompt tuned for one model can behave differently on another, even when every field is accepted.

How it works in practice with an SDK

The official SDKs make the idea concrete. They are the same libraries you would use for OpenAI, and you point them at another host with a constructor argument.

from openai import OpenAI

client = OpenAI(
    base_url="https://api.openaicompatibleapi.com/v1",
    api_key="paste-your-key-here",
)

r = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Name three uses for a webhook."}],
)
print(r.choices[0].message.content)
print(r.usage)

Many tools also read environment variables. Setting a base URL variable and a key variable in your shell or container, as described in the docs, switches a whole application without touching its code. That is the same property people exploit when they route traffic through a gateway; the trade-offs of that approach are covered in the proxy comparison.

The three values you change are always the same: base URL, key and model name. Forget the model name and you get a 404 or a validation error, because a name like gpt-4o means nothing to a different provider. On this service the right value is uncensored.

A short test plan for any compatible provider

Do not trust a feature list. Spend fifteen minutes with a script that checks what your app really needs.

  1. List models. Call GET /models and confirm the ID you plan to use.
  2. Plain chat. Send one message and read usage. Check the numbers against your own estimate of the prompt length.
  3. Streaming. Stream a long answer and cancel it halfway. Make sure your client closes the connection; on this service a stream holds its concurrency slot until it ends.
  4. Tools. Send a tool definition, let the model call it, return a result and check that the final answer uses it.
  5. JSON mode. Request {"type": "json_object"} and parse the output a hundred times. Count failures.
  6. Errors. Send a bad key, an unknown model and a request over the limit. Confirm your code handles 401, 404 and 429, and honors a Retry-After header.
  7. Long input. Send a prompt near the context limit and make sure the failure, if any, is clear.

Run the same script on any provider you consider and keep the results in a table. It also becomes a regression test when the provider updates something.

Cost, with one worked example

Compatible APIs bill per token, but each provider sets its own rates. Here the price is $0.15 per 1M input tokens and $0.50 per 1M output tokens, charged from prepaid credit. There is no subscription, failed or refused requests are not charged, and the credit never expires.

Suppose an app sends 2,000,000 input tokens and receives 400,000 output tokens in a day. Input: 2 x $0.15 = $0.30. Output: 0.4 x $0.50 = $0.20. The day costs $0.50. Because output is more than three times the price of input, long answers move the bill faster than long prompts; a tighter max_tokens or a shorter style instruction cuts cost directly.

To try the format without paying, new users can claim $0.50 of trial credit with one click on the API key page after sign-up. It lasts 7 days and needs no card. See the pricing page for top-up amounts and bonuses, or go straight to the key page.

Questions and answers

Does OpenAI compatible mean it is made by OpenAI?

No. It means the service accepts the same request format. The model and the company behind it can be completely different.

Will my existing OpenAI code work unchanged?

Usually you only change the base URL, the API key and the model name. Features the provider does not offer, such as image generation or embeddings here, will fail.

Is the output the same as with OpenAI models?

No. Compatibility covers the request and response format, not model behavior. Prompts often need retuning when the model changes.

Do I need a special library?

No. The standard OpenAI SDKs work, and so does any HTTP client that can send JSON with a Bearer header.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API keyRead the docs

$0.15per 1M input tokens

Get API key