Use

HTTP API

Edit on GitHub

Everything lives on one port (http://localhost:11234 by default): OpenAI, Anthropic and Ollama wire protocols, plus native media generation endpoints.

POST /v1/chat/completions

curl http://localhost:11234/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "Write a haiku about programming."}],
    "max_tokens": 256,
    "stream": true
  }'

Supports messages, max_tokens, temperature, top_p, top_k, stream, stream_options, tools, response_format, repetition_penalty, presence_penalty, logprobs / top_logprobs, reasoning_effort / enable_thinking / reasoning_budget_tokens, plus per-request kv_quant, kv_attn_mode and suppress_cjk overrides. Messages can include image_url content blocks (base64 or URL) for vision-capable models. Usage always carries prompt_tokens_details.cached_tokens, and completion_tokens_details.reasoning_tokens when the reply reasoned (streamed on the stream_options.include_usage chunk). A reply cut short because the model went in circles reports finish_details: {"type": "repetition_loop"} beside finish_reason.

"suppress_cjk": true keeps every token that writes CJK (Han, kana, Hangul, CJK punctuation, fullwidth forms) out of sampling, drafts included, on /v1/messages, /v1/responses and /v1/completions too. A non-boolean is a 400, null leaves it off, and a model whose engine samples elsewhere (GGUF, Neural Engine) refuses it by name.

Directional ablation

With --ablation-profiles <dir> and --ablation-key-file <path>, /v1/chat/completions and /v1/completions take "ablation": {"profile": "<name>", "strength": 0.0-1.0} (strength defaults to 1) with the key in the X-Ablation-Key header. For that request only, the model removes the profile's direction from everything it writes to its residual stream (Arditi et al. 2024, "Refusal in Language Models Is Mediated by a Single Direction"), and the response carries X-Ablation: profile=<name>; strength=<s>; hash=<hex>, the only confirmation that it ran ablated. A missing or wrong key is a 401. Every other problem is a named 400: an unknown, refused or mismatched profile, a bad strength or field, a model whose plugin lacks Caps.ablation, or the field sent to /v1/messages, /v1/responses, the Ollama routes or a proxied <id>@<provider> / <id>@<peer> model. Other endpoints ignore it. The key is compared with surrounding whitespace trimmed; browsers may send X-Ablation-Key and read X-Ablation cross-origin.

A profile is a directory: manifest.json ("format": "mlx-serve-ablation", "version": 1, hidden_size, base_config_sha256: sha256 of the base pack's exact config.json bytes) and direction.safetensors (one tensor direction, [hidden], F32/F16/BF16, normalized at load). Make the key with openssl rand -hex 32 > key && chmod 600 key and serve only over TLS or loopback: the header is a bearer secret.

Request priority

X-MLX-Priority: high on a request to any of the chat, completion, messages, responses, speech or Ollama routes lets it start between the chunks of a long prompt another request is reading with up to 8192 prompt tokens the cache does not hold, instead of 1024, so a short call does not wait for the whole long prompt. Any client on this machine (loopback, as for LoRA paths) may claim it; from another machine the header is ignored. Such a request starts only once the long prompt has read for as long as the priority requests it already hosted plus this one cost (about one chunk per 1024 tokens): the long prompt keeps at least half its speed, and a shorter one never hosts it. A small request arriving meanwhile waits for it, up to about eight chunks. --prefill-decode-share 0 turns it off with the rest of the chunk-boundary admission; any other value of the header is a normal request.

POST /v1/messages (Anthropic)

curl http://localhost:11234/v1/messages \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "mlx-serve",
    "max_tokens": 256,
    "messages": [{"role": "user", "content": "Write a haiku about programming."}]
  }'

Compatible with Claude Code (ANTHROPIC_BASE_URL=http://localhost:11234 claude) and Anthropic SDKs. Supports streaming, tool calling, and extended thinking. Usage always carries output_tokens_details.thinking_tokens (0 without thinking; streamed on message_delta).

POST /v1/responses (OpenAI Responses API)

curl http://localhost:11234/v1/responses \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mlx-serve",
    "input": "Write a haiku about programming.",
    "stream": true
  }'

Stateful chains via previous_response_id, full streaming SSE with per-event sequence_number, schema-conformant envelope with tools / tool_choice / text / reasoning / usage echo. POST /v1/responses/compact returns an opaque base64 history blob that round-trips back as a compaction input item without any LLM call. Same endpoint also accepts an Upgrade: websocket handshake — each text frame is a response.create JSON message, and each SSE event becomes one outbound text frame.

Ollama API

/api/chat, /api/generate, /api/tags, /api/show, /api/ps, /api/embed, /api/pull speak the Ollama wire (NDJSON streaming, tool calls with object arguments, thinking, format JSON schemas, name:latest model names), so the whole Ollama client ecosystem works against mlx-serve unchanged — point Raycast, Obsidian, Enchanted, Open WebUI, ollama-python/js at http://localhost:11234 where they had http://localhost:11434.

Other endpoints

Every media endpoint takes "stream": true for SSE progress ending in a base64 complete payload. Video streams also accept "preview": true for a cheap JPEG on each denoise step (off by default; cached-velocity H3 steps stay preview-less). Media LoRAs use one grammar everywhere: lora_paths + lora_scales, up to 8, stacked. The paths are files on the server's disk, so only a client on the server's own machine may send them; from anyone else (LAN sharing, --api-key) a request carrying them is a 403.

Qwen3-TTS voice cloning limits

On POST /v1/audio/speech, Qwen3-TTS uses ref_audio (a base64-encoded WAV) to produce a speaker embedding. This is not transcript-conditioned cloning:

Ming-3.0-tts speech

POST /v1/audio/speech on a Ming-3.0-tts-0.5B pack answers a 44.1 kHz mono WAV. The server loads the bf16 pack (inclusionAI/Ming-3.0-tts-0.5b, mlx-community/Ming-3.0-tts-0.5B-bf16) and the affine quantized packs (mlx-community/Ming-3.0-tts-0.5B-8bit, jorgepb96/Ming-3.0-tts-0.5B-4bit). input takes up to 50,000 characters: long text is split by paragraph, sentence and clause, and joined with pauses.

Qwen-Image transparent PNG output

POST /v1/images/generations accepts "transparent": true for Qwen-Image-2.1. It preserves the VAE's native fourth (alpha) channel in the returned PNG, including SSE complete responses. Omitted or false keeps the existing RGB output; other image backends return HTTP 400 when transparent is true.

Use the official RGBA prompt convention, for example: This is an RGBA image with transparency. A red apple. The image has alpha channel and the background is transparent. The option preserves generated alpha; it does not rewrite the prompt. It also applies to "mode":"edit", so an instruction such as "remove the background" returns the edited image with its alpha channel.