Local MLX API Reference for Mac Developers
Run rapid-mlx serve qwen3.5-4b-4bit, then point your client at http://localhost:8000/v1. The served alias is the model name; see the routes below.
$ rapid-mlx serve qwen3.5-4b-4bit
from openai import OpenAI client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-used") stream = client.chat.completions.create( model="qwen3.5-4b-4bit", messages=[{"role": "user", "content": "Hello"}], stream=True, ) for chunk in stream: print(chunk.choices[0].delta.content or "", end="")
The three things most clients need:
- Chat:
POST /v1/chat/completions— tools, vision, streaming andreasoning_content. - Agents:
POST /v1/responses(Codex CLI) andPOST /v1/messages(Anthropic Messages, used by Claude Code). - Discovery:
GET /v1/modelslists what the server serves, with its parsers and context window.
GET /openapi.json and an
interactive Swagger UI at GET /docs. The list below
is the human-readable summary; the JSON schema is the source of truth.
Endpoints
| Endpoint | What it does |
|---|---|
| POST /v1/chat/completions | Chat completions — tools, vision, streaming and reasoning_content. |
| POST /v1/responses | OpenAI Responses API — streaming with item-by-item events, reasoning items, tool calls. |
| POST /v1/messages | Anthropic Messages API — tools, streaming and thinking blocks. |
| POST /v1/messages/count_tokens | Anthropic token count for a Messages request. |
| POST /v1/completions | Text completion without a chat template. |
| GET /v1/models | The served models with their parsers, modality, capabilities and context window. |
| POST /v1/rerank | Score documents against a query in relevance order — start with --rerank-model <hf-id>. Requests default to at most 1000 documents. |
| POST /v1/cache/prefill | Warm a fixed system-and-tools prefix or a revisioned conversation draft without returning generated text. Requires a ready chat model; disk caching needs explicit allow_disk_cache consent. |
| POST /v1/embeddings | Embeddings — set --embedding-model with a chat model or by itself for an embedding-only server (e.g. embeddinggemma-2-4bit, which uses the bundled vision runtime). |
| POST /v1/audio/speech | Text-to-speech (Kokoro, Qwen3-TTS, IndexTTS, Chatterbox, VibeVoice, VoxCPM, F5-TTS, Dia) — needs the [audio] extra. Cloning models take a ref_audio field; Qwen3-TTS Base and F5-TTS also need ref_text. |
| POST /v1/audio/transcriptions | Speech-to-text (Whisper, Parakeet, SenseVoice, Qwen3-ASR) with word-level timestamps — needs the [audio] extra. A text field switches to forced alignment against that transcript. |
| POST /v1/audio/translations | Speech-to-English translation — needs the [audio] extra. |
| POST /v1/audio/music | Text-to-music and sound effects — needs the [audio] extra. |
| POST /v1/images/generations | Text-to-image (FLUX, Qwen-Image, Z-Image and more) — uses the bundled image runtime and Python 3.12+. Returns b64_json. |
| POST /v1/images/edits | Image editing on models that support it (e.g. qwen-image-edit). |
| POST /v1/videos | Create a video job (LTX-2.5 / 2.3, Wan, CogVideoX-Fun) — uses the bundled video runtime, ffmpeg and Python 3.12+. Returns a job id. |
| GET /v1/videos/{id} | Poll a video job's status. |
| GET /v1/videos/{id}/content | Download the finished MP4. |
| POST /v1/videos/extend | Extend an LTX-2.5 MP4 (multipart upload): returns one MP4 with the original and the appended frames, through the same job and download endpoints. Source: 24 fps, 256–1920 px in multiples of 32, an 8n+1 frame count of at least 9, up to 20 MiB; extend_frames 8–48 in steps of 8. The result may hold at most 97 frames and 24 million pixel-frames. Allow the upload with --max-request-bytes 23068672. |
| GET /v1/videos/capabilities | What the loaded video model accepts — modes, native fps, size and frame-count rules, and the extension limits. |
| POST /v1/requests/{id}/cancel | Cancel an in-flight request. |
| GET /v1/status | Running and waiting requests, cache and Metal memory. |
| GET /health | Health probe (also /healthz, /readyz, /livez, /health/ready). |
| GET /metrics | Prometheus counters and histograms. |
| GET /openapi.json | OpenAPI 3 schema for every route. |
| GET /docs | Swagger UI. |
MCP tool routes (/v1/mcp/*) appear when the server starts
with --mcp-config; model management, cache and agent-run
routes are listed in /openapi.json.
New in 1.0.3: Anthropic tool choice
On the Anthropic-compatible POST /v1/messages endpoint,
forced and required tool_choice requests now generate
tool arguments instead of attempting an empty call. Automatic tool
choice also works when parallel calls are disabled.
New in 1.0.4 and 1.0.5
Embedding discovery
Embedding cards on GET /v1/models and GET /v1/models/{id} advertise known embedding_dimensions, supported_dimensions (an object with min and max), max_input_tokens, pooling and normalized. Unknown facts are omitted. Supported dimensions describe API support, not retrieval quality at every size; discovery does not load weights or run inference to guess them.
Retain recent prefixes
POST /v1/cache/clear accepts {"keep_recent": 2} to retain recent text-prefix entries while releasing older ones and protecting active or pinned state. The value must be a nonnegative integer. Responses and cache statistics report released and retained state. A request without a body keeps the existing full-clear behavior; model weights stay loaded. Partial release can return HTTP 409 when unavailable.
curl -sS http://localhost:8000/v1/cache/clear \
-H 'Content-Type: application/json' -d '{"keep_recent":2}'
Add your configured bearer key when calling authenticated administrative routes.
Required tool-call recovery
Non-streaming chat completions get one guided decoding recovery attempt for required multi-tool responses with no calls and schema-invalid required or pinned calls. Successful retries combine usage; unavailable or unsuccessful recovery preserves the original error. Strict /v1/responses output reuses the tool parse. Parallel streamed calls remain separate even when they call the same tool. Quote values containing literal closing tags: an unquoted argument ending in a closer can still lose that tag.
Image models, edits and LoRAs
FLUX 3 Klein and Klein Base support up to ten edit references; MiniMax-H3-Image supports up to 16, subject to its community license restrictions. Qwen-Image enforces checkpoint-specific reference limits with HTTP 400 errors. Put local image LoRAs in ~/.rapid-mlx/loras and select by name; GET /v1/images/loras lists them. LoRA support depends on the image runtime; MiniMax-H3-Image does not support LoRAs. See model names, memory floors and license restrictions.
Scoring and input errors
/v1/completions returns prompt-token logprobs when echo is combined with logprobs. Qwen3-Reranker (mlx-community/Qwen3-Reranker-0.6B-4bit) uses its trained prompt format. Lone UTF-16 surrogates in embedding or rerank input now return HTTP 400 instead of 500.
Continue a partial assistant message
New in 1.1.0: POST /v1/chat/completions accepts continue_final_message: true. Also set add_generation_prompt: false and end messages with an assistant message. The model continues that message instead of starting a new assistant turn. The final message must not contain nonempty tool_calls or a legacy function_call; invalid combinations fail request validation.
curl http://localhost:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"qwen3.5-4b-4bit","messages":[{"role":"user","content":"Name two colors."},{"role":"assistant","content":"The colors are"}],"continue_final_message":true,"add_generation_prompt":false,"max_tokens":64}'
Background request priority
For batched text and vision-language inference, send X-Rapid-Priority: background on batch work. Waiting interactive requests are admitted first. A background request waiting more than 30 seconds is treated as interactive to prevent starvation. Running requests are never preempted. Omitting the header, or sending another value, uses interactive priority.
curl http://localhost:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-H 'X-Rapid-Priority: background' \
-d '{"model":"qwen3.5-4b-4bit","messages":[{"role":"user","content":"Summarize this batch."}],"max_tokens":64}'
Supervised serve: status, log and jobs
These 1.1.0 endpoints are mounted in a supervised runner. They require a loopback peer and bearer authentication when a key is configured. They are separate from the primary-engine GET /v1/status endpoint.
| Endpoint | Response / behavior |
|---|---|
| GET /rapid/v1/status | control_version, supervisor_pid, port, mode and runner containing pid, started_at, restarts and state. Returns 503 if the control plane is unavailable. |
| GET /rapid/v1/log | calls array. Optional limit query parameter: 1–1,000, default 50. Each record contains ts, method, path, status, duration_ms and client. |
| GET /rapid/v1/jobs | jobs array of agent runs: id, kind, status, created, updated and a bounded summary. |
| POST /rapid/v1/jobs/{job_id}/cancel | Cancel the agent run identified by its returned id. |
The last 1,000 API calls stay in runner memory, without request bodies, query strings or other headers. The client label uses X-Rapid-Client or a shortened User-Agent. Restarting the runner clears this log. CLI equivalents and log coverage.
What's the same as OpenAI
- Request and response shapes for
/chat/completions,/completions,/embeddings,/responses. - SSE streaming via
stream: truewith adata: [DONE]terminator. - Function / tool calling via
toolsandtool_choice, returned as an OpenAItool_callsarray. - Vision inputs as
image_urlcontent parts on multimodal models (Gemma 4, Qwen3-VL and others). - Authorization: without
--api-key(orRAPID_MLX_API_KEY) the header is accepted but not checked; with it, a missing or wrong key returns401.
Where it differs
-
Reasoning is off unless you ask for it on chat completions.
For thinking models, a
/v1/chat/completionsrequest that sets no thinking preference — plain chat, or a request withtools— gets a direct answer. Ask for reasoning withchat_template_kwargs: {"enable_thinking": true},reasoning_effortorreasoning_max_tokens. -
reasoning_contentis a sibling ofcontent(the DeepSeek-R1 field name), not OpenAI'sreasoningblocks. -
reasoning_max_tokenscaps the thinking part of a response; the model then answers. It does not bound the answer — pair it withmax_tokensfor total length. -
When
max_tokenstruncates a tool call, Chat Completions reportsfinish_reason: "length", Responses reportsincomplete, and Messages reportsstop_reason: "max_tokens". Do not execute partial tool arguments. -
Each alias uses its own tool-call format internally (Hermes, Qwen3
XML, GLM, Harmony, Gemma 4, UI-TARS, Llama, DeepSeek, MiniMax…); the
client always receives OpenAI's
tool_callsarray. -
/v1/modelsadds Rapid-MLX fields —tool_call_parser,reasoning_parser,is_hybrid,is_moe,modality,capabilities,context_window,recommended_sampling— that OpenAI-only clients ignore. -
A finished response can carry a Rapid-MLX
metricsobject:speculative_decodingwhen the request ran MTP, andprompt_compression(original_tokens,kept_tokens) when an opted-in PFlash shortened the prompt. Chat Completions, single-prompt Completions and Responses also report experimental request timing:time_to_first_token_ms(scheduler arrival to first output token, so queueing and prefill are included) and, from two tokens on,mean_itl_ms(mean interval between output tokens;1000 / mean_itl_msis that request's decode tokens/second). Streaming sends them once on the final event, whether or notstream_options.include_usageis set. Failed, cancelled and response-cache replays omit them, and/v1/messagesdoes not carry them. Themetricsobject is omitted when none of these apply. Non-streaming responses on every text API, including/v1/messages, also announce compression with theX-Rapid-MLX-Prompt-Compressed: <kept>/<original>header. -
When the server can't take a request it returns
503withRetry-After. The message says why:Server is busy (max concurrent requests reached)above--max-concurrent-requests, orServer is at its Metal memory limitwith how much memory the request needs (see Troubleshooting). -
Streaming SSE for
/v1/responsesemitsresponse.output_item.added,response.output_item.done, reasoning items and tool-call items in OpenAI's order; a diffusion model emits a block of tokens per delta instead of one.
Examples
List models
$ curl -s http://localhost:8000/v1/models | jq '.data[] | select(.id=="qwen3.5-4b-4bit")' { "id": "qwen3.5-4b-4bit", "object": "model", "owned_by": "rapid-mlx", "is_hybrid": false, "is_moe": false, "tool_call_parser": "hermes", "reasoning_parser": "qwen3", "modality": "text", "context_window": 262144, "capabilities": ["text", "tools"], … }
The list also carries the underlying Hugging Face repo id as its own
entry, so either name works as model.
Chat completion with cURL
$ curl http://localhost:8000/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{"model": "qwen3.5-4b-4bit", "messages": [{"role": "user", "content": "What is 17*23?"}], "chat_template_kwargs": {"enable_thinking": true}}'
With thinking on, the reply carries both reasoning_content
and the final content.
Embeddings
# first install: pip install rapid-mlx==1.1.1 $ rapid-mlx serve qwen3.5-4b-4bit \ --embedding-model embeddinggemma-2-4bit --port 8000 & $ curl http://localhost:8000/v1/embeddings \ -H "Content-Type: application/json" \ -d '{"model": "embeddinggemma-2-4bit", "input": "ping"}'
An embedding model is attached to a chat server — on its own,
rapid-mlx serve embeddinggemma-2-4bit exits with a hint to
use --embedding-model. Setup, task prefixes,
dimensions and a worked search example are on the
EmbeddingGemma 2 page.
Long inputs. The input limit comes from the model
(config.max_position_embeddings, else
tokenizer.model_max_length), so a 32K-context embedder uses
its full window. Inputs above the limit are never cut silently: by
default the tail is truncated with a logged warning and a
rapid_mlx_embedding_truncations_total increment on
/metrics; with --embedding-overflow-policy error
the request is rejected with a 400:
$ rapid-mlx serve qwen3.5-4b-4bit --port 8000 \ --embedding-model embeddinggemma-2-4bit \ --embedding-max-length 2048 --embedding-overflow-policy error # a 3,000-token input then returns: {"error": {"code": "input_too_long", "message": "…observed vs allowed tokens…"}}
Audio (TTS)
The speed field on /v1/audio/speech controls playback duration for supported voices, including Qwen3-TTS, Chatterbox and IndexTTS, while preserving pitch.
# first install: pip install 'rapid-mlx[audio]' $ rapid-mlx serve kokoro --port 8002 & $ curl http://localhost:8002/v1/audio/speech \ -H "Content-Type: application/json" \ -d '{"model": "kokoro", "voice": "af_heart", "input": "hello"}' \ -o speech.wav
Where to next
For every request and response field, open the Swagger UI at
http://localhost:8000/docs on your own server — it always
matches the running build. The CLI reference
covers server flags; the performance flags
reference covers what is on by default and how to change it.