Reference · HTTP API

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:

Live OpenAPI schema. Every running server exposes its own machine-readable schema at 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

EndpointWhat it does
POST /v1/chat/completionsChat completions — tools, vision, streaming and reasoning_content.
POST /v1/responsesOpenAI Responses API — streaming with item-by-item events, reasoning items, tool calls.
POST /v1/messagesAnthropic Messages API — tools, streaming and thinking blocks.
POST /v1/messages/count_tokensAnthropic token count for a Messages request.
POST /v1/completionsText completion without a chat template.
GET /v1/modelsThe served models with their parsers, modality, capabilities and context window.
POST /v1/rerankScore documents against a query in relevance order — start with --rerank-model <hf-id>. Requests default to at most 1000 documents.
POST /v1/cache/prefillWarm 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/embeddingsEmbeddings — 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/speechText-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/transcriptionsSpeech-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/translationsSpeech-to-English translation — needs the [audio] extra.
POST /v1/audio/musicText-to-music and sound effects — needs the [audio] extra.
POST /v1/images/generationsText-to-image (FLUX, Qwen-Image, Z-Image and more) — uses the bundled image runtime and Python 3.12+. Returns b64_json.
POST /v1/images/editsImage editing on models that support it (e.g. qwen-image-edit).
POST /v1/videosCreate 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}/contentDownload the finished MP4.
POST /v1/videos/extendExtend 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/capabilitiesWhat the loaded video model accepts — modes, native fps, size and frame-count rules, and the extension limits.
POST /v1/requests/{id}/cancelCancel an in-flight request.
GET /v1/statusRunning and waiting requests, cache and Metal memory.
GET /healthHealth probe (also /healthz, /readyz, /livez, /health/ready).
GET /metricsPrometheus counters and histograms.
GET /openapi.jsonOpenAPI 3 schema for every route.
GET /docsSwagger 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.

EndpointResponse / behavior
GET /rapid/v1/statuscontrol_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/logcalls array. Optional limit query parameter: 1–1,000, default 50. Each record contains ts, method, path, status, duration_ms and client.
GET /rapid/v1/jobsjobs array of agent runs: id, kind, status, created, updated and a bounded summary.
POST /rapid/v1/jobs/{job_id}/cancelCancel 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

Where it differs

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.