> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nativeport.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nativeport.ai/_mcp/server.

# Grok

Fronts [xAI](https://docs.x.ai)'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

| Endpoint                                              | Notes                                                                                              |
| ----------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `POST v1/chat/completions`                            | The OpenAI-compatible chat endpoint xAI's own client libraries target                              |
| `POST v1/responses`                                   | Stateful 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 channel** — `Authorization: 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

#### Chat Completions

```bash
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."}]
  }'
```

#### Tokenize

```bash
curl -X POST "$GATEWAY/grok/v1/tokenize-text" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"text": "Summarize this page in one sentence.", "model": "grok-4.3"}'
```

#### List your models

```bash
curl "$GATEWAY/grok/v1/models" \
  -H "Authorization: Bearer $TOKEN"
```

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](https://docs.x.ai).