bots-garden/razorbillpublic Fork
⑂ v0.3.0
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
http-api.md · 424 lines · 24.4 KBmarkdown
Blame HistoryOpen raw

Reference: HTTP API

The endpoints of rzb serve, the fields each one accepts, refuses or ignores, and what it answers. Error bodies and status codes are in the errors reference; the server's options in the command-line reference and the configuration reference.

The examples use mlx-community/Qwen3-4B-4bit as chat model and BAAI/bge-small-en-v1.5 as embedding model, both pulled beforehand with rzb models pull. The compatibility suite runs every curl example of this page against a real server (scripts/compat.sh).

General rules

Rule Value
Base URL http://<host>:<port>/v1, by default http://127.0.0.1:7920/v1
Request body JSON (Content-Type: application/json), at most 16 MiB (larger: 413)
Response body JSON, compact, keys sorted; streams are Server-Sent Events
Authentication Authorization: Bearer <key> on every route except /health, when the server has an API key (--api-key-env); none otherwise
CORS Off, unless --cors-origin / server.cors_origin is set
Unknown fields Ignored, as OpenAI does, unless listed as refused below
Connections Generation endpoints answer with Connection: close (the server watches the connection to stop a generation whose client has left)
Concurrency One generation at a time per model; other requests for that model wait in a queue (limits)

Endpoints

Method and path Purpose
GET /health Liveness check, no authentication
GET /v1/models Models the server can serve
GET /v1/models/{id} One of them ({id} may contain /)
POST /v1/chat/completions Chat answer, plain or streamed, with structured output, tools and reasoning
POST /v1/completions Legacy text completion: the prompt is continued as raw text
POST /v1/embeddings Embedding vectors
GET /rzb/status, POST /rzb/… razorbill's own admin routes, from this machine only: see local admin routes

Any other path answers 404 with code unknown_url.

GET /health

curl -s http://127.0.0.1:7920/health

Answer: {"status":"ok"}, status 200, whenever the process is up.

GET /v1/models

curl -s http://127.0.0.1:7920/v1/models

Answer: {"object": "list", "data": [<model>, …]}. The list holds, in this order: the models declared in the configuration (under their id), then the loadable models of the Hugging Face cache, then models loaded by their Hugging Face id that are neither.

Field of <model> Type Value
id string The name to put in "model"
object string "model"
created integer The server's start time (Unix seconds)
owned_by string "razorbill"
loaded boolean razorbill extension: in memory now
kind string razorbill extension: chat or embedding. A cached model that is not declared is reported as chat (the cache does not record the kind)

GET /v1/models/{id} answers one <model>, or 404 model_not_found.

Model names

The "model" of a request is, in this order of lookup:

  1. the id of a model declared in the configuration; its kind must match the endpoint (chat for completions, embedding for embeddings), otherwise 400;
  2. a Hugging Face repository id, org/name or org/name@revision, of a model in MLX format. It is downloaded on its first use if it is not in the cache, and taken to be of the endpoint's kind. A repository the cache shows without .safetensors weights (GGUF, for instance) is refused with 400 model_not_supported.

Anything else is a 404 model_not_found.

POST /v1/chat/completions

curl -s http://127.0.0.1:7920/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mlx-community/Qwen3-4B-4bit",
    "messages": [
      {"role": "system", "content": "Answer in one sentence."},
      {"role": "user", "content": "What is MLX?"}
    ],
    "temperature": 0.2,
    "max_tokens": 200
  }'

Request fields

