API contract

The local contract, including its compatibility boundaries.

AFM is OpenAI-compatible where that buys client interoperability, and explicit where local runtimes behave differently. This reference separates compatible fields, AFM extensions, Apple-native routes, and backend-conditional behavior.

Connection contract

ConcernBehavior
Default base URLhttp://127.0.0.1:9999
Request bodiesJSON unless the endpoint explicitly accepts files; UTF-8 is assumed.
AuthenticationNo application-level authentication is added to ordinary local endpoints. Loopback is the default trust boundary; network exposure is an operator decision.
CorrelationSend X-Request-ID or OpenAI-Request-ID. AFM echoes both, or mints req_<uuid12>.
Streamingtext/event-stream; each event uses data: <json> and the stream closes with data: [DONE].
Payload ceilingsChat and batch collection allow 100 MB; narrower Apple and tokenizer endpoints enforce smaller route-specific limits.
OpenAI-compatible or ecosystem-shapedAFM extensionApple-native capability

Contract guides

Route matrix

Availability describes route registration and backend requirements, not a remote service guarantee. Apple framework availability and model capabilities are still checked at request time.

MethodPathContractAvailabilityPurpose
POST/v1/chat/completionsOpenAI-compatibleEvery AFM serverChat, SSE, tools, reasoning, structured output, and logprobs
GET/v1/modelsOpenAI-compatibleEvery AFM serverLoaded chat model, gateway models, and Apple embedding catalog
POST/v1/embeddingsOpenAI-compatibleEvery AFM serverApple NaturalLanguage embeddings, loaded lazily
POST/v1/vision/ocrAFM Apple-nativeSupported macOS releasesOCR, document tables, barcodes, PDFs, and recognized subjects
POST/v1/audio/transcriptionsOpenAI-shapedmacOS 13+On-device speech recognition
POST/v1/audio/speechOpenAI-shapedmacOS 13+Speech synthesis using installed Apple voices
GET/v1/audio/voicesAFM Apple-nativemacOS 13+Discover installed synthesis voices
POST/v1/tokenizevLLM-compatibleMLX tokenizer loadedToken IDs, count, and known context limit
POST/v1/count_tokensAnthropic-shapedMLX tokenizer loadedInput token count
POST/v1/batch/completionsAFM extensionMLX batch serviceMultiplex up to 64 completions over one SSE connection
POST/v1/chat/completions/{id}/cancelAFM extensionEvery AFM serverCooperatively cancel an in-flight generation
GET/metricsPrometheusEvery AFM serverQueue, token, throughput, timing, and connection metrics
GET/healthAFM operationsEvery AFM serverLiveness and build response
GET/openapi.jsonOpenAPI 3.1Every AFM serverThe running binary's compact API description
GET/docsScalar UIEvery AFM serverInteractive reference served by the running process

MLX-only file and batch routes

When AFM owns the concrete MLX batch service, it also registers POST /v1/files, GET /v1/files/{file_id}, GET /v1/files/{file_id}/content, DELETE /v1/files/{file_id}, POST /v1/batches, GET /v1/batches, GET /v1/batches/{batch_id}, and POST /v1/batches/{batch_id}/cancel. These jobs accept JSONL lines targeting /v1/chat/completions.

How to read this contract

  1. Use GET /v1/models to discover what the process advertises now.
  2. Use the hosted OpenAPI document for client generation and planning.
  3. Use the human pages for precedence, conditional behavior, and operational caveats that schemas cannot express well.
  4. Use the running process's /openapi.json to confirm the bundled contract for that binary.