Grok Imagine Image (Quality) Serverless API

Photorealistic text-to-image with legible typography and 2K detail.

 1import requests
 2import json
 3
 4url = "https://api.segmind.com/v1/grok-imagine-image-quality"
 5headers = {
 6    "x-api-key": "YOUR_API_KEY",
 7    "Content-Type": "application/json"
 8}
 9
10data = {
11    "prompt": "Macro photograph of a hummingbird hovering beside a red hibiscus flower, iridescent emerald feathers, wings frozen mid-beat, tiny nectar droplets suspended in the air, soft bokeh garden background, golden morning light, ultra-detailed, photorealistic",
12    "aspect_ratio": "16:9",
13    "resolution": "2k",
14    "n": 1,
15    "output_format": "jpeg"
16}
17
18response = requests.post(url, headers=headers, json=data)
19
20if response.status_code == 200:
21    result = response.json()
22    print(json.dumps(result, indent=2))
23else:
24    print(f"Error: {response.status_code}")
25    print(response.text)

API Endpoint

POSThttps://api.segmind.com/v1/grok-imagine-image-quality

Parameters

promptrequired
string

Text description of the image. Detailed photographic prompts with lighting cues work best.

Default: "Macro photograph of a hummingbird hovering beside a red hibiscus flower, iridescent emerald feathers, wings frozen mid-beat, tiny nectar droplets suspended in the air, soft bokeh garden background, golden morning light, ultra-detailed, photorealistic"
aspect_ratiooptional
string

Output aspect ratio, 14 options. Use 16:9 landscape, 9:16 social, 1:1 square.

Default: "16:9"
Allowed values (14 total):
"1:1""3:4""4:3""9:16""16:9""2:3""3:2""9:19.5""19.5:9""9:20"+4 more
noptional
integer

Number of images per request, 1-4. Each image is billed separately.

Default: 1Range: 1 - 4
output_formatoptional
string

Output file format. jpeg default, png for lossless, webp for web delivery.

Default: "jpeg"
Allowed values :
"jpeg""png""webp"
resolutionoptional
string

Output resolution. Use 2k for final renders, 1k for fast iteration.

Default: "2k"
Allowed values :
"1k""2k"

Response Type

Returns: Text/JSON

Common Error Codes

The API returns standard HTTP status codes. Detailed error messages are provided in the response body.

400

Bad Request

Invalid parameters or request format

401

Unauthorized

Missing or invalid API key

403

Forbidden

Insufficient permissions

404

Not Found

Model or endpoint not found

406

Insufficient Credits

Not enough credits to process request

429

Rate Limited

Too many requests

500

Server Error

Internal server error

502

Bad Gateway

Service temporarily unavailable

504

Timeout

Request timed out