Field Type Default Description
model string required See model names
messages array required, not empty See messages
temperature number, 0–2 configuration, else 0.6 Sampling temperature
top_p number, >0–1 configuration, else 1.0 Nucleus sampling
max_tokens integer ≥ 1 configuration, else 1024 Most tokens generated, reasoning included
max_completion_tokens integer ≥ 1 — Same as max_tokens; wins when both are sent
stop string or array of ≤ 4 strings none The answer ends before the first occurrence; finish_reason is then stop
seed integer random Sampler seed: same seed and settings, same answer
presence_penalty number, −2–2 none Penalises tokens present among the last 20 tokens (prompt included)
frequency_penalty number, −2–2 none Penalises tokens by their frequency among the last 20 tokens (prompt included)
top_k integer ≥ 0 configuration, else 0 (off) Extension (vLLM, llama-server, Ollama, mlx-lm): sample among the top_k most likely tokens only
min_p number, 0–1 configuration, else 0 (off) Extension: drop tokens less likely than min_p × the most likely one
repetition_penalty number > 0 configuration, else none Extension: divides the score of tokens seen in the last repetition_context_size tokens (prompt included); above 1 discourages repeats
repetition_context_size integer ≥ 1 configuration, else 20 Extension (mlx-lm's name): how many recent tokens repetition_penalty looks at
stream boolean false Stream the answer as Server-Sent Events (streaming)
stream_options.include_usage boolean false Add a last chunk with usage
response_format object {"type": "text"} text, json_object or json_schema; see structured output
tools array none Functions the model may call; see tools
tool_choice string or object auto with tools, none without none, auto, required, or {"type": "function", "function": {"name": "…"}}
parallel_tool_calls boolean true; false for a forced call false: at most one call
reasoning_effort string configuration none and minimal turn thinking off; low, medium, high turn it on (all three alike)
chat_template_kwargs.enable_thinking boolean — vLLM's switch; wins over reasoning_effort
thinking_budget integer ≥ 0 configuration razorbill extension: most tokens of reasoning before the model must answer
include_reasoning boolean configuration, else true OpenRouter's switch: false leaves out reasoning_content (the model still thinks)

The configuration's locked values win over the request: temperature, top_p, top_k, min_p, repetition_penalty, repetition_context_size, thinking and show_reasoning are imposed, max_tokens and thinking_budget are ceilings (configuration reference).

Refused fields

These fields answer 400 naming the field, rather than being silently ignored:

Field Refused when
n other than 1
logprobs true
a message with role other than system, developer, user, assistant, tool always
a content part of type other than text (images, audio…) always
response_format combined with a forced tool call tool_choice is required or names a function, or a tool is strict

Messages

Role Fields Notes
system, developer content developer is treated as system
user content
assistant content (may be null), tool_calls Previous answers, with the calls the model made
tool content, tool_call_id, name The result of a call

content is a string or an array of {"type": "text", "text": "…"} parts, joined with a line break. In tool_calls, function.arguments must be a JSON object encoded as a string, as OpenAI sends it.

The conversation is rendered with the model's own chat template. The server keeps no state between requests.

Response

{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "created": 1764096042,
  "model": "mlx-community/Qwen3-4B-4bit",
  "choices": [{
    "index": 0,
    "message": {"role": "assistant", "content": "…", "reasoning_content": "…", "tool_calls": […]},
    "logprobs": null,
    "finish_reason": "stop"
  }],
  "usage": {"prompt_tokens": 20, "completion_tokens": 9, "total_tokens": 29,
            "completion_tokens_details": {"reasoning_tokens": 120}}
}
Field Present Value
id always chatcmpl- and 24 hexadecimal digits
model always The "model" of the request, as sent
message.content always The answer; null when the model only called tools
message.reasoning_content when the model thought and reasoning is shown The reasoning, without the <think> tags
message.tool_calls when the model called tools [{"id", "type": "function", "function": {"name", "arguments"}}], arguments a JSON string
finish_reason always stop, length (token limit) or tool_calls
usage.prompt_tokens_details.cached_tokens when part of the prompt was reused Prompt tokens taken from the KV cache of the previous request instead of being read again; included in prompt_tokens (why)
usage.completion_tokens_details.reasoning_tokens when the model thought Pieces of reasoning received (about one per token), also counted when reasoning is hidden

When a stop sequence ends the answer, the engine is interrupted before it reports its counts: usage then counts one token per piece of text and prompt_tokens is 0.

Structured output

response_format Effect
{"type": "text"} No constraint
{"type": "json_object"} The answer is one JSON object
{"type": "json_schema", "json_schema": {"name": "…", "schema": {…}, "strict": true}} The answer is one JSON value valid against schema
  • The constraint is enforced while tokens are generated (constrained decoding, on macOS with MLX); a reasoning model thinks freely first, and the constraint applies after its reasoning.
  • The server adds one instruction to the system message (a system message is created if there is none): Answer with a single JSON object. for json_object; Answer with a single JSON object that follows this JSON Schema: followed by the schema for json_schema.
  • Object properties are generated in the order the schema lists them.
  • With "strict": true, a schema that uses a keyword the decoder cannot enforce is refused with 400 naming it and where it is: not, if, then, else, dependentRequired, dependentSchemas, multipleOf, uniqueItems, contains, minContains, maxContains. Without strict, such keywords are ignored.
curl -s http://127.0.0.1:7920/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mlx-community/Qwen3-4B-4bit",
    "messages": [{"role": "user", "content": "Describe Lyon."}],
    "response_format": {"type": "json_schema", "json_schema": {"name": "city", "strict": true,
      "schema": {"type": "object", "additionalProperties": false, "required": ["name", "country"],
        "properties": {"name": {"type": "string"}, "country": {"type": "string"}}}}},
    "reasoning_effort": "none"
  }'

Tools

tools[i] field Type Rules
type string "function"
function.name string 1–64 letters, digits, _ or -; unique
function.description string Optional
function.parameters object A JSON Schema object; default {"type": "object", "properties": {}}
function.strict boolean true: the arguments are generated under the schema (same keyword limits as strict structured output)
tool_choice Effect
none Tools are not offered to the model; it answers in text
auto The model decides; its calls are parsed from its output
required The answer is tool calls only, generated under a grammar
{"type": "function", "function": {"name": "f"}} The answer is one call to f, generated under a grammar
  • Forced calls (required, a named function, or a strict tool) are only possible for models whose tool-call syntax is <tool_call>{"name": …, "arguments": …}</tool_call> (Qwen, Hermes and similar). For other families (Llama 3, Mistral, Gemma…) they answer 400; auto works for every family mlx-swift-lm can parse.
  • A forced call produces one call, unless parallel_tool_calls is true.
  • With parallel_tool_calls: false, calls after the first are dropped.
