Inference API

Chat

View as Markdown

POST /v1/chat/completions

/v1/chat/completions

Create a chat response from text/image chat prompts. This is the endpoint for making requests to chat and image understanding models.

Request Body

Response Body

choicesarray<object>

A list of response choices from the model. The length corresponds to the `n` in request body (default to 1).

createdinteger

The chat completion creation time in Unix timestamp.

idstring

A unique ID for the chat response.

modelstring

Model ID used to create chat completion.

objectstring

The object type, which is always `"chat.completion"`.

service_tier"default" | "priority"

Processing tier for a request. Determines scheduling priority and billing.

Example
{
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant that can answer questions and help with tasks."
    },
    {
      "role": "user",
      "content": "What is 101*3?"
    }
  ],
  "model": "latest"
}

POST /v1/responses

/v1/responses

Generates a response based on text or image prompts. The response ID can be used to retrieve the response later or to continue the conversation without repeating prior context. New responses will be stored for 30 days and then permanently deleted.

Request Body

inputstring | array<object | object | object | object | object>

Content of the input passed to a `/v1/response` request.

Response Body

backgroundboolean

OpenResponses compatibility fields. Not used at the moment. Just for OpenResponses compatibility. Whether to process the response asynchronously in the background.

created_atinteger

The Unix timestamp (in seconds) for the response creation time.

frequency_penaltynumber

(NOT SUPPORTED in Responses API) Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.

idstring

Unique ID of the response.

metadataobject

Only included for compatibility.

modelstring

Model name used to generate the response.

objectstring

The object type of this resource. Always set to `response`.

outputarray<object | object | object | object | object | object | object | object | object | object>

The response generated by the model.

parallel_tool_callsboolean

Whether to allow the model to run parallel tool calls.

presence_penaltynumber

(NOT SUPPORTED in Responses API) Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.

service_tier"default" | "priority"

statusstring

Status of the response. One of `completed`, `in_progress` or `incomplete`.

storeboolean

Whether to store the input message(s) and model response for later retrieval.

textobject

tool_choicestring | object

Parameter to control how model chooses the tools.

toolsarray<object | object | object | object | object | object | object | object>

A list of tools the model may call in JSON-schema. Currently, only functions and web search are supported as tools. A max of 128 tools are supported.

top_logprobsinteger

An integer between 0 and 8 specifying the number of most likely tokens to return at each token position.

truncationstring

The truncation strategy to use for the model response.

Code Examples

**Response example:**


Example
curl -s https://api.x.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d '{
    "model": "grok-4.6",
    "input": "What is the meaning of life?"
  }'

POST /v1/responses/compact

/v1/responses/compact

Compacts a full Responses API input window into a shorter canonical window.

Request Body

inputstring | array<object | object | object | object | object>

Content of the input passed to a `/v1/response` request.

modelstring

Model to use for compaction summarization (required).

Response Body

created_atinteger

Unix timestamp (in seconds) when the compacted conversation was created.

idstring

Unique ID for this compaction (e.g. `cmp_<uuid>`).

modelstring

Model used for the compaction summary.

objectstring

Always `"response.compaction"`.

outputarray<object | object | object | object | object>

Compacted output containing a single compaction item. Pass this verbatim as input to the next `/v1/responses` call.

Code Examples

**Response example:**


Example
curl -s https://api.x.ai/v1/responses/compact \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d '{
    "model": "grok-4.6",
    "input": [
      {"role": "system", "content": "You are a concise and knowledgeable science tutor."},
      {"role": "user", "content": "What is the Higgs boson and why is it important?"},
      {"role": "assistant", "content": "The Higgs boson is an elementary particle in the Standard Model, predicted by Peter Higgs in 1964 and confirmed at CERN in 2012. It is the quantum excitation of the Higgs field, which gives mass to fundamental particles via the Higgs mechanism."},
      {"role": "user", "content": "How does the Higgs mechanism actually work?"},
      {"role": "assistant", "content": "Through spontaneous symmetry breaking. The Higgs field has a nonzero vacuum value, and particles acquire mass in proportion to how strongly they couple to it. Photons do not couple, which is why they remain massless."}
    ]
  }'

GET /v1/responses/{response_id}

/v1/responses/{response_id}

Retrieve a previously generated response.

Path Parameters

response_idstring

The response id returned by a previous create response request.

Response Body

backgroundboolean

OpenResponses compatibility fields. Not used at the moment. Just for OpenResponses compatibility. Whether to process the response asynchronously in the background.

created_atinteger

The Unix timestamp (in seconds) for the response creation time.

frequency_penaltynumber

(NOT SUPPORTED in Responses API) Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.

idstring

Unique ID of the response.

