Grok Imagine Image Generation
xAI's image generation model, known for its unique creative style and high-quality image output.
Try it Online
Quick Start
python
from openai import OpenAI
client = OpenAI(
base_url="https://open.dieyuyun.com/v1",
api_key="YOUR_API_KEY"
)
response = client.images.generate(
model="grok-imagine",
prompt="An astronaut riding a giant koi fish through a nebula, surreal art style",
size="1024x1024",
n=1
)
print(response.data[0].url)Endpoint
| Item | Value |
|---|---|
| Method | POST |
| Path | /v1/images/generations |
| Base URL | https://open.dieyuyun.com |
| Protocol | OpenAI Images API |
Authentication
Bearer Token: Authorization: Bearer YOUR_API_KEY
Standard Request Fields
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| model | string | Yes | — | Model identifier: grok-imagine |
| prompt | string | Yes | — | Image description text |
| size | string | No | 1024x1024 | Image size |
| quality | string | No | standard | Generation quality: standard, hd |
| n | integer | No | 1 | Number of images to generate |
| response_format | string | No | url | Response format: url or b64_json |
Supported Sizes
| Size | Aspect Ratio | Description |
|---|---|---|
1024x1024 | 1:1 | Square |
1536x1024 | 3:2 | Landscape |
1024x1536 | 2:3 | Portrait |
Request Examples
bash
curl https://open.dieyuyun.com/v1/images/generations \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine",
"prompt": "An astronaut riding a giant koi fish through a nebula, surreal art style",
"size": "1024x1024",
"n": 1
}'python
from openai import OpenAI
client = OpenAI(
base_url="https://open.dieyuyun.com/v1",
api_key="YOUR_API_KEY"
)
response = client.images.generate(
model="grok-imagine",
prompt="An astronaut riding a giant koi fish through a nebula, surreal art style",
size="1024x1024",
n=1
)
print(response.data[0].url)javascript
import OpenAI from 'openai'
const client = new OpenAI({
baseURL: 'https://open.dieyuyun.com/v1',
apiKey: 'YOUR_API_KEY',
})
const response = await client.images.generate({
model: 'grok-imagine',
prompt: 'An astronaut riding a giant koi fish through a nebula, surreal art style',
size: '1024x1024',
n: 1,
})
console.log(response.data[0].url)Response Format
Success Response
json
{
"created": 1717000000,
"data": [
{
"url": "https://...",
"revised_prompt": "A surreal artwork of an astronaut in a white spacesuit riding a magnificent golden koi fish, swimming through a colorful nebula filled with purple and blue cosmic dust, stars twinkling in the background"
}
]
}| Field | Type | Description |
|---|---|---|
| created | integer | Unix timestamp |
| data | array | Array of generated results |
| data[].url | string | Image URL |
| data[].revised_prompt | string | The revised/optimized prompt used for generation |
Error Response
See Error Codes for details.
Best Practices
- Creative scenes: Grok Imagine excels at surreal, creative, and fantasy scenes, making it ideal for highly artistic image creation.
- Style specification: Explicitly specify the art style in your prompt (e.g., "surreal art style", "oil painting", "digital art") for more precise results.
- English prompts: Grok Imagine has better understanding of English prompts. Use English descriptions for the best results.
- High resolution: Use the
hdquality tier for finer image details.
Rate Limits
See Rate Limits for details.
Related Documentation
- GPT Image 2 - OpenAI image generation model
- Gemini Flash Image - Google image generation model
- Model List & Pricing - Browse available models and pricing
- Playground - Test image generation interactively