curl -s http://127.0.0.1:7920/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mlx-community/Qwen3-4B-4bit",
    "messages": [{"role": "user", "content": "What is the weather in Lyon?"}],
    "tools": [{"type": "function", "function": {"name": "get_weather",
      "description": "Current weather for a city",
      "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}],
    "tool_choice": "required",
    "reasoning_effort": "none"
  }'

POST /v1/completions

The legacy text-completion endpoint. The prompt is tokenized as is and continued: no chat template, no thinking, no tool-call parsing.

curl -s http://127.0.0.1:7920/v1/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "mlx-community/Qwen3-4B-4bit", "prompt": "The capital of France is", "max_tokens": 8, "temperature": 0}'
Field Type Default Description
model string required A chat model (model names)
prompt string, or array of one string required The text to continue
max_tokens integer ≥ 1 configuration, else 1024 (OpenAI's default is 16) Most tokens generated
temperature, top_p, stop, seed, presence_penalty, frequency_penalty, top_k, min_p, repetition_penalty, repetition_context_size As for chat completions
echo boolean false Put the prompt before the completion in text
stream, stream_options.include_usage false As for chat completions

Refused with 400: suffix (no fill-in-the-middle), logprobs above 0, n or best_of other than 1, several prompts, token arrays.

Response: {"id": "cmpl-…", "object": "text_completion", "created", "model", "choices": [{"text", "index": 0, "logprobs": null, "finish_reason"}], "usage"}. A stream sends objects of the same shape, each with a piece of text; with echo, the first one holds the prompt.

POST /v1/embeddings

curl -s http://127.0.0.1:7920/v1/embeddings \
  -H "Content-Type: application/json" \
  -d '{"model": "BAAI/bge-small-en-v1.5", "input": ["The cat sits on the mat.", "A feline rests on a rug."]}'
Field Type Default Description
model string required An embedding model (model names)
input string or array of 1–2048 strings required Texts to embed; none may be empty. Token arrays are refused
encoding_format float or base64 float base64: each vector as little-endian float32 bytes, Base64-encoded
dimensions integer ≥ 1 the model's size Keep the first dimensions values and renormalise (for Matryoshka models); larger than the model's size: 400

Response: {"object": "list", "data": [{"object": "embedding", "index": i, "embedding": […]}], "model", "usage": {"prompt_tokens", "total_tokens"}}. Vectors are L2-normalised. A text longer than the model accepts is a 400 naming input[i] and the limit. Inputs are embedded in batches of 32. Pooling follows the model's sentence-transformers configuration.

Streaming

With "stream": true, the answer is text/event-stream:

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}],…}

data: {…"choices":[{"index":0,"delta":{"content":"Hel"},…}]…}

data: {…"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]…}

data: [DONE]

  • Chat chunks: a first chunk with delta.role, then pieces in delta.content, delta.reasoning_content or delta.tool_calls (each call whole, with its index), then an empty delta with finish_reason.
  • With stream_options.include_usage, every chunk has "usage": null and a last chunk with empty choices carries the usage.
  • While the model produces nothing (loading, long prompt), a comment line : keep-alive is sent every 5 seconds; SSE clients ignore it.
  • An error after the stream started is sent as one last event data: {"error": {…}}, without [DONE].
  • When the client disconnects, the generation stops and the model is freed for the next request.
curl -sN http://127.0.0.1:7920/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "mlx-community/Qwen3-4B-4bit", "messages": [{"role": "user", "content": "Count to 5."}],
       "stream": true, "stream_options": {"include_usage": true}, "reasoning_effort": "none"}'

Local admin routes (/rzb)

razorbill's own routes, for rzb tui and the operator of the server. They are not part of OpenAI's API and OpenAI clients never call them.

Rule Value
Access Only connections from the machine running the server (loopback: 127.0.0.0/8, ::1, ::ffff:127.x), even when it listens on 0.0.0.0; any other client gets 403 local_only
Authentication As on /v1: Authorization: Bearer <key> when the server has an API key
Request log Logged like every request, but left out of recent_requests
Method and path Purpose
GET /rzb/status What the server process holds right now
POST /rzb/models/{id}/unload Free a model now ({id} may contain /)
POST /rzb/config/reload Read the configuration file again

GET /rzb/status

curl -s http://127.0.0.1:7920/rzb/status
Field Type Value
version string razorbill's version
uptime_seconds integer Seconds since the server started
host, port string, integer The configured address (port is 0 when the server picked a free port)
config_file string or null The --config file as an absolute path; null without one
models array The models loaded or being loaded, sorted by key (table below); [] when none
recent_requests array The last 50 requests answered, newest first, each recorded once its last byte is sent (table below)
memory object or null The engine's memory (table below); null when the engine cannot measure it (the Linux build)
system object The machine (table below), measured on each request
Field of a model Type Value
key string The loaded model: org/name, or org/name#embedding for an embedding load
name string The name of the request that loaded it (a declared id or a Hugging Face id)
kind string chat or embedding
state string loading until its first request has loaded it, then loaded
size_bytes integer Bytes of weights on disk; 0 when unknown
busy boolean A request holds it (loading it or generating)
queued integer Requests waiting for it
idle_seconds number Seconds since its last request ended (tenths); 0 while busy or queued
keep_alive_left_seconds number or null Seconds before keep_alive unloads it; null while busy or queued
Field of a request Type Value
method, path, status string, string, integer The request and its answer's status
model string or null The model it used
prompt_tokens, completion_tokens integer or null Its token counts, when it generated (streamed answers included)
cached_tokens integer Prompt tokens reused from the previous request
first_byte_ms integer Time to the response head: for a stream, to its first chunk
duration_ms integer Time to the last byte of the answer
finished_at integer Unix seconds
Field of memory Type Value
active_bytes integer Held by live arrays: weights, KV caches, activations
cache_bytes integer Freed by MLX but kept for reuse
peak_bytes integer Highest active_bytes since the process started
limit_bytes integer What MLX may allocate
Field of system Type Value
physical_bytes integer Installed memory
pressure string or null normal, warning or critical, as Activity Monitor's memory pressure; null on Linux
available_bytes integer or null Memory available without swapping: free and speculative pages on macOS, MemAvailable on Linux
compressed_bytes integer or null Memory held compressed (macOS)
swap_used_bytes integer or null Swap in use
process_bytes integer or null The server process's memory footprint
gpu_utilization integer or null GPU use in percent, from the IOAccelerator statistics of IOKit; null when the GPU does not publish it, and on Linux

