---
title: "Create a messages response. This endpoint is compatible with the Anthropic API."
method: POST
path: "/v1/messages"
tags: ["v1"]
---

# Create a messages response. This endpoint is compatible with the Anthropic API.

`POST /v1/messages`

## Request body

- MessageRequest — Request message for `/v1/messages`
  - `max_tokens` integer — The maximum number of tokens to generate before stopping. The model may stop before the max_tokens when it reaches the stop sequence.
  - `messages` MessageBody[] — Input messages.
    - `content` union, required
      - string — Text prompt.
      - MessageContentPart[] — An array of message content parts.
        - union
          - object — Text prompt message content part.
            - `cache_control` unknown
            - `text` string, required — Text prompt.
            - `type` 'text', required
          - object — Image prompt message content part.
            - `cache_control` unknown
            - `source` union, required
              - …
            - `type` 'image', required
          - object — Tool call message content part. Received from model.
            - `cache_control` unknown
            - `id` string, required — ID of the tool call.
            - `input` unknown, required
            - `name` string, required — Name of the tool call.
            - `type` 'tool_use', required
          - object — Tool call result.
            - `cache_control` unknown
            - `content` union, required — Content of a tool_result block. The Anthropic SDK may send this as either a plain string or an array of typed content blocks (e.g. `[{"type": "text", "text": "..."}]`).
              - …
            - `is_error` boolean, nullable — Whether the tool call returns an error.
            - `tool_use_id` string, required — ID of the tool call given by the model.
            - `type` 'tool_result', required
          - object — (Redacted) Thinking of the model.
            - `data` string, required — Encrypted data of the redacted thinking.
            - `type` 'redacted_thinking', required
          - object — Thinking of the model.
            - `signature` string, nullable — Signature of the thinking block (required by Anthropic SDK for round-tripping).
            - `thinking` string, required — Thinking.
            - `type` 'thinking', required
    - `role` string, required — The role that the message belongs to, `"system"` for system prompt, `"user"` for user prompt, and `"assistant"` for response from the model.
  - `metadata` MessageMetadata
    - `user_id` string, nullable — A unique identifier representing your end-user, which can help xAI to monitor and detect abuse.
  - `model` string — Model name for the model to use.
  - `stop_sequences` string[], nullable — (Not supported by reasoning models) Up to 4 sequences where the API will stop generating further tokens.
  - `stream` boolean, nullable — If set, partial message deltas will be sent. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a `data: [DONE]` message.
  - `system` union
    - string — Text content of system prompt.
    - SystemMessagePart[] — An array of system prompt parts.
      - `cache_control` unknown
      - `text` string, required — System prompt text.
      - `type` string, required — Type of the object. This is always `"text"`.
  - `temperature` number, float, nullable — What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. It may not work well with reasoning models.
  - `tool_choice` union — Tool choice option.
    - object — Allows the model to automatically decide whether to call the tool
      - `type` 'auto', required
    - object — Forces the model to use at least one tool, without specifying the tool.
      - `type` 'any', required
    - object — Forces the model to use the named tool
      - `name` string, required — Name of the tool to use.
      - `type` 'tool', required
  - `tools` MessageTools[], nullable — A list of tools the model may call in JSON-schema. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.
    - `cache_control` unknown
    - `description` string, required — Description of the tool.
    - `input_schema` MessageToolInputSchema, required
      - `properties` unknown, required
      - `required` string[], nullable — Required properties of the tool input schema, if any.
      - `type` string, required — Type of the schema. This is always `"object"`.
    - `name` string, required — Name of the tool.
  - `top_k` integer, nullable — (Unsupported) When generating next tokens, randomly selecting the next token from the k most likely options.
  - `top_p` number, float, nullable — An alternative to sampling with `temperature`, called nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. It is generally recommended to alter this or `temperature` but not both.

## Response `200`

Success

- MessageResponse — Response message for `/v1/messages`
  - `content` MessageResponseContent[], required — Response message content.
    - union
      - object — Text response from the model.
        - `text` string, required
        - `type` 'text', required
      - object — Thinking response for the model
        - `signature` string, required — Signature of the content
        - `thinking` string, required — Thinking content
        - `type` 'thinking', required
      - object — Redacted thinking response for the model
        - `data` string, required — Signature of the content
        - `type` 'redacted_thinking', required
      - object — Request by the model to invoke a tool call.
        - `id` string, required — Tool call ID.
        - `input` unknown, required
        - `name` string, required — Name of the tool call to be used.
        - `type` 'tool_use', required
  - `id` string, required — Unique object identifier.
  - `model` string, required — Model name that handled the request.
  - `role` string, required — Role of the generated message. Always `"assistant"`
  - `stop_reason` string, nullable — Reason to stop. `"stop_sequence"` means the inference has reached a model-defined or user-supplied stop sequence in `stop`. `"max_tokens"` means the inference result has reached models' maximum allowed token length or user defined value in `max_tokens`. `"end_turn"` or `null` in streaming mode when the chunk is not the last. `"tool_use"` means the model has called a tool and is waiting for the tool response.
  - `stop_sequence` string, nullable — Custom stop sequence used to stop the generation.
  - `type` string, required — Object type. This is always `"message"` for message types.
  - `usage` MessageUsage, required
    - `cache_creation_input_tokens` integer, required — (Unsupported) Number of tokens written to the cache when creating a new entry.
    - `cache_read_input_tokens` integer, required — Number of tokens retrieved from the cache for this request.
    - `input_tokens` integer, required — Number of input tokens used
    - `output_tokens` integer, required — Number of output tokens used

## Other responses

- `400` — Bad request. The request is invalid or an invalid API key is provided.
- `422` — Unprocessable Entity. There are missing fields in the request body.

---

[API](https://skmtc.net/x/apis/xai-s-rest-api.md) · [All operations](https://skmtc.net/x/apis/xai-s-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/x/xai-s-rest-api/revisions/8f6014272113/schema)
