Skip to content

POST /v1/chat/completions ​

Purpose ​

This endpoint starts a new chat request.

Request ​

http
POST /v1/chat/completions
Authorization: Bearer km_your_token_here
Content-Type: application/json

Minimal body ​

json
{
  "model": "group:123e4567-e89b-12d3-a456-426614174000",
  "messages": [
    {
      "role": "user",
      "content": "Summarize this document."
    }
  ]
}

Supported fields ​

FieldTypeRequiredNotes
modelstringyesformat group:<uuid> or custom:<uuid>
messagesarrayyesmust include at least one user message
streambooleannoenables SSE mode
keep_alivebooleannodefault false; JSON whitespace heartbeat, only with stream: false
modalitiesarray<string>noup to 2 values: text, image; omitted or empty uses automatic output selection
max_tokensintegernooutput limit
max_completion_tokensintegernopreferred output limit field
temperaturenumbernovalue between 0 and 2
reasoning_effortstringnobrain reasoning effort, see Conventions
reasoningobjectnoOpenAI-style object; reasoning.effort maps to brain reasoning effort
reasoning_effort_overridesobjectnomaps target IDs such as brain or agent:0 to an effort
metadataobjectnosupports request_id and mode

group:<uuid> can use metadata.mode values auto, normal, orch, or synth. custom:<uuid> runs in normal mode. Sending orch or synth with a custom target returns 400.

Text-only integrations ​

Use "modalities": ["text"] for shopping assistants and other integrations that expect a text response. This disables image generation, editing and composition, including when product data contains image references. This setting only constrains outputs; it does not disable analysis of images accessible to the request. It does not enforce a business JSON schema.

A list containing "image" explicitly requests image production. When the field is absent or empty, the request determines whether an image is needed. This request processing may consume platform credits even when your selected models use your own keys; text-only requests skip output selection.

json
{
  "model": "custom:123e4567-e89b-12d3-a456-426614174000",
  "modalities": ["text"],
  "messages": [{ "role": "user", "content": "Prepare a delivery." }]
}

Standard response ​

In non-streaming mode, the response follows this general shape:

json
{
  "id": "chatcmpl_123",
  "object": "chat.completion",
  "created": 1712345678,
  "model": "group:123e4567-e89b-12d3-a456-426614174000",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Here is the summary."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 120,
    "completion_tokens": 84,
    "total_tokens": 204
  },
  "kitemesh": {
    "execution_id": "3e6f4f5d-c02a-4cae-b35d-e83420867962",
    "credits_charged": 3,
    "request_id": "req_demo_001"
  }
}

Response with tool approval ​

If the request requires approval before a tool can run, the non-stream response can look like this:

json
{
  "id": "chatcmpl_123",
  "object": "chat.completion",
  "created": 1712345678,
  "model": "group:123e4567-e89b-12d3-a456-426614174000",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "1fb2fd25-8f78-412a-a0b8-7976e3700fc4",
            "type": "function",
            "function": {
              "name": "create_ticket",
              "arguments": "{\"priority\":\"high\"}"
            }
          }
        ]
      },
      "finish_reason": "tool_calls"
    }
  ],
  "kitemesh": {
    "approval_id": "86dd028d-6f5c-4f13-83db-d4fe9bc5b865",
    "execution_id": "3e6f4f5d-c02a-4cae-b35d-e83420867962",
    "expires_at": "2026-06-08T16:20:00.000Z"
  }
}

Store approval_id. It is required for POST /v1/chat/resume.

SSE streaming ​

When stream is true, the API returns SSE events.

Example text chunk:

json
{
  "id": "chatcmpl_123",
  "object": "chat.completion.chunk",
  "created": 1712345678,
  "model": "group:123e4567-e89b-12d3-a456-426614174000",
  "choices": [
    {
      "index": 0,
      "delta": {
        "content": "Here "
      },
      "finish_reason": null
    }
  ]
}

Example approval chunk:

json
{
  "id": "chatcmpl_123",
  "object": "chat.completion.chunk",
  "created": 1712345678,
  "model": "group:123e4567-e89b-12d3-a456-426614174000",
  "choices": [
    {
      "index": 0,
      "delta": {
        "tool_calls": [
          {
            "id": "1fb2fd25-8f78-412a-a0b8-7976e3700fc4",
            "type": "function",
            "function": {
              "name": "create_ticket",
              "arguments": "{\"priority\":\"high\"}"
            }
          }
        ]
      },
      "finish_reason": "tool_calls"
    }
  ],
  "kitemesh": {
    "approval_id": "86dd028d-6f5c-4f13-83db-d4fe9bc5b865",
    "execution_id": "3e6f4f5d-c02a-4cae-b35d-e83420867962",
    "expires_at": "2026-06-08T16:20:00.000Z",
    "request_id": "req_demo_001"
  }
}

The end of the stream is marked with:

text
data: [DONE]

Delivery and long requests ​

stream: false waits for a complete JSON response. With keep_alive: true, JSON whitespace is sent periodically while waiting; the final body remains one JSON document. This option defaults to false and is rejected with stream: true. It cannot extend the client's own timeout.

With keep_alive, HTTP status is committed before generation finishes. A later failure returns an error object in the body with HTTP 200; check it before reading choices. Without this option, errors before output preserve their HTTP status.

In SSE mode, ignore heartbeat comments such as : heartbeat, normally sent every 15 seconds. Termination uses data: [DONE]; failures after headers are reported in the stream. Both modes expose X-Kitemesh-Job-Id. Disconnection requests cancellation.

For work that continues without an HTTP connection, use asynchronous jobs. Idempotency-Key is supported as described there.