Inference API

Responses

View as Markdown

The Responses API is the primary interface for text generation, reasoning, and tool use. See the Text Generation guide for usage.



Create new response

/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.

errorobject

An error object returned when the model fails to generate a response.

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 | 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" | "fast"

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 | 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 350 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.7",
    "input": "What is the meaning of life?"
  }'
Exampletext

text

{
  "created_at": 1774274151,
  "completed_at": 1774274155,
  "id": "e7fd6e3f-0a77-9948-99a9-b40ba7c1c6f1",
  "max_output_tokens": null,
  "model": "grok-4.20-0309-reasoning",
  "object": "response",
  "output": [
    {
      "content": [
        {
          "type": "output_text",
          "text": "**42.**",
          "logprobs": [],
          "annotations": []
        }
      ],
      "id": "msg_e7fd6e3f-0a77-9948-99a9-b40ba7c1c6f1",
      "role": "assistant",
      "type": "message",
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "previous_response_id": null,
  "reasoning": {
    "effort": null,
    "summary": null
  },
  "temperature": 0.7,
  "text": {
    "format": {
      "type": "text"
    }
  },
  "tool_choice": "auto",
  "tools": [],
  "top_p": 0.95,
  "usage": {
    "input_tokens": 131,
    "input_tokens_details": {
      "cached_tokens": 128
    },
    "output_tokens": 624,
    "output_tokens_details": {
      "reasoning_tokens": 246
    },
    "total_tokens": 755,
    "num_sources_used": 0,
    "num_server_side_tools_used": 0,
    "cost_in_usd_ticks": 37756000
  },
  "user": null,
  "incomplete_details": null,
  "status": "completed",
  "store": true,
  "metadata": {},
  "background": false,
  "service_tier": "default",
  "truncation": "disabled",
  "top_logprobs": 0,
  "presence_penalty": 0,
  "frequency_penalty": 0,
  "prompt_cache_key": null,
  "max_tool_calls": null,
  "safety_identifier": null,
  "error": null,
  "instructions": null
}

Retrieve previous response

/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.

errorobject

An error object returned when the model fails to generate a response.

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 | 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" | "fast"

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 | 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 350 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.

Exampletext

text

No parameters.
Exampletext

text

{
  "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 previous response

/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`.

Exampletext

text

No parameters.
Exampletext

text

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

Compact a conversation

/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.7",
    "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."}
    ]
  }'
Exampletext

text

{}

Last updated:September 14, 2026