Grok

Call xAI's Grok chat, reasoning, and image models through HopBase's OpenAI-compatible API, including long-context pricing, reasoning-token billing, and server-side tool charges.

xAI's Grok models are served through HopBase's OpenAI-compatible protocol. Use https://api.hop-base.com/v1 and the exact model ID returned by GET /v1/models. No aliases or bare names are registered.

Grok video (grok-imagine-video-1.5) sits in a separate plan group and uses the asynchronous task API instead; see Video generation.

Chat and reasoning models

Model IDContext window
grok-4.6500K
grok-4.5500K
grok-4.31M
grok-4.20-0309-reasoning2M
grok-4.20-multi-agent-03092M

Both POST /v1/chat/completions and POST /v1/responses are available, so Codex CLI and any OpenAI SDK client can reach these models.

Multi-agent is Responses-only

grok-4.20-multi-agent-0309 is Responses-only by xAI design. Calling it through chat/completions returns an explicit upstream error — this is the model's own constraint, not a gateway restriction, so the error text comes from xAI.

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_context in your usage record, so you can tell them apart.

Reasoning tokens in the response

Grok is a reasoning family, and the two endpoints report reasoning differently. This matters when you read usage programmatically.

EndpointOutput fieldIncludes reasoning?
/v1/chat/completionscompletion_tokensNo — reasoning is reported separately in completion_tokens_details.reasoning_tokens
/v1/responsesoutput_tokensYes

HopBase passes the upstream response body through unchanged, so a single reply on chat/completions 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.

If you read usage from a streamed chat response, note that this upstream 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.

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 reported in your usage record, broken down by tool type.

Image models

Grok image models use the standard OpenAI Images API — not chat.

EndpointPurpose
POST /v1/images/generationsText to image
POST /v1/images/editsImage to image, with reference images
Model IDResolutions
grok-imagine-image1k; a 2k request is accepted and produced at 1k
grok-imagine-image-2.01k / 2k
grok-imagine-image-quality1k / 2k

Parameters

ParameterNotes
promptRequired
modelRequired, exact ID
nOptional, defaults to 1
resolution1k or 2k, defaults to 1k. 4k is rejected with a 400
imageEdits only. A URL string, an array of strings, or { "url": ... }. At most 2 reference images
maskNot supported — rejected with a 400

Responses return image URLs. Uploading through the OpenAI SDK works: xAI's edits endpoint takes JSON rather than multipart, and HopBase rewrites a multipart request into the shape the upstream expects.

Response shape

Responses return image URLs. An empty response means nothing was produced. Image responses carry no token usage.

curl

# Chat
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." }]
  }'

# Text to image
curl https://api.hop-base.com/v1/images/generations \
  -H "Authorization: Bearer sk-your-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-image-2.0",
    "prompt": "An orange cat asleep on a sunlit windowsill, editorial photography",
    "resolution": "2k",
    "n": 1
  }'

Group selection

Chat and image models are served by the Grok 全系 plan group; video is served by Grok 视频. A key is bound to one group, so a key that reaches the chat models does not reach the video model. Check GET /v1/models with the key you intend to use, and see the signed-in model catalog for your effective rates.

On this page