Skip to content

Grok Imagine Image Generation

xAI's image generation model, known for its unique creative style and high-quality image output.

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

ItemValue
MethodPOST
Path/v1/images/generations
Base URLhttps://open.dieyuyun.com
ProtocolOpenAI Images API

Authentication

Bearer Token: Authorization: Bearer YOUR_API_KEY

Standard Request Fields

FieldTypeRequiredDefaultDescription
modelstringYesModel identifier: grok-imagine
promptstringYesImage description text
sizestringNo1024x1024Image size
qualitystringNostandardGeneration quality: standard, hd
nintegerNo1Number of images to generate
response_formatstringNourlResponse format: url or b64_json

Supported Sizes

SizeAspect RatioDescription
1024x10241:1Square
1536x10243:2Landscape
1024x15362:3Portrait

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"
    }
  ]
}
FieldTypeDescription
createdintegerUnix timestamp
dataarrayArray of generated results
data[].urlstringImage URL
data[].revised_promptstringThe 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 hd quality tier for finer image details.

Rate Limits

See Rate Limits for details.