Grok
Call Grok chat, reasoning, and image models through the OpenAI-compatible API.
| Item | Value |
|---|---|
| Base URL | https://api.hop-base.com/v1 |
| Chat | POST /v1/chat/completions |
| Responses | POST /v1/responses |
| Image generation | POST /v1/images/generations |
Use the exact model ID returned by GET /v1/models; no aliases or bare names are registered.
curl https://api.hop-base.com/v1/chat/completions \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4.6",
"messages": [{
"role": "user",
"content": "Summarize this quarter'\''s risks in five bullets."
}]
}'Chat and reasoning models
| Model ID | Context window |
|---|---|
grok-4.6 | 500K |
grok-4.5 | 500K |
grok-4.3 | 1M |
grok-4.20-0309-reasoning | 2M |
grok-4.20-multi-agent-0309 | 2M |
Both POST /v1/chat/completions and POST /v1/responses are available to any OpenAI SDK client. Codex CLI cannot use Grok directly: it sends a namespace tool type that the model service rejects with 422 before generating anything. On /v1/responses, previous_response_id is removed and store is forced to false, so send the full input every turn.
422 Failed to deserialize the JSON body into the target type: tools[<n>].type: unknown variant `namespace`Chat and image models are served by the Grok Suite group; video is served by Grok Video. A key reaches the video model only if it also includes Grok Video; one key can include both groups. Check GET /v1/models with the key you intend to use.
xAI serves grok-4.20-multi-agent-0309 only over Responses. HopBase converts chat/completions requests to Responses for you and returns standard Chat Completions output, streaming or not. The model does not accept client-side function tools yet: xAI returns 400 on both endpoints.
Request parameters
Applies to both endpoints. The gateway only rejects empty messages on Chat Completions and sets no bound on the parameters below; limits marked "official" come from xAI's reasoning guide and API reference.
| Parameter | Required | Type & limits | Default | Description |
|---|---|---|---|---|
model | Required | One of the five IDs above | — | Exact match, no aliases |
messages / input | Required | Non-empty messages on Chat; input on Responses | — | Empty messages returns a gateway 400 |
max_tokens / max_output_tokens | Optional | Integer; no gateway limit, bounded by the context window | Official default 128,000 on Responses | Officially includes reasoning tokens |
temperature | Optional | Number 0–2 (official) | Service default | Higher values give more varied output |
top_p | Optional | Number 0–1 (official) | Service default | xAI recommends this or temperature, not both |
reasoning_effort | Optional | Values listed below | high | Reasoning cannot be turned off |
tools | Optional | Function tools and server-side tools | — | Server-side tools are billed per call |
stream_options.include_usage | Optional | Boolean | false | Must be true to receive usage when streaming Chat |
xAI offers reasoning_effort on two models only:
grok-4.6:low/medium/high/xhigh.grok-4.5:low/medium/high.grok-4.20-multi-agent-0309usesreasoning.effort(reasoning_efforton Chat Completions), which sets how many agents collaborate.
presence_penalty, frequency_penalty, and stop are not supported (official); reasoning models reject them with an error. On grok-4.20 and newer, logprobs and top_logprobs are not supported either and token log probabilities are not returned, so omit them.
For every field, see API reference · Chat Completions and pick the Grok model family.
Billing and usage
Long-context requests
A request whose prompt exceeds 200,000 tokens is treated as a long-context request.
- The threshold counts non-cached input plus cached input. Output tokens do not count toward it.
- A request that lands exactly on 200,000 tokens does not cross it; it takes one token more.
- Affected requests are flagged
long_contexton the Usage page in the console, so you can tell them apart.
Reasoning tokens
Grok is a reasoning family, and the two endpoints report reasoning differently. This matters when you read usage programmatically.
| Endpoint | Output field | Includes reasoning? |
|---|---|---|
/v1/chat/completions | completion_tokens | No |
/v1/responses | output_tokens | Yes |
Chat Completions reports reasoning separately in completion_tokens_details.reasoning_tokens. HopBase passes xAI's response body through unchanged, so a single reply can report completion_tokens: 1 with reasoning_tokens: 158.
Add the two together to get the real output length; on /v1/responses it is already included, so do not add it again.
Server-side tools
Grok can call built-in server-side tools during a request: web search, X search, code interpreter, document search, and file search. MCP calls reach your own remote service.
The number of tool calls a request made is shown on the Usage page in the console, broken down by tool type. See the signed-in Model Plaza for your effective rates.
If you read usage from a streamed chat response, note that this model sometimes emits mirror fields input_tokens and output_tokens fixed at zero in the final usage chunk. HopBase backfills them from the standard fields when that happens.
Image models
The Grok image models grok-imagine-image, grok-imagine-image-2.0, and grok-imagine-image-quality use the standard OpenAI Images API and are synchronous only. Use POST /v1/images/generations for text to image and POST /v1/images/edits for image to image.
Shape comes from aspect_ratio and the pixel tier from resolution; there is no size. For the full parameters, measured output sizes, and what you are billed for, see Grok Imagine images and video.
Grok video (grok-imagine-video-1.5) belongs to the Grok Video group and uses the asynchronous task API; it is covered on the same page.
Next steps
- Grok Imagine images and video
- Codex CLI — direct connection over Responses
- Error codes and retries
- Concurrency, timeouts, and billing