Example, after one chat request:

{"config_file": "/Users/me/server.yaml", "host": "127.0.0.1", "port": 7920, "uptime_seconds": 34, "version": "0.3.0",
 "memory": {"active_bytes": 364743776, "cache_bytes": 23594047, "limit_bytes": 32641751449, "peak_bytes": 408882564},
 "system": {"available_bytes": 18200000000, "compressed_bytes": 1100000000, "gpu_utilization": 87, "physical_bytes": 34359738368,
            "pressure": "normal", "process_bytes": 4400000000, "swap_used_bytes": 0},
 "models": [{"busy": false, "idle_seconds": 7, "keep_alive_left_seconds": 592.9, "key": "mlx-community/Qwen3-0.6B-4bit",
             "kind": "chat", "name": "qwen", "queued": 0, "size_bytes": 335450584, "state": "loaded"}],
 "recent_requests": [{"cached_tokens": 0, "completion_tokens": 9, "duration_ms": 529, "finished_at": 1795728740, "first_byte_ms": 529,
                      "method": "POST", "model": "qwen", "path": "/v1/chat/completions", "prompt_tokens": 14, "status": 200}]}

POST /rzb/models/{id}/unload

curl -s -X POST http://127.0.0.1:7920/rzb/models/mlx-community/Qwen3-4B-4bit/unload

{id} is a model name. A declared id frees the load of its own kind; a Hugging Face id frees both its chat and its embedding loads. The next request for the model loads it again.

Case Status Body
The model was loaded and idle 200 {"model": "<id>", "status": "unloaded", "unloaded": ["<key>", …]}
The model was not loaded 200 {"model": "<id>", "status": "not_loaded", "unloaded": []}
A request holds the model or waits for it 409 Error model_busy; nothing is unloaded
Not a model name 404 Error model_not_found
The path does not end with /unload 404 Error unknown_url

POST /rzb/config/reload

curl -s -X POST http://127.0.0.1:7920/rzb/config/reload

Reads the --config file again and applies it; what changes at once and what needs a restart is listed in the configuration reference. Sending SIGHUP to the server does the same, with the outcome written to its log.

Field of the answer Type Value
file string The file read
declared_models integer Models it declares
unloaded array of strings Loaded models no declared id points to anymore, unloaded now
unload_when_idle array of strings Such models still in use, unloaded when their last request ends
restart_required array of strings server keys changed in the file that only apply after a restart: host, port, api_key_env, cors_origin. A key set by a command-line option is never listed
Case Status Body
The file is valid 200 The fields above
The file is invalid or unreadable 400 Error invalid_config listing the problems; the configuration in force stays
The server was started without --config 409 Error no_config_file
  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
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# Reference: HTTP API

> The endpoints of `rzb serve`, the fields each one accepts, refuses or ignores, and what it answers. Error bodies and status codes are in the [errors reference](errors.md); the server's options in the [command-line reference](cli.md) and the [configuration reference](configuration.md).

The examples use `mlx-community/Qwen3-4B-4bit` as chat model and `BAAI/bge-small-en-v1.5` as embedding model, both pulled beforehand with `rzb models pull`. The compatibility suite runs every `curl` example of this page against a real server (`scripts/compat.sh`).

## General rules

