> ## Documentation Index
> Fetch the complete documentation index at: https://www.agent37.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Host Grok

> Run xAI's Grok coding agent on its own always-on instance, on your own xAI API key.

The `agent37-grok` [template](/docs/agents-api/templates) runs Grok, xAI's coding agent, on an Agent37 instance: an always-on computer with the same chat API, sessions, files, and URLs as every other template. The image is lean, with no browser and no desktop. Grok runs on **your own xAI API key**: Agent37 never supplies or bills xAI model usage, and there is no managed-model option on this template, so set your key before the first chat turn.

## Create the instance

One call to the hosting API at `https://api.agent37.com`, with your xAI API key as [instance env](/docs/agents-api/instances#environment-variables):

```bash curl theme={null}
curl -X POST https://api.agent37.com/v1/instances \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "template": "agent37-grok", "env": { "XAI_API_KEY": "xai-..." } }'
```

The `201` response carries the instance id and its URL, `https://{instanceId}.agent37.app`, which routes to the gateway on port `3737`. The terminal is on port `7681` and the file browser on `8080`, each at `https://{instanceId}-{port}.agent37.app`; see [Instance and preview URLs](/docs/agents-api/urls).

Grok reads `XAI_API_KEY` straight from the environment, so there is no login step: the first turn works as soon as the instance is running. Until a key is set, a chat turn fails with `auth_error`, and `GET /v1/health?agent=grok` on the instance URL reports `"healthy": false`. To connect a Grok subscription account instead of a key, mint a [signed URL](/docs/agents-api/urls#browser-access-with-signed-urls) for the terminal port and run `grok login --device-code` in the shell; the login persists on the instance volume.

## Send the first message

Chat is the instance URL plus a path, with the same `sk_live_` key sent as the `X-Agent37-Key` header. `grok` is the template's default agent, so there is no `agent` field to pass:

```bash curl theme={null}
curl https://ab12cd34ef.agent37.app/v1/responses \
  -H "X-Agent37-Key: sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "input": "Clone github.com/expressjs/express and summarize how routing works." }'
```

Set `"stream": true` to receive the turn as Server-Sent Events instead of one JSON body, and reuse the returned `session_id` to continue the conversation. Grok owns its session store, so start a session by omitting `session_id`; you cannot bring an unknown id on the first turn. See [Send a message](/docs/agents-api/chat) and [Streaming](/docs/agents-api/streaming).

## Models

`GET /v1/models?agent=grok` on the instance lists the models your xAI key can run, the `grok-4.x` family. With no key set the list is empty. Pass an id as `model` on a turn, and set `reasoning_effort` per turn (`ultra` maps to Grok's `max`; non-reasoning models ignore the knob). Usage bills to your xAI account, not your Agent37 wallet, and each turn's `usage` reports the real USD cost. See [Models](/docs/agents-api/models).

## Connect apps

[App integrations](/docs/agents-api/integrations) work here like on every system template: drive the `/v1/integrations` endpoints to connect your users' Gmail, Slack, Notion, and hundreds of other apps, and the platform registers its Composio MCP server with Grok automatically (in `~/.grok/config.toml`).

## Custom image

To add your own tools, build on the clean base image, which ships Grok and the gateway with no managed integrations, the same pattern as `hermes-base`:

```dockerfile theme={null}
FROM ghcr.io/agent37-platform/grok-base:latest
```

See [Build a custom image](/docs/agents-api/custom-image).

## Troubleshooting

| Symptom                                                                                                | Fix                                                                                                                                                                                                                                                                                                     |
| ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| A turn fails with `auth_error`                                                                         | No xAI credential is present yet: set `XAI_API_KEY` in the instance env (recreate, or [update](/docs/agents-api/instances#update) with new env), or run `grok login --device-code` in the terminal.                                                                                                          |
| `GET /v1/health?agent=grok` reports `"healthy": false`                                                 | Same cause: the harness reports unhealthy until a key or login is present. `ok: true` alone only means the gateway is up.                                                                                                                                                                               |
| A first turn on a `session_id` you chose is rejected with `400 validation_error` (`param: session_id`) | Grok owns its session ids: a client cannot bring an unknown `session_id` on the first turn. Omit it to start a session, then reuse the id the response returns. Sessions you start in the terminal appear in `GET /v1/sessions?agent=grok` on their own.                                                |
| `PATCH /v1/sessions/{id}` returns `405 rename_unsupported`                                             | Grok stores no editable session title, so rename is not available on this harness.                                                                                                                                                                                                                      |
| A turn returns `503 agent_unavailable`                                                                 | The Grok binary is not present on this instance, so a turn that has to create or resolve a session cannot run. Unlike Hermes (which returns `200` with `status: "failed"`), Grok answers `503`. Recreate or [update](/docs/agents-api/instances#update) the instance to a template revision that ships Grok. |
