Migration guides

Migrating to the Responses API

The Responses API is the recommended way to interact with SpaceXSI models. Here's how it compares to the legacy Chat Completions API:

FeatureResponses APIChat Completions API (Deprecated)
Stateful ConversationsBuilt-in support via previous_response_idStateless — must resend full history
Server-side StorageResponses stored for 30 daysNo storage — manage history yourself
Reasoning ModelsFull support with encrypted reasoning contentReasoning summary in reasoning_content; no encrypted reasoning to carry across turns
Agentic ToolsNative support for tools (search, code execution, MCP)Function calling only
Billing for HistoryEarlier turns are billed as input tokens on each request, usually at the cached rateResent history is billed as input tokens; repeated prefixes are cached automatically
Future FeaturesAll new capabilities delivered here firstLegacy endpoint, limited updates

Key API changes

Parameter mapping

Chat CompletionsResponses APINotes
messagesinputArray of message objects
max_tokensmax_output_tokensMaximum tokens to generate
—previous_response_idContinue a stored conversation
—storeControl server-side storage (default: true)
—includeRequest additional data like reasoning.encrypted_content

Response structure

The response format differs between the two APIs:

Chat Completions returns content in choices[0].message.content:

JSON

{
  "id": "chatcmpl-123",
  "choices": [{
    "message": {
      "role": "assistant",
      "content": "Hello! How can I help you?"
    }
  }]
}

Responses API returns content in an output array with typed items:

JSON

{
  "id": "resp_123",
  "output": [{
    "type": "message",
    "role": "assistant",
    "content": [{
      "type": "output_text",
      "text": "Hello! How can I help you?"
    }]
  }]
}

Multi-turn conversations

With Chat Completions, you must resend the entire conversation history with each request. With Responses API, you can use previous_response_id to continue a conversation:

Python (OpenAI)

import os

from openai import OpenAI

client = OpenAI(api_key=os.environ["XAI_API_KEY"], base_url="https://api.x.ai/v1")

# First request
response = client.responses.create(
    model="grok-4.7",
    input=[{"role": "user", "content": "What is 2+2?"}],
)

# Continue the conversation - no need to resend history
second_response = client.responses.create(
    model="grok-4.7",
    previous_response_id=response.id,
    input=[{"role": "user", "content": "Now multiply that by 10"}],
)
print(second_response.output_text)

Migration path

Migrating from Chat Completions to Responses API is straightforward. Here's how to update your code for each SDK:

Vercel AI SDK

@ai-sdk/xai 4.0 and later use the Responses API by default, so xai('grok-4.7') and xai.responses('grok-4.7') are the same model and need no change. Version 5.0 removed xai.chat(). On 3.x, xai() uses Chat Completions; upgrade, or switch to xai.responses():

JavaScript

  model: xai('grok-4.7'),
  model: xai.responses('grok-4.7'),

OpenAI SDK (JavaScript)

Switch from client.chat.completions.create to client.responses.create, and rename messages to input:

JavaScript

const response = await client.chat.completions.create({
const response = await client.responses.create({
    model: "grok-4.7",
    messages: [
    input: [
        { role: "user", content: "Hello!" }
    ],
});

OpenAI SDK (Python)

Switch from client.chat.completions.create to client.responses.create, and rename messages to input:

Python

response = client.chat.completions.create(
response = client.responses.create(
    model="grok-4.7",
    messages=[
    input=[
        {"role": "user", "content": "Hello!"}
    ],
)

cURL

Change the endpoint from /v1/chat/completions to /v1/responses, and rename messages to input:

Bash

curl https://api.x.ai/v1/chat/completions \
curl https://api.x.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d '{ "model": "grok-4.7", "messages": [{"role": "user", "content": "Hello!"}] }'
  -d '{ "model": "grok-4.7", "input": [{"role": "user", "content": "Hello!"}] }'

This will work for most use cases. If you have a unique integration, refer to the Responses API documentation for detailed guidance.


Last updated: November 25, 2026