The System One EventUtahGo To Event Page →

Docs

Set up Midium, use every part of it, run it for your team, and build on it.

Chat completions

POST /v1/chat/completions — the OpenAI chat API on local models, with streaming, reasoning, tools and structured output, plus the fields Midium adds.

For developers

POST /v1/chat/completions is OpenAI's chat completions API, served by the models on this Mac. Point any OpenAI SDK or client at http://127.0.0.1:9100/v1, send your Midium key, and use a Midium model's name as model. It streams, calls tools, returns structured JSON and gives you the model's reasoning separately from its answer.

Request#

curl http://127.0.0.1:9100/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "Why is the sky blue? One sentence."}
    ],
    "reasoning_effort": "low"
  }'

Fields that aren't in the OpenAI SDK's types (top_k, chat_template_kwargs, strict_max_tokens, …) go in extra_body in Python, or straight into the request object in JavaScript.

Parameters#

NameTypeDescription
modelstringRequired. A model's name or nickname. Midium: matched without regard to case or extra spaces. A nickname such as Qwen3.8 27B (8-bit) picks that exact build; a plain name picks the default build.
messagesarrayRequired. The conversation: system, user, assistant and tool messages. User content can be a string or a list of parts, including images (see Images & vision).
streambooleanSend the reply as server-sent events. Default false.
temperaturenumberSampling temperature. Midium: when you leave it out, the model's recommended value is used (one for thinking turns, one for plain turns), not 1.0.
top_pnumberNucleus sampling. Midium: filled from the model's recommendation when omitted.
top_kintegerMidium: keep only the k most likely tokens (vLLM-style field). Filled from the model's recommendation when omitted.
max_tokensintegerCap on the reply's length. Midium: a cap below 8192 is raised to 8192, because small caps cut reasoning and tool-calling models off mid-answer. Omitted: the model's default, else 32,768. Always limited to the context the prompt leaves free.
strict_max_tokensbooleanMidium: true honors max_tokens exactly, with no 8192 floor.
stopstring or arrayStop sequences.
presence_penaltynumberDefault 0.
frequency_penaltynumberDefault 0.
reasoning_effortstringHow hard a reasoning model thinks. Midium: none turns thinking off; low, medium, high (and minimal, xhigh, max) turn it on and map to the model's own levels where it has them.
chat_template_kwargsobjectMidium: passed to the model's chat template, for example {"enable_thinking": false}. Wins over reasoning_effort.
toolsarrayFunction tools the model may call, plus Midium's {"type": "web_search"}. See Tool calling.
tool_choicestring or objectauto, none, required, or a specific function. See Tool calling.
response_formatobject{"type": "json_object"} or {"type": "json_schema", ...}. See Structured output.
nintegerAccepted, but one choice is always returned.
userstringAccepted and ignored.
speculative_decodingbooleanMidium: false skips the model's speculative-decoding helper for this request, if it has one turned on.
ignore_eosbooleanMidium: for benchmarks. Don't stop at the end-of-text token, so the reply is exactly the cap long. Needs max_tokens (or max_completion_tokens), which then is honored exactly.
max_completion_tokensintegerMidium: read only together with ignore_eos, where it takes the place of max_tokens. Otherwise ignored.
midium_metricsbooleanMidium: with stream: true, the last chunk carries midium_metrics with the engine's measured decode_tps, prompt_tokens and completion_tokens (what Settings → API uses).

Response#

JSON
{
  "id": "chatcmpl-6f1c2a4e-…",
  "object": "chat.completion",
  "created": 1763030400,
  "model": "YOUR_MODEL",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Air scatters short blue wavelengths of sunlight far more than red ones.",
        "reasoning": "The user wants one sentence on Rayleigh scattering…",
        "reasoning_content": "The user wants one sentence on Rayleigh scattering…"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 31,
    "completion_tokens": 58,
    "total_tokens": 89
  }
}
  • model echoes the name you sent.
  • finish_reason is stop, length (the reply hit its cap) or tool_calls.
  • reasoning and reasoning_content hold the model's thinking, the same text twice (most OpenAI-compatible clients read reasoning_content). They're absent when the model didn't think.
  • usage.prompt_tokens_details.cached_tokens appears when part of the prompt was served from the model's cache.

Streaming#

With "stream": true the reply comes as chat.completion.chunk events:

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","reasoning_content":"The user wants"},"finish_reason":null}]}

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Air scatters"},"finish_reason":null}]}

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":31,"completion_tokens":58,"total_tokens":89}}

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":31,"completion_tokens":58,"total_tokens":89}}

data: [DONE]
  • Thinking streams as delta.reasoning_content, the answer as delta.content.
  • Tool calls stream as delta.tool_calls: the call's id and name first, then its arguments.
  • Usage is always sent — on the finishing chunk and on a final chunk with empty choices. You don't need stream_options. Some chunks along the way also carry a running usage.completion_tokens.
  • If generation fails partway, a chunk with an error object and empty choices is sent, then [DONE].

Thinking#

Reasoning models (Qwen 3.x, gpt-oss, and others) think before they answer. The thinking is never mixed into content.

  • A request that says nothing about thinking gets the model's own default: Qwen 3.x thinks, Gemma 4 doesn't.
  • reasoning_effort: "none" or chat_template_kwargs: {"enable_thinking": false} turns it off. Any other reasoning_effort turns it on.
  • GET /v1/models marks models that can think with capabilities.reasoning: true.

Notes#

  • Loading. A model that isn't in memory loads on the first request, so that request takes longer. Keep a model loaded from Settings → Models.
  • Only chat models. A request naming an embedding, reranker, image or video model fails with 400 model_not_chat and says which endpoint to use instead.
  • Audio models. An installed transcription model can be called here with an input_audio part, without streaming or tools. Audio transcription is the better fit.
  • Agents. Hermes Agent, OpenClaw, OpenBot and other OpenAI-compatible agents use this endpoint. See Connectors.

Errors#

StatuscodeWhen
404model_not_foundNo model by that name. The message lists the models you can use.
400model_not_chatThe model can't chat (embedding, reranker, image or video model).
400invalid_tool_choicetool_choice names a tool that isn't in tools.
400invalid_tool_callThe model's tool-call arguments weren't valid JSON.
400unsupported_streaming, unsupported_tools, invalid_audioStreaming, tools or a bad audio part sent to a transcription model.
422—The body doesn't match the schema (a missing model, a wrong type).

Errors use OpenAI's envelope: {"error": {"message", "type", "code"}}. See Errors & limits.

Something here wrong or out of date? Tell us.