Grok API
  1. Guides
Grok API
  • Getting started
    • Introduction
    • Models and Pricing
    • Billing
    • Consumption and Rate Limits
    • Usage Explorer
    • Free Credits
  • Guides
    • Asynchronous Requests
    • Image Understanding
    • Structured Outputs
    • Migration from Other Providers
    • Chat
      POST
    • Reasoning
      POST
    • Streaming Response
      POST
    • Deferred Chat Completions
      POST
    • Image Generations
      POST
    • Fingerprint
      POST
  1. Guides

Streaming Response

POST
https://api.x.ai/v1/chat/completions
Streaming outputs is supported by all models with text output capability (Chat, Image Understanding, etc.). It is not supported by models with image output capability (Image Generation).
Streaming outputs uses Server-Sent Events (SSE) that let the server send back the delta of content in event streams.
Streaming responses are beneficial for providing real-time feedback, enhancing user interaction by allowing text to be displayed as it's generated.
To enable streaming, you must set "stream": true in your request:
You'll get the event streams like these:
It is recommended that you use a client SDK to parse the event stream.
Example streaming responses in Python/Javascript:
Request Request Example
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.x.ai/v1/chat/completions' \
--header 'Authorization: Bearer ' \
--header 'Content-Type: application/json' \
--data-raw '{
        "messages": [
          {
            "role": "system",
            "content": "You are Grok, a chatbot inspired by the Hitchhikers Guide to the Galaxy."
          },
          {
            "role": "user",
            "content": "What is the meaning of life, the universe, and everything?"
          }
        ],
        "model": "grok-3-latest",
        "stream": true,
        "temperature": 0
      }'
Response Response Example
{}

Request

Header Params
Content-Type
string 
required
Example:
application/json
Authorization
string 
required
Example:
Bearer {{XAI_API_KEY}}
Body Params application/json
messages
array [object {2}] 
required
role
string 
required
content
string 
required
model
string 
required
stream
boolean 
required
temperature
integer 
required
Examples

Responses

🟢200Success
application/json
Body
object {0}
Modified at 2025-04-10 08:51:55
Previous
Reasoning
Next
Deferred Chat Completions
Built with