# Grok 4.7 API

> xAI's Grok 4.7 — their frontier model for coding, agentic tasks and knowledge work, with a 500K-token context window.

- **Provider**: Grok
- **Model id**: `grok-4-7`
- **Modality**: text
- **Price**: 75–225 credits

## Overview

Grok 4.7 is called in ONE step: POST your request and the answer comes back in the same response, in `text`. There is no task to poll.

## Authentication

All requests require a Bearer Token in the request header:

```
Authorization: Bearer YOUR_API_KEY
```

## Create Task

`POST https://you.bot/api/v1/generate`

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| modelId | string | Yes | Model id: `grok-4-7` |
| input | object | Yes | Input parameters object (see below) |
| callbackUrl | string | No | https URL we POST the finished task to. Signed with `X-Webhook-Signature` once you create a webhook signing key in Dashboard → Settings |

### input object parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| prompt | string | Yes | Text value (example: Explain why a queue with plenty of spare capacity can still develop a growing backlog, using one everyday analogy and one worked example with numbers. Then… — full value in the request example) |
| structured_outputs | boolean | No | Generate structured outputs (true/false) (example: false) |
| stream | boolean | No | Send true to receive the reply as an event stream (Content-Type: text/event-stream). Omit it and you get a single JSON response — streaming is opt-in on this endpoint. (true/false) (example: true) |
| images | string[] | No | Up to 4 images per message — JPEG, PNG, GIF or WebP, 5 MB each. Send each one as a data: URL or an https URL. Images are billed as input tokens. (image URL) |
| web_search | boolean | No | Web search feeds the results back as input tokens, so a searched turn typically costs many times a normal turn (measured: 6–87×). Billed per token as usual — nothing extra per search. (true/false) (example: false) |
| system | string | No | System instruction for the model. Defaults to "You are Grok 4.7, developed by Grok." when omitted. |
| messages | array | No | A conversation instead of a single `prompt`: an array of { "role", "content" } objects, where role is user, assistant or system. Send the whole conversation — we do not limit how many messages it has, and we do not drop old ones; the model's context window is the limit. Send `prompt` or `messages`, not both. Do not flatten a conversation into one prompt with "User:" / "Assistant:" labels — the model reads that as a single message, and a model using web search then searches for the whole block instead of your question. |

### Request example

```json
{
  "modelId": "grok-4-7",
  "input": {
    "prompt": "Explain why a queue with plenty of spare capacity can still develop a growing backlog, using one everyday analogy and one worked example with numbers. Then give the two measurements that tell you which of the two causes you are looking at. Under 250 words, no formulas heavier than multiplication.",
    "structured_outputs": false,
    "stream": false,
    "images": [
      "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVR4nGP8z4AATAxIHFQeMg8OAgB1yQIDpk8YwwAAAABJRU5ErkJggg=="
    ],
    "web_search": false
  }
}
```

### Response example

```json
{
  "model": "grok-4-7",
  "text": "…",
  "creditsCharged": 0.13,
  "usage": {
    "inputTokens": 1400,
    "outputTokens": 120,
    "cachedInputTokens": 0,
    "cacheWriteTokens": 0
  }
}
```

## Query Task

`GET https://you.bot/api/v1/task/{taskId}?model=grok-4-7`

When `state` is `success`, the output is in `resultUrls`: `{ "text": "…" }`. (Text models return inline in the create response.)

## Error Codes

| Code | Description |
|------|-------------|
| 200 | Request successful |
| 400 | Invalid request parameters |
| 401 | Authentication failed — check API Key |
| 402 | Insufficient account balance |
| 403 | IP not allowed for this key, or the key is restricted to other models |
| 404 | Task not found, or it has expired |
| 409 | Duplicate request — an identical submit arrived moments ago. Nothing was charged; retry is safe |
| 413 | Payload too large — see the character and file-size limits for this model |
| 429 | Rate limit exceeded — retry after the Retry-After header |
| 500 | Internal server error |
| 504 | Upstream timed out — nothing was delivered; retry is safe |
| 400 · too_many_images | More than 4 image(s) attached to one message |
| 400 · image_too_large | An attached image is over the 5 MB per-image limit |
| 400 · image_format_unsupported | Unsupported image format — accepted: image/jpeg, image/png, image/gif, image/webp (read from the file's own bytes, not the declared type) |
| 400 · image_unreadable | An attached image, or its pixel size, could not be read |
| 400 · capability_not_supported | A capability was requested (e.g. `web_search: true`) that this model does not offer — refused, nothing charged, rather than answered without it |
| 422 · image_not_received | The model answered that it did not receive the attached image — the reply is not usable, so nothing is charged. Retry |
| 400 · unknown_image_field | Images were sent under a different key (input_urls, image_urls, imageUrl …). This model takes them as `images` |
| 400 · image_placement_unsupported | An image is attached to a message that is not sent to the model as an image (a system message, an assistant message or a tool result). Attach images to a user message — they are refused rather than dropped |
