Skip to Content
APIGrok / xAI ProtocolChat Completions

Grok Chat Completions

Call Grok models through HaoAI’s Grok / xAI API family. The Grok / xAI route selects only Grok-family models and upstreams; its text request and response payloads use xAI’s OpenAI-compatible Chat Completions JSON and SSE shape.

This is a Grok / xAI protocol boundary, not an OpenAI-upstream alias. Use your HaoAI API key—not an xAI OAuth credential—and the Grok endpoint below.

Base URL and endpoint

The protocol root is:

https://api.hao.ai/grok

For the official OpenAI SDK, configure this SDK base URL:

https://api.hao.ai/grok/v1

The Chat Completions endpoint is:

POST https://api.hao.ai/grok/v1/chat/completions

Authentication

Pass your HaoAI API key as a Bearer token:

Authorization: Bearer <your HAOAI_API_KEY>

Available models

Use canonical model IDs with the grok/ prefix.

Model IDCurrent use
grok/grok-4.5Default frontier model for general, coding, and agentic work; 500,000-token context window.
grok/grok-composer-2.5-fastText-only coding model for Grok Build workflows; 200,000-token context window. It does not accept image input.

Request examples

Terminal
curl https://api.hao.ai/grok/v1/chat/completions \ -H "Authorization: Bearer $HAOAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "grok/grok-4.5", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Explain how an API gateway works."} ] }'

Streaming

Set stream: true to receive an SSE stream in the xAI-compatible Chat Completions format:

grok_stream.py
stream = client.chat.completions.create( model="grok/grok-4.5", messages=[{"role": "user", "content": "Write a short welcome message."}], stream=True, ) for chunk in stream: content = chunk.choices[0].delta.content if content: print(content, end="", flush=True)

For the xAI-compatible Responses shape, use the Grok Responses API.