bots-garden/razorbillpublic Fork
⑂ main
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/razorbill.git
git clone ssh://git@rickub.com/bots-garden/razorbill.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
openai-compatibility.md · 62 lines · 6.5 KBmarkdown
Blame HistoryOpen raw

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_penalty and frequency_penalty count the last 20 tokens, prompt included, as mlx-swift-lm does; OpenAI counts the whole answer. repetition_penalty works the same way, with a window set by repetition_context_size.
  • Locked settings win. An operator can impose temperature or cap max_tokens for every client, which OpenAI's API has no equivalent for.

Routes of our own, under /rzb

razorbill started with a firm rule: the OpenAI API and nothing else, no Ollama-style /api/* of its own. A second API would be a second thing to keep stable, and every feature exposed through it would be one that OpenAI clients cannot use.

The terminal interface (rzb tui) bent that rule. It is a second rzb process on the same Mac: it chats through the OpenAI API like any client, and reads the model cache and the configuration file directly, as rzb models and rzb config validate do. What only the server process knows — which models are in memory, who is waiting for them, what MLX holds, the last requests — has no OpenAI endpoint, and neither has asking the process to free a model or read its file again. Those few things got routes of their own, under /rzb/, a prefix that cannot be mistaken for an OpenAI path or for Ollama's.

They answer the machine itself only, even on a server listening on 0.0.0.0. The /v1 routes serve whoever the operator lets in; the /rzb routes act on the server for everyone, and reveal what other clients are doing. The person allowed to do that is the one at the Mac, and the address of the connection is the simplest proof of it that does not need a second key. The API key still applies on top, so a shared Mac with a key set does not open these routes to every local user.

The interface polls GET /rzb/status rather than following a stream of events. A refresh every second or so costs a few hundred bytes, needs no connection kept open, and works with curl and watch; an event stream would add a second way to learn the same state, to be kept consistent with the first.

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

 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
52
53
54
55
56
57
58
59
60
61
62
# 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](constrained-decoding.md)). OpenAI's models are trained for structured output; local models need to be told.
- **Penalties look at a window.** `presence_penalty` and `frequency_penalty` count the last 20 tokens, prompt included, as mlx-swift-lm does; OpenAI counts the whole answer. `repetition_penalty` works the same way, with a window set by `repetition_context_size`.
- **Locked settings win.** An operator can impose `temperature` or cap `max_tokens` for every client, which OpenAI's API has no equivalent for.

## Routes of our own, under /rzb

razorbill started with a firm rule: the OpenAI API and nothing else, no Ollama-style `/api/*` of its own. A second API would be a second thing to keep stable, and every feature exposed through it would be one that OpenAI clients cannot use.

The terminal interface (`rzb tui`) bent that rule. It is a second `rzb` process on the same Mac: it chats through the OpenAI API like any client, and reads the model cache and the configuration file directly, as `rzb models` and `rzb config validate` do. What only the server process knows — which models are in memory, who is waiting for them, what MLX holds, the last requests — has no OpenAI endpoint, and neither has asking the process to free a model or read its file again. Those few things got routes of their own, under `/rzb/`, a prefix that cannot be mistaken for an OpenAI path or for Ollama's.

They answer the machine itself only, even on a server listening on `0.0.0.0`. The `/v1` routes serve whoever the operator lets in; the `/rzb` routes act on the server for everyone, and reveal what other clients are doing. The person allowed to do that is the one at the Mac, and the address of the connection is the simplest proof of it that does not need a second key. The API key still applies on top, so a shared Mac with a key set does not open these routes to every local user.

The interface polls `GET /rzb/status` rather than following a stream of events. A refresh every second or so costs a few hundred bytes, needs no connection kept open, and works with `curl` and `watch`; an event stream would add a second way to learn the same state, to be kept consistent with the first.

## 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](../reference/http-api.md).
- Using the `/rzb` routes: [watch and steer a running server](../how-to/watch-and-steer-a-running-server.md).
- Running the suite: [run the tests](../how-to/run-the-tests.md#check-compatibility-with-real-openai-clients).