chat.v1

docs/capabilities/chat.v1.md · wiki index

chat.v1

Status: v1. A published shape is frozen by spec.md section 20.1. Capability key: chat Route: POST /chat

Parts in

kindrolerequiredmeaning
textsystemnothe system instruction. At most one. Must come first.
textuseryes, one or morea user turn.
textassistantnoa previous assistant turn.
texttoolnoa tool result. The role field of the text part names the tool call.
imageusernoa visual input. The model must declare image in its parts.
audiousernoa speech input. The model must declare audio in its parts.
jsontoolsno{"tools": [{"name", "description", "parameters"}]}.
jsonresponse_formatno{"type": "text"} or {"type": "json_object"}.

Parameters

The plugin validates these. A parameter that is not in this table is ignored, not an error (R26). A default of catalogue means the model entry in the catalogue gives the value.

nametypedefaultmeaning
max_tokensuintcataloguethe output limit
temperaturefloatcataloguesampling temperature
top_pfloatcataloguenucleus sampling
top_kuintcataloguetop-k sampling. 0 disables it.
stopstring arraycataloguestop sequences
seeduintnonea fixed seed for a repeatable job
tool_choicestringautoauto, none, or the name of one tool
logprobsboolfalseemit tokens events as well as text

Channels out

channelmimepayload
texttext/plain; charset=utf-8one UTF-8 fragment of the answer
tokensapplication/cboran array of {id: uint, text: bstr, logprob: float / null}
decisionapplication/jsonone tool call: {call_id, name, arguments}
progressapplication/json{stage, pct} during prefill or a batch

Terminal metadata

keytypemeaning
finish_reasonstringstop, length, tool_calls, or content_filter
modelstringthe served name that ran the job

finish_reason is required when outcome is completed. It is absent when the outcome is cancelled or expired.

Request

POST /chat
{
  "model": "example",
  "input": [
    {"kind": "text", "role": "system", "text": "You answer in one line."},
    {"kind": "text", "role": "user", "text": "What is a ledger?"},
    {"kind": "image", "role": "user", "mime": "image/png", "blob": "<sha256>"}
  ],
  "params": {"max_tokens": 128, "temperature": 0.0},
  "stream": true
}

Response, no stream

{"job": "019...", "outcome": "completed",
 "text": "A record of reserved bytes for each device.",
 "usage": {"tokens_in": 9, "tokens_out": 12},
 "meta": {"finish_reason": "stop", "model": "example"}}

Stream

event  ch=progress {"stage": "prefill", "pct": 0.4}
event  ch=text     "A record of"
event  ch=text     " reserved bytes"
event  ch=decision {"call_id": "c1", "name": "lookup", "arguments": {"term": "ledger"}}
done   outcome=completed meta={"finish_reason": "tool_calls"}

Rules

  1. At least one text part with role user is required. A request with no user turn is invalid_part.
  2. The plugin applies the chat template and the stop set. The core and the adapters never do. The template name comes from the catalogue.
  3. One text event is a whole UTF-8 sequence. A plugin never splits a code point across two events.
  4. A tool call is one decision event per call. The arguments are a JSON object, not a string. call_id is chosen by the plugin and is unique in the job.
  5. finish_reason is exactly one value. A job that reaches max_tokens reports length, not stop.
  6. tokens events are opt-in. A plugin that cannot give logprobs still accepts logprobs = true and emits its best token split, or omits the channel.
  7. No event follows a cancel. The terminal frame is done with outcome = cancelled.
  8. The plugin emits bytes and JSON only. Framing belongs to the core and to the web.