Messages

Messages API

Call Kimi models with an Anthropic Messages API compatible format, supporting streaming, tool use, image input, thinking, and structured output.

post/anthropic/v1/messages

Request

  • Base URL: https://api.moonshot.ai
  • URL: https://api.moonshot.ai/anthropic/v1/messages
  • Auth: HTTP bearer

Headers

X-Msh-Request-Noncestring
Example:7d929748-0ae6-41c2-ab5d-a186498ad721

A client-generated random nonce (a UUID v4 is recommended). Sending it enables Request Signature: the Kimi API returns Msh-Request-Timestamp and Msh-Request-Signature in the response headers, which can later be used to prove that the request was handled by the Kimi API. Exactly one non-empty header value is allowed; if the value is invalid, the request proceeds normally but the headers above are not returned. See Verify Request Signature.

Request body

model'kimi-k3' required

Model ID

max_tokensinteger required

Maximum number of tokens to generate, required. If the limit is reached before the model finishes, stop_reason is max_tokens.

streamboolean

Whether to stream the response as Server-Sent Events, default false

stop_sequencesstring[]

Stop sequences. Generation stops on an exact match; the matched sequence itself is not output. Up to 5 entries, each at most 32 bytes.

Example request

{
  "messages": [
    {
      "role": "user"
    }
  ]
}

Response

Message response

idstring

Unique identifier of the response

type'message'
role'assistant'
modelstring

The model specified in the request

stop_reason'end_turn' | 'max_tokens' | 'tool_use' | 'refusal' | 'null' nullable

Stop reason. end_turn: finished naturally (including a stop_sequences match); max_tokens: reached the max_tokens limit; tool_use: the model issued a tool call; refusal: content safety review was triggered.

stop_sequencestring nullable

The stop sequence that was matched

Example response

{
  "type": "message"
}

Changes

No recorded changes to this operation across all 1 revision of this API.