| Rule | Value |
| --- | --- |
| Base URL | `http://<host>:<port>/v1`, by default `http://127.0.0.1:7920/v1` |
| Request body | JSON (`Content-Type: application/json`), at most 16 MiB (larger: 413) |
| Response body | JSON, compact, keys sorted; streams are Server-Sent Events |
| Authentication | `Authorization: Bearer <key>` on every route except `/health`, when the server has an API key ([`--api-key-env`](cli.md#rzb-serve)); none otherwise |
| CORS | Off, unless `--cors-origin` / `server.cors_origin` is set |
| Unknown fields | Ignored, as OpenAI does, unless listed as refused below |
| Connections | Generation endpoints answer with `Connection: close` (the server watches the connection to stop a generation whose client has left) |
| Concurrency | One generation at a time per model; other requests for that model wait in a queue ([`limits`](configuration.md#limits)) |

## Endpoints

| Method and path | Purpose |
| --- | --- |
| `GET /health` | Liveness check, no authentication |
| `GET /v1/models` | Models the server can serve |
| `GET /v1/models/{id}` | One of them (`{id}` may contain `/`) |
| `POST /v1/chat/completions` | Chat answer, plain or streamed, with structured output, tools and reasoning |
| `POST /v1/completions` | Legacy text completion: the prompt is continued as raw text |
| `POST /v1/embeddings` | Embedding vectors |
| `GET /rzb/status`, `POST /rzb/…` | razorbill's own admin routes, from this machine only: see [local admin routes](#local-admin-routes-rzb) |

Any other path answers 404 with code `unknown_url`.

## GET /health

```bash
curl -s http://127.0.0.1:7920/health
```

Answer: `{"status":"ok"}`, status 200, whenever the process is up.

## GET /v1/models

```bash
curl -s http://127.0.0.1:7920/v1/models
```

Answer: `{"object": "list", "data": [<model>, …]}`. The list holds, in this order: the models declared in the configuration (under their `id`), then the loadable models of the Hugging Face cache, then models loaded by their Hugging Face id that are neither.

| Field of `<model>` | Type | Value |
| --- | --- | --- |
| `id` | string | The name to put in `"model"` |
| `object` | string | `"model"` |
| `created` | integer | The server's start time (Unix seconds) |
| `owned_by` | string | `"razorbill"` |
| `loaded` | boolean | razorbill extension: in memory now |
| `kind` | string | razorbill extension: `chat` or `embedding`. A cached model that is not declared is reported as `chat` (the cache does not record the kind) |

`GET /v1/models/{id}` answers one `<model>`, or 404 `model_not_found`.

## Model names

The `"model"` of a request is, in this order of lookup:

1. the `id` of a model declared in the configuration; its `kind` must match the endpoint (chat for completions, embedding for embeddings), otherwise 400;
2. a Hugging Face repository id, `org/name` or `org/name@revision`, of a model in MLX format. It is downloaded on its first use if it is not in the cache, and taken to be of the endpoint's kind. A repository the cache shows without `.safetensors` weights (GGUF, for instance) is refused with 400 `model_not_supported`.

Anything else is a 404 `model_not_found`.

## POST /v1/chat/completions

```bash
curl -s http://127.0.0.1:7920/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mlx-community/Qwen3-4B-4bit",
    "messages": [
      {"role": "system", "content": "Answer in one sentence."},
      {"role": "user", "content": "What is MLX?"}
    ],
    "temperature": 0.2,
    "max_tokens": 200
  }'
```

### Request fields

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `model` | string | required | See [model names](#model-names) |
| `messages` | array | required, not empty | See [messages](#messages) |
| `temperature` | number, 0–2 | configuration, else `0.6` | Sampling temperature |
| `top_p` | number, >0–1 | configuration, else `1.0` | Nucleus sampling |
| `max_tokens` | integer ≥ 1 | configuration, else `1024` | Most tokens generated, reasoning included |
| `max_completion_tokens` | integer ≥ 1 | — | Same as `max_tokens`; wins when both are sent |
| `stop` | string or array of ≤ 4 strings | none | The answer ends before the first occurrence; `finish_reason` is then `stop` |
| `seed` | integer | random | Sampler seed: same seed and settings, same answer |
| `presence_penalty` | number, −2–2 | none | Penalises tokens present among the last 20 tokens (prompt included) |
| `frequency_penalty` | number, −2–2 | none | Penalises tokens by their frequency among the last 20 tokens (prompt included) |
| `top_k` | integer ≥ 0 | configuration, else `0` (off) | Extension (vLLM, llama-server, Ollama, mlx-lm): sample among the `top_k` most likely tokens only |
| `min_p` | number, 0–1 | configuration, else `0` (off) | Extension: drop tokens less likely than `min_p` × the most likely one |
| `repetition_penalty` | number > 0 | configuration, else none | Extension: divides the score of tokens seen in the last `repetition_context_size` tokens (prompt included); above 1 discourages repeats |
| `repetition_context_size` | integer ≥ 1 | configuration, else `20` | Extension (mlx-lm's name): how many recent tokens `repetition_penalty` looks at |
| `stream` | boolean | `false` | Stream the answer as Server-Sent Events ([streaming](#streaming)) |
| `stream_options.include_usage` | boolean | `false` | Add a last chunk with `usage` |
| `response_format` | object | `{"type": "text"}` | `text`, `json_object` or `json_schema`; see [structured output](#structured-output) |
| `tools` | array | none | Functions the model may call; see [tools](#tools) |
| `tool_choice` | string or object | `auto` with tools, `none` without | `none`, `auto`, `required`, or `{"type": "function", "function": {"name": "…"}}` |
| `parallel_tool_calls` | boolean | `true`; `false` for a forced call | `false`: at most one call |
| `reasoning_effort` | string | configuration | `none` and `minimal` turn thinking off; `low`, `medium`, `high` turn it on (all three alike) |
| `chat_template_kwargs.enable_thinking` | boolean | — | vLLM's switch; wins over `reasoning_effort` |
| `thinking_budget` | integer ≥ 0 | configuration | razorbill extension: most tokens of reasoning before the model must answer |
| `include_reasoning` | boolean | configuration, else `true` | OpenRouter's switch: `false` leaves out `reasoning_content` (the model still thinks) |

The configuration's `locked` values win over the request: `temperature`, `top_p`, `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size`, `thinking` and `show_reasoning` are imposed, `max_tokens` and `thinking_budget` are ceilings ([configuration reference](configuration.md#defaults-and-locked)).

### Refused fields

These fields answer 400 naming the field, rather than being silently ignored:

| Field | Refused when |
| --- | --- |
| `n` | other than 1 |
| `logprobs` | `true` |
| a message with role other than `system`, `developer`, `user`, `assistant`, `tool` | always |
| a content part of type other than `text` (images, audio…) | always |
| `response_format` combined with a forced tool call | `tool_choice` is `required` or names a function, or a tool is `strict` |

### Messages

| Role | Fields | Notes |
| --- | --- | --- |
| `system`, `developer` | `content` | `developer` is treated as `system` |
| `user` | `content` | |
| `assistant` | `content` (may be null), `tool_calls` | Previous answers, with the calls the model made |
| `tool` | `content`, `tool_call_id`, `name` | The result of a call |

`content` is a string or an array of `{"type": "text", "text": "…"}` parts, joined with a line break. In `tool_calls`, `function.arguments` must be a JSON object encoded as a string, as OpenAI sends it.

The conversation is rendered with the model's own chat template. The server keeps no state between requests.

### Response

```json
{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "created": 1764096042,
  "model": "mlx-community/Qwen3-4B-4bit",
  "choices": [{
    "index": 0,
    "message": {"role": "assistant", "content": "…", "reasoning_content": "…", "tool_calls": […]},
    "logprobs": null,
    "finish_reason": "stop"
  }],
  "usage": {"prompt_tokens": 20, "completion_tokens": 9, "total_tokens": 29,
            "completion_tokens_details": {"reasoning_tokens": 120}}
}
```

| Field | Present | Value |
| --- | --- | --- |
| `id` | always | `chatcmpl-` and 24 hexadecimal digits |
| `model` | always | The `"model"` of the request, as sent |
| `message.content` | always | The answer; `null` when the model only called tools |
| `message.reasoning_content` | when the model thought and reasoning is shown | The reasoning, without the `<think>` tags |
| `message.tool_calls` | when the model called tools | `[{"id", "type": "function", "function": {"name", "arguments"}}]`, `arguments` a JSON string |
| `finish_reason` | always | `stop`, `length` (token limit) or `tool_calls` |
| `usage.prompt_tokens_details.cached_tokens` | when part of the prompt was reused | Prompt tokens taken from the KV cache of the previous request instead of being read again; included in `prompt_tokens` ([why](../explanation/model-lifecycle.md#reusing-the-previous-prompt)) |
| `usage.completion_tokens_details.reasoning_tokens` | when the model thought | Pieces of reasoning received (about one per token), also counted when reasoning is hidden |

When a stop sequence ends the answer, the engine is interrupted before it reports its counts: `usage` then counts one token per piece of text and `prompt_tokens` is 0.

### Structured output

| `response_format` | Effect |
| --- | --- |
| `{"type": "text"}` | No constraint |
| `{"type": "json_object"}` | The answer is one JSON object |
| `{"type": "json_schema", "json_schema": {"name": "…", "schema": {…}, "strict": true}}` | The answer is one JSON value valid against `schema` |

- The constraint is enforced while tokens are generated (constrained decoding, on macOS with MLX); a reasoning model thinks freely first, and the constraint applies after its reasoning.
- The server adds one instruction to the system message (a system message is created if there is none): `Answer with a single JSON object.` for `json_object`; `Answer with a single JSON object that follows this JSON Schema:` followed by the schema for `json_schema`.
- Object properties are generated in the order the schema lists them.
- With `"strict": true`, a schema that uses a keyword the decoder cannot enforce is refused with 400 naming it and where it is: `not`, `if`, `then`, `else`, `dependentRequired`, `dependentSchemas`, `multipleOf`, `uniqueItems`, `contains`, `minContains`, `maxContains`. Without `strict`, such keywords are ignored.

```bash
curl -s http://127.0.0.1:7920/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mlx-community/Qwen3-4B-4bit",
    "messages": [{"role": "user", "content": "Describe Lyon."}],
    "response_format": {"type": "json_schema", "json_schema": {"name": "city", "strict": true,
      "schema": {"type": "object", "additionalProperties": false, "required": ["name", "country"],
        "properties": {"name": {"type": "string"}, "country": {"type": "string"}}}}},
    "reasoning_effort": "none"
  }'
```

### Tools

| `tools[i]` field | Type | Rules |
| --- | --- | --- |
| `type` | string | `"function"` |
| `function.name` | string | 1–64 letters, digits, `_` or `-`; unique |
| `function.description` | string | Optional |
| `function.parameters` | object | A JSON Schema object; default `{"type": "object", "properties": {}}` |
| `function.strict` | boolean | `true`: the arguments are generated under the schema (same keyword limits as `strict` structured output) |

| `tool_choice` | Effect |
| --- | --- |
| `none` | Tools are not offered to the model; it answers in text |
| `auto` | The model decides; its calls are parsed from its output |
| `required` | The answer is tool calls only, generated under a grammar |
| `{"type": "function", "function": {"name": "f"}}` | The answer is one call to `f`, generated under a grammar |

- Forced calls (`required`, a named function, or a `strict` tool) are only possible for models whose tool-call syntax is `<tool_call>{"name": …, "arguments": …}</tool_call>` (Qwen, Hermes and similar). For other families (Llama 3, Mistral, Gemma…) they answer 400; `auto` works for every family mlx-swift-lm can parse.
- A forced call produces one call, unless `parallel_tool_calls` is `true`.
- With `parallel_tool_calls: false`, calls after the first are dropped.

```bash
curl -s http://127.0.0.1:7920/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mlx-community/Qwen3-4B-4bit",
    "messages": [{"role": "user", "content": "What is the weather in Lyon?"}],
    "tools": [{"type": "function", "function": {"name": "get_weather",
      "description": "Current weather for a city",
      "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}],
    "tool_choice": "required",
    "reasoning_effort": "none"
  }'
```

## POST /v1/completions

The legacy text-completion endpoint. The prompt is tokenized as is and continued: no chat template, no thinking, no tool-call parsing.

```bash
curl -s http://127.0.0.1:7920/v1/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "mlx-community/Qwen3-4B-4bit", "prompt": "The capital of France is", "max_tokens": 8, "temperature": 0}'
```

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `model` | string | required | A chat model ([model names](#model-names)) |
| `prompt` | string, or array of one string | required | The text to continue |
| `max_tokens` | integer ≥ 1 | configuration, else `1024` (OpenAI's default is 16) | Most tokens generated |
| `temperature`, `top_p`, `stop`, `seed`, `presence_penalty`, `frequency_penalty`, `top_k`, `min_p`, `repetition_penalty`, `repetition_context_size` | | | As for chat completions |
| `echo` | boolean | `false` | Put the prompt before the completion in `text` |
| `stream`, `stream_options.include_usage` | | `false` | As for chat completions |

Refused with 400: `suffix` (no fill-in-the-middle), `logprobs` above 0, `n` or `best_of` other than 1, several prompts, token arrays.

Response: `{"id": "cmpl-…", "object": "text_completion", "created", "model", "choices": [{"text", "index": 0, "logprobs": null, "finish_reason"}], "usage"}`. A stream sends objects of the same shape, each with a piece of `text`; with `echo`, the first one holds the prompt.

## POST /v1/embeddings

```bash
curl -s http://127.0.0.1:7920/v1/embeddings \
  -H "Content-Type: application/json" \
  -d '{"model": "BAAI/bge-small-en-v1.5", "input": ["The cat sits on the mat.", "A feline rests on a rug."]}'
```

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `model` | string | required | An embedding model ([model names](#model-names)) |
| `input` | string or array of 1–2048 strings | required | Texts to embed; none may be empty. Token arrays are refused |
| `encoding_format` | `float` or `base64` | `float` | `base64`: each vector as little-endian float32 bytes, Base64-encoded |
| `dimensions` | integer ≥ 1 | the model's size | Keep the first `dimensions` values and renormalise (for Matryoshka models); larger than the model's size: 400 |

Response: `{"object": "list", "data": [{"object": "embedding", "index": i, "embedding": […]}], "model", "usage": {"prompt_tokens", "total_tokens"}}`. Vectors are L2-normalised. A text longer than the model accepts is a 400 naming `input[i]` and the limit. Inputs are embedded in batches of 32. Pooling follows the model's sentence-transformers configuration.

## Streaming

With `"stream": true`, the answer is `text/event-stream`:

```
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}],…}

data: {…"choices":[{"index":0,"delta":{"content":"Hel"},…}]…}

data: {…"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]…}

data: [DONE]

```

- Chat chunks: a first chunk with `delta.role`, then pieces in `delta.content`, `delta.reasoning_content` or `delta.tool_calls` (each call whole, with its `index`), then an empty delta with `finish_reason`.
- With `stream_options.include_usage`, every chunk has `"usage": null` and a last chunk with empty `choices` carries the `usage`.
- While the model produces nothing (loading, long prompt), a comment line `: keep-alive` is sent every 5 seconds; SSE clients ignore it.
- An error after the stream started is sent as one last event `data: {"error": {…}}`, without `[DONE]`.
- When the client disconnects, the generation stops and the model is freed for the next request.

```bash
curl -sN http://127.0.0.1:7920/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "mlx-community/Qwen3-4B-4bit", "messages": [{"role": "user", "content": "Count to 5."}],
       "stream": true, "stream_options": {"include_usage": true}, "reasoning_effort": "none"}'
```

## Local admin routes (/rzb)

razorbill's own routes, for `rzb tui` and the operator of the server. They are not part of OpenAI's API and OpenAI clients never call them.

| Rule | Value |
| --- | --- |
| Access | Only connections from the machine running the server (loopback: `127.0.0.0/8`, `::1`, `::ffff:127.x`), even when it listens on `0.0.0.0`; any other client gets 403 `local_only` |
| Authentication | As on `/v1`: `Authorization: Bearer <key>` when the server has an API key |
| Request log | Logged like every request, but left out of `recent_requests` |

| Method and path | Purpose |
| --- | --- |
| `GET /rzb/status` | What the server process holds right now |
| `POST /rzb/models/{id}/unload` | Free a model now (`{id}` may contain `/`) |
| `POST /rzb/config/reload` | Read the configuration file again |

### GET /rzb/status

```bash
curl -s http://127.0.0.1:7920/rzb/status
```

| Field | Type | Value |
| --- | --- | --- |
| `version` | string | razorbill's version |
| `uptime_seconds` | integer | Seconds since the server started |
| `host`, `port` | string, integer | The configured address (`port` is `0` when the server picked a free port) |
| `config_file` | string or `null` | The `--config` file as an absolute path; `null` without one |
| `models` | array | The models loaded or being loaded, sorted by `key` (table below); `[]` when none |
| `recent_requests` | array | The last 50 requests answered, newest first, each recorded once its last byte is sent (table below) |
| `memory` | object or `null` | The engine's memory (table below); `null` when the engine cannot measure it (the Linux build) |
| `system` | object | The machine (table below), measured on each request |

| Field of a model | Type | Value |
| --- | --- | --- |
| `key` | string | The loaded model: `org/name`, or `org/name#embedding` for an embedding load |
| `name` | string | The name of the request that loaded it (a declared `id` or a Hugging Face id) |
| `kind` | string | `chat` or `embedding` |
| `state` | string | `loading` until its first request has loaded it, then `loaded` |
| `size_bytes` | integer | Bytes of weights on disk; `0` when unknown |
| `busy` | boolean | A request holds it (loading it or generating) |
| `queued` | integer | Requests waiting for it |
| `idle_seconds` | number | Seconds since its last request ended (tenths); `0` while `busy` or `queued` |
| `keep_alive_left_seconds` | number or `null` | Seconds before [`keep_alive`](configuration.md#limits) unloads it; `null` while `busy` or `queued` |

| Field of a request | Type | Value |
| --- | --- | --- |
| `method`, `path`, `status` | string, string, integer | The request and its answer's status |
| `model` | string or `null` | The model it used |
| `prompt_tokens`, `completion_tokens` | integer or `null` | Its token counts, when it generated (streamed answers included) |
| `cached_tokens` | integer | Prompt tokens reused from the previous request |
| `first_byte_ms` | integer | Time to the response head: for a stream, to its first chunk |
| `duration_ms` | integer | Time to the last byte of the answer |
| `finished_at` | integer | Unix seconds |

| Field of `memory` | Type | Value |
| --- | --- | --- |
| `active_bytes` | integer | Held by live arrays: weights, KV caches, activations |
| `cache_bytes` | integer | Freed by MLX but kept for reuse |
| `peak_bytes` | integer | Highest `active_bytes` since the process started |
| `limit_bytes` | integer | What MLX may allocate |

| Field of `system` | Type | Value |
| --- | --- | --- |
| `physical_bytes` | integer | Installed memory |
| `pressure` | string or `null` | `normal`, `warning` or `critical`, as Activity Monitor's memory pressure; `null` on Linux |
| `available_bytes` | integer or `null` | Memory available without swapping: free and speculative pages on macOS, `MemAvailable` on Linux |
| `compressed_bytes` | integer or `null` | Memory held compressed (macOS) |
| `swap_used_bytes` | integer or `null` | Swap in use |
| `process_bytes` | integer or `null` | The server process's memory footprint |
| `gpu_utilization` | integer or `null` | GPU use in percent, from the `IOAccelerator` statistics of IOKit; `null` when the GPU does not publish it, and on Linux |

Example, after one chat request:

```json
{"config_file": "/Users/me/server.yaml", "host": "127.0.0.1", "port": 7920, "uptime_seconds": 34, "version": "0.3.0",
 "memory": {"active_bytes": 364743776, "cache_bytes": 23594047, "limit_bytes": 32641751449, "peak_bytes": 408882564},
 "system": {"available_bytes": 18200000000, "compressed_bytes": 1100000000, "gpu_utilization": 87, "physical_bytes": 34359738368,
            "pressure": "normal", "process_bytes": 4400000000, "swap_used_bytes": 0},
 "models": [{"busy": false, "idle_seconds": 7, "keep_alive_left_seconds": 592.9, "key": "mlx-community/Qwen3-0.6B-4bit",
             "kind": "chat", "name": "qwen", "queued": 0, "size_bytes": 335450584, "state": "loaded"}],
 "recent_requests": [{"cached_tokens": 0, "completion_tokens": 9, "duration_ms": 529, "finished_at": 1795728740, "first_byte_ms": 529,
                      "method": "POST", "model": "qwen", "path": "/v1/chat/completions", "prompt_tokens": 14, "status": 200}]}
```

### POST /rzb/models/{id}/unload

```bash
curl -s -X POST http://127.0.0.1:7920/rzb/models/mlx-community/Qwen3-4B-4bit/unload
```

`{id}` is a [model name](#model-names). A declared `id` frees the load of its own kind; a Hugging Face id frees both its chat and its embedding loads. The next request for the model loads it again.

| Case | Status | Body |
| --- | --- | --- |
| The model was loaded and idle | 200 | `{"model": "<id>", "status": "unloaded", "unloaded": ["<key>", …]}` |
| The model was not loaded | 200 | `{"model": "<id>", "status": "not_loaded", "unloaded": []}` |
| A request holds the model or waits for it | 409 | Error `model_busy`; nothing is unloaded |
| Not a model name | 404 | Error `model_not_found` |
| The path does not end with `/unload` | 404 | Error `unknown_url` |

### POST /rzb/config/reload

```bash
curl -s -X POST http://127.0.0.1:7920/rzb/config/reload
```

Reads the `--config` file again and applies it; what changes at once and what needs a restart is listed in the [configuration reference](configuration.md#reloading). Sending `SIGHUP` to the server does the same, with the outcome written to its log.

| Field of the answer | Type | Value |
| --- | --- | --- |
| `file` | string | The file read |
| `declared_models` | integer | Models it declares |
| `unloaded` | array of strings | Loaded models no declared `id` points to anymore, unloaded now |
| `unload_when_idle` | array of strings | Such models still in use, unloaded when their last request ends |
| `restart_required` | array of strings | `server` keys changed in the file that only apply after a restart: `host`, `port`, `api_key_env`, `cors_origin`. A key set by a command-line option is never listed |

| Case | Status | Body |
| --- | --- | --- |
| The file is valid | 200 | The fields above |
| The file is invalid or unreadable | 400 | Error `invalid_config` listing the problems; the configuration in force stays |
| The server was started without `--config` | 409 | Error `no_config_file` |