Grok

xAI’s chat & Responses API — policed, billed dollar-direct from the response

View as Markdown

Fronts xAI’s Grok API, scoped to text inference. Like the OpenAI and Anthropic routes, this is policed rather than transparent: requests are checked against a model allowlist and a request-field policy before they reach xAI.

GET|POST|DELETE /grok/<api path> → https://api.x.ai/<api path>

This route ships behind a kill switch that defaults to off, plus a per-account pilot allowlist — the same current-availability caveat as the other model-inference routes. A request can 404 here even with a funded, valid key until this route is enabled for your deployment.

Endpoints

EndpointNotes
POST v1/chat/completionsThe OpenAI-compatible chat endpoint xAI’s own client libraries target
POST v1/responsesStateful mode is an explicit opt-in, mirroring the OpenAI route
POST v1/tokenize-text
GET v1/models, GET v1/models/{id}Answered locally from the gateway’s six-model catalog — xAI’s upstream model list is never proxied
v1/files, v1/batches (and their {id} sub-paths)Create/read/delete, ownership-tracked per account

xAI’s Management API (management-api.x.ai) is a separate host and credential this route never addresses — Collections and account-management features that live there are out of scope entirely, not merely unrouted.

Request policy

  • One client credential channelAuthorization: Bearer — is overwritten unconditionally, simpler than Anthropic’s dual-channel case.
  • Always overwritten: user, xAI’s documented end-user attribution field, is replaced with a per-tenant identifier, so abuse enforcement lands on your account rather than the shared key.
  • Checked by its explicit type field: each tools[] entry with type: "function" is validated structurally; any other type must be web_search or x_search — xAI’s Remote MCP tool and code_interpreter are never reachable, for the same credential-relay and unattributable-billing reasons Anthropic’s equivalents are excluded.

Stateful resources

Files and batches you create are tracked per account; a foreign or unknown id answers the same 404. GET v1/files and GET v1/batches (the bare list forms) are answered locally from this ownership record. Batches settle on a recurring poll, since xAI documents no batch-completion webhook either.

Billing

The defining difference from the other model-inference routes: most Grok responses report their own real dollar cost in the response body, and billing reads that figure directly rather than computing it from a maintained price table. The gateway’s price table only backs up the rare response that omits the field. An account can register its own xAI key; while that’s active, calls bill to that key directly instead of metering through the gateway balance.

Examples

$curl -X POST "$GATEWAY/grok/v1/chat/completions" \
> -H "Authorization: Bearer $TOKEN" \
> -H "Content-Type: application/json" \
> -d '{
> "model": "grok-4.3",
> "messages": [{"role": "user", "content": "Summarize this page in one sentence."}]
> }'

Responses arrive as xAI’s JSON, untouched once a request clears the checks above. Field-level request and response detail lives in xAI’s documentation.