# Create Grok Image

Generate an image with a Grok image model.

- Source: https://www.unifyllm.com/docs/api-reference/create-grok-image/
- Language: en

## Endpoint

```http
POST https://api.unifyllm.top/v1/images/generations
```

Use the authentication and headers shown in the request examples. Content-Type: application/json

## Parameters

| Field | Location | Type | Required | Description | Allowed values | Example |
| --- | --- | --- | --- | --- | --- | --- |
| prompt | body | string | yes | Text instruction describing the requested output. |  |  |
| aspect_ratio | body | string | no | Aspect ratio of the generated media. | 1:1, 3:4, 4:3, 9:16, 16:9, 2:3, 3:2, 9:19.5, 19.5:9, 9:20, 20:9, 1:2, 2:1, auto | auto |
| model | body | string | yes | Model identifier used for this request. |  |  |
| n | body | integer | no | Number of results to generate. |  |  |
| resolution | body | string | no | Resolution of the generated media. | 1k, 2k |  |
| response_format | body | string | no | Format used to return generated media. | url, b64_json | url |

## Example 1

```json
{
  "model": "grok-imagine-image-quality",
  "prompt": "A collage of London landmarks in a stenciled street‑art style"
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1/images/generations' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "grok-imagine-image-quality",
  "prompt": "A collage of London landmarks in a stenciled street‑art style"
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/images/generations", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "model": "grok-imagine-image-quality",
    "prompt": "A collage of London landmarks in a stenciled street‑art style"
  }),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1/images/generations",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"model\": \"grok-imagine-image-quality\",\n  \"prompt\": \"A collage of London landmarks in a stenciled street‑art style\"\n}")
)
response.raise_for_status()
print(response.json())
```

## Response examples

### Example 1 — HTTP 200

```json
{
  "data": [
    {
      "url": "https://imgen.x.ai/xai-imgen/xai-tmp-imgen-a73bae6f-5a65-4bec-9ffb-8220caa3fa61.jpeg",
      "mime_type": "image/jpeg",
      "revised_prompt": ""
    }
  ],
  "usage": {
    "cost_in_usd_ticks": 200000000
  }
}
```
