API / migrate-chat-completions-to-responses

API

Migrate Chat Completions calls to Responses

Migrate Chat Completions calls to Responses

Responses is the recommended xAI API. Chat Completions is deprecated. Change the endpoint from /v1/chat/completions to /v1/responses, rename messages to input, and rename max_tokens to max_output_tokens. Then you can pass previous_response_id, store, and include (for example reasoning.encrypted_content).

Chat Completions Responses API Notes
messages input Array of message objects
max_tokens max_output_tokens Maximum tokens to generate
previous_response_id Continue a stored conversation
store Control server-side storage (default: true)
include Request additional data like reasoning.encrypted_content

Chat Completions returns text at choices[0].message.content. Responses returns an output array of typed items (type: "message" with output_text). Stored Responses last 30 days. previous_response_id continues a stored conversation without resending the full history.

OpenAI SDK (Python)

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

was client.chat.completions.create(..., messages=[...]).

OpenAI SDK (JavaScript)

const response = await client.responses.create({
    input: [
        { role: "user", content: "Hello!" }
    ],
});

was client.chat.completions.create({ messages: [...] }).

Vercel AI SDK

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

was model: xai('grok-4').

curl

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

was POST https://api.x.ai/v1/chat/completions with "messages".

Continue a stored conversation

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

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

Comparison-page examples use grok-4. Swap the model string to grok-4.6 (or another current model) in new code. New capabilities ship on Responses first: encrypted reasoning content, server-side tools (search, code execution, MCP), and automatic conversation-history caching.

Pitfalls

  • Read output (typed items), not choices[0].message.content.
  • store defaults to true. Set store: false when you do not want the 30-day server copy.
  • previous_response_id needs a stored prior response. It fails when storage is off (see disable-store-on-responses).
  • Chat Completions stays on function calling only; server-side agentic tools live on Responses.
  • Console API credits are separate from SuperGrok's weekly pool on grok.com.