Skip to content

Grok

Call Grok chat, reasoning, and image models through the OpenAI-compatible API.

ItemValue
Base URLhttps://api.hop-base.com/v1
ChatPOST /v1/chat/completions
ResponsesPOST /v1/responses
Image generationPOST /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 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 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.

Multi-agent also works on Chat Completions.

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.

ParameterRequiredType & limitsDefaultDescription
modelRequiredOne of the five IDs above—Exact match, no aliases
messages / inputRequiredNon-empty messages on Chat; input on Responses—Empty messages returns a gateway 400
max_tokens / max_output_tokensOptionalInteger; no gateway limit, bounded by the context windowOfficial default 128,000 on ResponsesOfficially includes reasoning tokens
temperatureOptionalNumber 0–2 (official)Service defaultHigher values give more varied output
top_pOptionalNumber 0–1 (official)Service defaultxAI recommends this or temperature, not both
reasoning_effortOptionalValues listed belowhighReasoning cannot be turned off
toolsOptionalFunction tools and server-side tools—Server-side tools are billed per call
stream_options.include_usageOptionalBooleanfalseMust 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-0309 uses reasoning.effort (reasoning_effort on 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_context on 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.

EndpointOutput fieldIncludes reasoning?
/v1/chat/completionscompletion_tokensNo
/v1/responsesoutput_tokensYes

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.

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