HTTP API
Edit on GitHubEverything 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
GET /— built-in web console (MLX Serve Studio): chat, image/audio/video generation, Library, Monitoring, API referenceGET /health— health checkGET /v1/models— list loaded models with capabilities + engine infoPOST /v1/completions— text completions;promptis a string or token ids ([1, 2, 3], as lm-eval sends them), one prompt per request.echo: truereturns the prompt ahead of the completion and, withlogprobs, every prompt token's logprob (the first isnull); it is refused withstreamPOST /v1/embeddings— text embeddings (BERT, EmbeddingGemma, and last-token pooling models like Qwen3-Embedding; pooling follows the checkpoint's sentence-transformers metadata,dimensionstruncates and renormalizes; EmbeddingGemma 2 wants its task prefix in the text,task: search result | query: …for a query andtitle: none | text: …for a document). EmbeddingGemma 2 also embeds images and video: sendmessages(one prompt, one embedding, like vLLM's chat embeddings) instead ofinput, with{"type": "text"},{"type": "image_url", "image_url": {"url": "data:image/png;base64,…"}}and{"type": "video_url", "video_url": {"frames": ["data:image/jpeg;base64,…", …]}}parts. The parts are concatenated in order (system turns first, as the model's own template does), images keep their aspect ratio and are sized to 280 soft tokens and video frames to 140 (processor_config.json), at most 32 frames of a longer clip are kept, and the whole prompt must fit the 8192-token window. Remote URLs are not fetched and audio is refused by name.POST /v1/decisions— Laya typed decisions:{"model", "state": <string|object>, "questions": {id: {"type": "choice"|"score"|"noul", "instructions", "criteria"}}}returns laya'spredictschema (answerswithtype,confidence,action.act_probability, pluschoice+probabilities,score+legend+probabilities, ornoul). An object state is serialized like Python'sjson.dumps. Limits: 64 questions (MLX_SERVE_LAYA_MAX_QUESTIONS), 32768 input tokens (MLX_SERVE_LAYA_MAX_INPUT_TOKENS), 4 MB body. A Kev pack (kev_config.json) takes the same request,choicecriteria as an object or a list of labels, and answers withoutaction(and withoutconfidenceonnoul); the same question and input-token limits (theMLX_SERVE_LAYA_*pair above), 255 options, 8192 tokens per question including the state. A D1 pack (LiquidAI/d1-3B, bf16) takes the same request as text only:imagesis a 400, and itschoiceandscoreanswers carry aconfidence(the chosen probability) whilenoulanswers carry nonePOST /v1/images/generations,POST /v1/images/edits— image generation and instruction edits; the edits endpoint speaks the OpenAI SDK's multipart shape (client.images.edit), including repeatedimage[]for multi-referencePOST /v1/audio/speech— Qwen3-TTS (Base:ref_audioclones a voice; CustomVoice:voicenames a built-in speaker,instructionsstyle it; VoiceDesign:instructionsdescribe the voice;seed), Kokoro (voicepicks or blends one of 54) or Ming-3.0-tts (below), WAV outPOST /v1/audio/transcriptions— speech to text with Qwen3-ASR (mlx-community'sQwen3-ASR-0.6B/1.7Bpacks), the OpenAI SDK's multipart form (client.audio.transcriptions.create): a WAVfile(any rate and channel count; one past 20 minutes is transcribed in pieces cut where it is quietest), optionallanguage(ISO code or name; omitted, the model detects it),prompt(context such as names to spell),temperature,response_formatjson,text,verbose_json,srt,vttordiarized_json, andtimestamp_granularities[](wordaddswords). Times come from Qwen3-ForcedAligner (mlx-community/Qwen3-ForcedAligner-0.6B-8bit, listed with thealignmentcapability and loaded when a request asks for times):verbose_jsonsegments end at sentences and pauses, every word carriesstart/end,srt/vttare those segments, and a clip past 180 s is cut where it is quietest and each piece transcribed and timed, as the official toolkit does. It times Chinese, Cantonese, English, German, Spanish, French, Italian, Portuguese, Russian, Korean and Japanese; another language, or no aligner on disk, gives one segment over the clip (srt/vttwithout an aligner are a named 400).diarized_jsonis OpenAI's speaker-labelled shape (segmentswithspeaker"A", "B", … in the order they first speak) from Nemotron 3 Diarization (mlx-community/Nemotron-3-Diarization-8bit, up to eight speakers, listed with thediarizationcapability), run once over the whole clip; a segment also closes where the speaker changes. Without the diarizer on disk it is a named 400;known_speaker_names[]is too. With Nemotron 3.5 Transcribe loaded none of this needs a companion: it times every word with its own CTC head (NVIDIA's banded aligner; a pack converted without the head, like mlx-audio's, answersverbose_jsonuntimed andsrt/vttwith a named 400),diarized_jsonasks it for the card's speaker-tagged transcript and names each word's speaker from its own speaker model, and it drafts with its MTP head. Nostream; other audio formats are named 400sPOST /v1/audio/music-generations— text-to-music, WAV out: ACE-Step (48 kHz stereo, fast) MiniMax Music 3 (lyricsrequired, 44.1 kHz, songs up to six minutes) or YuE2 (lyricsrequired, 48 kHz, plans an editable ABC score:cotandabc)POST /v1/video/generations— LTX-Video 2.3 / 2.5 or MiniMax-H3; base64rgb8frames pluspcm_s16leaudio, mux on your side. LTX 2.5 takes"decoder": "diffusion"for its sharper diffusion decoder; long H3 clips chain viachain_windows. Opt-in"preview": trueon"stream": trueattaches a Latent2RGB JPEG to each denoiseprogressevent (preview_frames,preview_max_side)POST /v1/3d/generations— Hunyuan3D-2.1, TRELLIS.2, Pixal3D and Idol (an image to a 3D Gaussian splat: a GLB withKHR_gaussian_splatting), base64 GLBPOST /v1/load-model,POST /v1/unload-model— load a discovered model (or one by absolute path), free one now;"default": truemakes the loaded model the serving default without a restartPOST /v1/models/rescan— pick up models downloaded while the server runs (the app calls it after every download)POST /tokenize,POST /detokenize,GET /props— tokenizer round-trip and llama.cpp-style server propsGET /metrics,GET /metrics.json— Prometheus + JSON (needs--metrics)GET /v1/responses/{id},DELETE /v1/responses/{id}— fetch / delete stored responses
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:
languagepins the spoken language: a name from the checkpoint'stalker_config.codec_language_id(any case:english,portuguese,spanish, …). Omit it or sendautoto let the model infer the language from the text, as before. Any other value, a dialect key included, returns HTTP 400. Pin it when the text could pass for a close language (Brazilian Portuguese read with Spanish phonetics).- The backend does not read
ref_text; a reference transcript does not condition the clone. - A non-empty
ref_audiomust be a decodable WAV and the model must have a speaker encoder. Invalid base64/WAV or a missing encoder returns HTTP 400 before synthesis or SSE headers. Omitref_audio(or send an empty string) to use the plain voice. voice(orspeaker) andinstructionsare honoured or refused, never dropped. A CustomVoice pack needsvoice, one of itstalker_config.spk_idnames (the 400 lists them); its 1.7B size also takesinstructionsas a speaking style. A VoiceDesign pack needsinstructions, a description of the voice. A Base pack takes neither (voicemay be absent ordefault).- To check a reference without generating speech, send
"warm_only": truewithref_audioto the same endpoint. Missing or undecodable reference audio and a missing speaker encoder return HTTP 400 instead of silently falling back. This checks reference handling, not pronunciation or accent quality.
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.
voice: a built-in voice (US_Emma,UK_George,UK_Charlotte, or a Chinese name).instruction: a description of a designed voice.ref_audio(base64 WAV, at most 20 s) clones a voice;ref_textis its transcript and improves the clone. French, German, Spanish, Japanese and Koreaninputneedsref_textto clone in that language's path.language:fr,de,es,ja,ko,zh,enorauto. Absent, these languages are detected frominput. French numbers, dates and typography are spelled out first.taskwithcontrolsselects the reference's other tasks:BASIC(speed,pitch,volume),EMOTION(emotion),DIALECT(dialect),IP,FREEFORM,VOICE_DESIGN(style),MULTILINGUAL. A field a task does not take is a named 400.seed(default 0) repeats a take while no chat runs on the server: with chat alongside, the same seed gives a different take.pause_scale(0 to 4) scales the pauses between fragments. Anything else is a named 400.
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.