metadataobject

Only included for compatibility.

modelstring

Model name used to generate the response.

objectstring

The object type of this resource. Always set to `response`.

outputarray<object | object | object | object | object | object | object | object | object | object>

The response generated by the model.

parallel_tool_callsboolean

Whether to allow the model to run parallel tool calls.

presence_penaltynumber

(NOT SUPPORTED in Responses API) Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.

service_tier"default" | "priority"

statusstring

Status of the response. One of `completed`, `in_progress` or `incomplete`.

storeboolean

Whether to store the input message(s) and model response for later retrieval.

textobject

tool_choicestring | object

Parameter to control how model chooses the tools.

toolsarray<object | object | object | object | object | object | object | object>

A list of tools the model may call in JSON-schema. Currently, only functions and web search are supported as tools. A max of 128 tools are supported.

top_logprobsinteger

An integer between 0 and 8 specifying the number of most likely tokens to return at each token position.

truncationstring

The truncation strategy to use for the model response.

ExampleJSON

JSON

{
  "created_at": 1754475266,
  "id": "ad5663da-63e6-86c6-e0be-ff15effa8357",
  "max_output_tokens": null,
  "model": "latest",
  "object": "response",
  "output": [
    {
      "content": [
        {
          "type": "output_text",
          "text": "101 multiplied by 3 is 303.",
          "logprobs": null,
          "annotations": []
        }
      ],
      "id": "msg_ad5663da-63e6-86c6-e0be-ff15effa8357",
      "role": "assistant",
      "type": "message",
      "status": "completed"
    },
    {
      "id": "",
      "summary": [
        {
          "text": "First, the user asked: \"What is 101*3?\"\n\nThis is a simple multiplication: 101 multiplied by 3.\n\nCalculating: 100 * 3 = 300, and 1 * 3 = 3, so 300 + 3 = 303.\n\nI should respond helpfully and directly, as per my system prompt: \"You are a helpful assistant that can answer questions and help with tasks.\"\n\nKeep the response concise and accurate. No need for extra fluff unless it adds value.\n\nFinal answer: 303.",
          "type": "summary_text"
        }
      ],
      "type": "reasoning",
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "previous_response_id": null,
  "reasoning": null,
  "temperature": null,
  "text": {
    "format": {
      "type": "text"
    }
  },
  "tool_choice": "auto",
  "tools": [],
  "top_p": null,
  "usage": {
    "prompt_tokens": 32,
    "completion_tokens": 9,
    "total_tokens": 151,
    "prompt_tokens_details": {
      "text_tokens": 32,
      "audio_tokens": 0,
      "image_tokens": 0,
      "cached_tokens": 8
    },
    "completion_tokens_details": {
      "reasoning_tokens": 110,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    },
    "num_sources_used": 0
  },
  "user": null,
  "incomplete_details": null,
  "status": "completed",
  "store": true
}

DELETE /v1/responses/{response_id}

/v1/responses/{response_id}

Delete a previously generated response.

Path Parameters

response_idstring

The response id returned by a previous create response request.

Response Body

deletedboolean

Whether the response was successfully deleted.

idstring

The response_id to be deleted.

objectstring

The deleted object type, which is always `response`.

ExampleJSON

JSON

{
  "id": "ad5663da-63e6-86c6-e0be-ff15effa8357",
  "object": "response",
  "deleted": true
}

GET /v1/chat/deferred-completion/{request_id}

/v1/chat/deferred-completion/{request_id}

Tries to fetch a result for a previously-started deferred completion. Returns `200 Success` with the response body, if the request has been completed. Returns `202 Accepted` when the request is pending processing.

Path Parameters

request_idstring

The deferred request id returned by a previous deferred chat request.

Response Body

choicesarray<object>

A list of response choices from the model. The length corresponds to the `n` in request body (default to 1).

createdinteger

The chat completion creation time in Unix timestamp.

idstring

A unique ID for the chat response.

modelstring

Model ID used to create chat completion.

objectstring

The object type, which is always `"chat.completion"`.

service_tier"default" | "priority"

Processing tier for a request. Determines scheduling priority and billing.

ExampleJSON

JSON

{
  "id": "335b92e4-afa5-48e7-b99c-b9a4eabc1c8e",
  "object": "chat.completion",
  "created": 1743770624,
  "model": "latest",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "101 multiplied by 3 is 303.",
        "refusal": null
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 31,
    "completion_tokens": 11,
    "total_tokens": 42,
    "prompt_tokens_details": {
      "text_tokens": 31,
      "audio_tokens": 0,
      "image_tokens": 0,
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "system_fingerprint": "fp_156d35dcaa"
}

Last updated:May 21, 2026