EN ▾

OpenAI Compatible API Spec: Request and Response Shape

There is no separate standard document: the openai compatible api spec is the request and response format of OpenAI's chat completions endpoint, copied by other providers. This page walks through that shape field by field, with a curl example against a live endpoint.

Last updated

Summary

  • The de facto spec is the chat completions format: POST /v1/chat/completions, bearer auth, JSON in and out.
  • A minimal request needs only model and messages; everything else is optional.
  • This API accepts model id uncensored and passes through temperature, top_p, stop, seed and penalties.
  • Streaming, tool calling and JSON mode follow the same field names as the original.
Blueprint-style rail carrying request and response envelopes, illustrating an API specification

What the spec is

Providers say "OpenAI compatible" when their HTTP interface matches the one the OpenAI SDKs expect. The reference is the public documentation of that interface, and the part almost everyone copies is the chat completions endpoint. If your client sends a request in that format and understands the reply, it works with any service that implements the same contract, whatever model sits behind it.

The contract has four layers. The transport is HTTPS with JSON bodies. Authentication is a bearer token. The request is a JSON object with a model name and a list of messages. The response is a JSON object with a list of choices and a usage block. Streaming adds a fifth layer: server-sent events that deliver the response in pieces. The rest of this page covers each layer in order, using this site's endpoint, https://api.apicompatibleopenai.com/v1.

A minimal request

A working call needs a URL, an Authorization header, and a body with two fields.

curl https://api.apicompatibleopenai.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [
      {"role": "system", "content": "You answer in one sentence."},
      {"role": "user", "content": "What is an HTTP header?"}
    ]
  }'

The model id for this API is always uncensored. Messages are objects with a role (system, user, assistant or tool) and a content string. The conversation history is yours to maintain: the server keeps no session between calls, so each request carries every earlier turn that the model should see.

The response object

The reply is a JSON object. The fields below are the ones client libraries read.

FieldMeaning
idIdentifier of the completion
objectType tag, chat.completion for a full response
modelThe model that answered
choices[0].messageThe assistant message with role and content, and tool_calls when the model calls a function
choices[0].finish_reasonWhy generation stopped, for example stop for a natural end or length for a cut-off
usageToken counts for the prompt and the completion, which billing is based on

Read finish_reason in production code. A value of length means the answer was truncated, and treating that text as complete is a common source of broken JSON and half-finished replies. In the real response you will also find the request id in the X-Request-Id header, and your remaining credit in X-Balance-USD.

Request fields this API accepts

The fields below are accepted. Anything beyond them is outside what this API documents, so test it before you depend on it.

  • model: always uncensored.
  • messages: the conversation, including system and tool messages.
  • stream: set to true for server-sent events, with usage reported at the end of the stream.
  • max_tokens: optional. The completion may use whatever is left of the 100,000-token window shared by prompt and completion.
  • temperature, top_p, stop, seed, and the frequency and presence penalties: passed through to the model.
  • tools and tool_choice: function calling, with streamed tool_calls and results returned as messages with role: "tool".
  • response_format: {"type":"json_object"} for JSON mode.

Besides chat completions the API implements POST /v1/responses and GET /v1/models. It is text only, so there are no image, audio, embedding or fine-tuning endpoints. The documentation is the place to confirm any parameter not in this list.

Tool calling and JSON mode

Two features change the response shape, so they deserve a closer look. With tools, you describe functions in the request, and the assistant message may come back with tool_calls instead of text. You run the function yourself, append a message with role set to tool and the matching call id, and send the whole conversation again.

from openai import OpenAI

client = OpenAI(
    base_url="https://api.apicompatibleopenai.com/v1",
    api_key="YOUR_API_KEY",
)

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

r = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Weather in Lisbon?"}],
    tools=tools,
    tool_choice="auto",
)

msg = r.choices[0].message
if msg.tool_calls:
    call = msg.tool_calls[0]
    print(call.function.name, call.function.arguments)

JSON mode is simpler: set response_format to {"type":"json_object"} and ask for JSON in the prompt. The reply is then a JSON string inside message.content. Parse it with a normal JSON parser and keep a fallback for the rare malformed result.

Streaming format

With stream set to true, the server answers with text/event-stream. Each event is a line starting with data: followed by a JSON chunk, and the stream ends with the literal data: [DONE]. Chunks use the object type chat.completion.chunk, and the text lives in choices[0].delta.content instead of message.content.

curl -N https://api.apicompatibleopenai.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","stream":true,"messages":[{"role":"user","content":"Count to three."}]}'

The -N flag turns off curl buffering so you see events as they arrive. One operational detail follows from how streams work: a streamed request keeps its concurrency slot until the stream ends. On a full key that is 8 slots, on a trial key 2.

Multi-turn conversations and roles

The messages array is how every compatible API models a conversation. Order matters: the model reads the list from top to bottom. A system message at the start sets behaviour. User and assistant messages alternate after it. When the model asked for a tool, an assistant message carries the tool_calls, and each result goes back as a tool message that points at the call it answers.

Because nothing is stored on the server between calls, a second turn looks like this: the same list as before, plus the assistant reply you received, plus the new user message. Your application owns that list, which gives you full control over what the model sees. It also means the input token count grows with each turn, and billing follows it. Trim or summarize old turns when conversations get long, and keep the total under the 100,000-token window.

Errors and the parts the spec leaves open

The spec is clear about the happy path and loose about the rest. Status codes and error bodies are where providers diverge most, so handle them defensively. This API returns HTTP 429 when you exceed a limit. The error code is rate_limited for requests per minute (300 on a full key, 60 on a trial key) and concurrency for too many requests at once. On temporary overload you also get 429, with a Retry-After: 5 header.

Failed or refused requests are not billed. Successful ones cost $0.15 per 1M input tokens and $0.50 per 1M output tokens; see the pricing page for top-ups. To try the format yourself, the API key page explains the one-click $0.50 trial. Before you start, the pricing checklist helps you work out what a workload will cost.

Common questions

Is there an official OpenAI-compatible API spec document?

Not as a separate standard. The practical spec is the public chat completions request and response format, which other providers implement.

What is the minimum request to a compatible endpoint?

A POST to /v1/chat/completions with a bearer key, and a JSON body containing model and messages. For this API the model is uncensored.

Which parameters does this API pass through?

Temperature, top_p, stop, seed and the penalties, plus stream, tools, tool_choice and response_format. Max_tokens is optional.

Does it support the Responses endpoint?

Yes, POST /v1/responses is available alongside chat completions and GET /v1/models.

Get your key in one step

Sign up, copy your key, update your base URL. Done.

Start now

No subscription. Prepaid credit does not expire.