# Grok 4.7 API Complete API reference for the Grok 4.7 LLM model powered by xAI. ## Model Variants This API supports one model variant: | Model | ID | Description | |-------|----|-------------| | **Grok 4.7** | `grok-4.7` | Text generation and image understanding | ## Quick Comparison | Feature | Grok 4.7 | |---------|----------| | Text input | Optional | | Image input | Optional | | File input | Not supported ❌ | | Output | Text | | Context window | 500,000 tokens shared by input and output | | Tool calling | Supported ✅ | | Streaming response | Optional (SSE) | | `max_tokens` | Optional | | `reasoning_effort` | Optional | ## Grok 4.7 ### Endpoint ```http POST /api/v1/chat/completions ``` ### Request Parameters #### Required | Parameter | Type | Description | |-----------|------|-------------| | `model` | string | Must be `"grok-4.7"` | | `messages` | array | Non-empty array of ordered messages. Each message contains `role` and `content`. Use a text string or an array of `text` and `image_url` content blocks. | #### Message Support | Field | Text | File | Image | |-------|------|------|-------| | `messages` | Optional | Not supported ❌ | Optional | #### Optional | Parameter | Type | Range | Description | |-----------|------|-------|-------------| | `max_tokens` | integer | `> 0` | Maximum output tokens. | | `stream` | boolean | `true`, `false` | `true` for SSE, `false` for a single JSON response. Defaults to `false`. | | `reasoning_effort` | string | `low`, `medium`, `high`, `xhigh` | Reasoning effort. Defaults to `high`. | ### Example Request ```javascript const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Accept': 'text/event-stream', 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'grok-4.7', messages: [ { role: 'user', content: 'Explain how a browser caches an image in two sentences.' } ], stream: true, max_tokens: 2048, reasoning_effort: 'medium' }) }); ``` ## Response Format Grok 4.7 returns OpenAI-compatible completion responses. With `stream: true`, the response is Server-Sent Events. With `stream: false` or when `stream` is omitted, the response is a single JSON object. ### Successful Response ```text data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.7","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.7","choices":[{"index":0,"delta":{"reasoning_content":"Explain cache reuse."},"finish_reason":null}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.7","choices":[{"index":0,"delta":{"content":"The browser saves a copy of the image. It reuses the copy while it is fresh."},"finish_reason":null}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.7","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]} data: [DONE] ``` ### Error Response ```text data: {"error":{"message":"API requests too frequent, exceeding rate limit","type":"rate_limit_error","code":"1302","param":null}} ``` ## Best Practices 1. **Use structured messages** to send conversation history through `messages[]`. 2. **Attach images in message content** by adding an `image_url` block to `messages[].content`. 3. **Consume SSE events** by appending `choices[0].delta.content` and treating `data: [DONE]` as the end of the stream.