OpenAI compatibility — explanation
What is this about?
"OpenAI-compatible" is a promise without a specification: OpenAI documents its own API, not what another server must do to be a substitute. Every local server draws the line somewhere. This page explains where razorbill draws it, and how that line is checked.
The goal: existing clients work unchanged
The test is not "does the server accept the documented fields" but "does a program written for OpenAI work when its base URL is changed". That shifts attention to what clients actually do: the openai Python library's parse() with a Pydantic class, LangChain's bind_tools and OpenAIEmbeddings, streaming with include_usage, base64 embeddings (which the openai library requests by default, silently), error bodies that the libraries turn into typed exceptions.
Refuse rather than ignore
When a request asks for something razorbill cannot do — several choices (n), log-probabilities, images, fill-in-the-middle, a schema keyword it cannot enforce, a forced tool call for an unsupported syntax — the server answers 400 and names the field. Ignoring the field would return an answer that looks right and is not what the client asked for: one choice instead of three, a schema rule silently broken. A clear error is found in the first test run; a silent difference is found in production.
Fields that change nothing important are ignored, as OpenAI itself ignores unknown fields: user, metadata, store, service_tier…
Extensions, borrowed rather than invented
Local models do things OpenAI's API has no field for, mostly around reasoning. Where another server already defined a convention, razorbill follows it, so clients that support it work without change:
| Need | Field | Borrowed from |
|---|---|---|
| Return the reasoning apart from the answer | reasoning_content (message and deltas) |
DeepSeek, vLLM |
| Turn thinking on or off | chat_template_kwargs.enable_thinking |
vLLM |
| Hide the reasoning | include_reasoning: false |
OpenRouter |
| Count reasoning tokens | usage.completion_tokens_details.reasoning_tokens |
OpenAI |
| Sample among the k most likely tokens | top_k |
vLLM, llama-server, Ollama, mlx-lm |
| Drop unlikely tokens relative to the best one | min_p |
vLLM, llama-server, Ollama, mlx-lm |
| Discourage repeats | repetition_penalty, repetition_context_size |
vLLM, llama-server, Ollama; mlx-lm for the window |
The sampling extensions stop at what mlx-swift-lm implements. Other servers' samplers (typical_p, XTC, DRY, Mirostat…) and OpenAI's logit_bias have no implementation in it, so they are ignored like any unknown field rather than imitated.
Only thinking_budget is razorbill's own, because no common convention exists for a hard limit on reasoning tokens. /v1/models also adds loaded and kind to each model, which clients ignore.
Deliberate differences
- Defaults come from the server. OpenAI's legacy completions default to 16 tokens; razorbill uses the server's configured
max_tokens, because a local operator sets limits once for every client. - The prompt may change. With
response_format, the server adds an instruction carrying the schema to the system message (see constrained decoding). OpenAI's models are trained for structured output; local models need to be told. - Penalties look at a window.
presence_penaltyandfrequency_penaltycount the last 20 tokens, prompt included, as mlx-swift-lm does; OpenAI counts the whole answer.repetition_penaltyworks the same way, with a window set byrepetition_context_size. - Locked settings win. An operator can impose
temperatureor capmax_tokensfor every client, which OpenAI's API has no equivalent for.
How compatibility is checked
Unit tests check the shapes; they cannot check that the real libraries agree with our reading of the shapes. A separate suite, Tests/Compatibility, drives a running rzb serve with the official clients — the openai library, LangChain, and every curl example of the API reference — and asserts what a user would see: a parsed Pydantic object, a tool round trip, cosine similarities equal to the Python sentence-transformers library's, typed exceptions on errors.
It runs in two modes. On Linux, against the fake engine, it checks the protocol on every change. On the Mac, against MLX with real models, it checks behaviour; its first run found two real defects (schema keys sorted, and reasoning models writing prose into JSON fields), which unit tests had no way to see.
How it relates to the rest
- What is supported, refused and ignored, field by field: HTTP API reference.
- Running the suite: run the tests.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|