Generate images from text prompts using the OpenAI SDK client.images.generate() method.
from openai import OpenAI
client = OpenAI(api_key='sk-snap-xxx', base_url='https://api.snapapi.ai/v1')| Model | Description | Credit |
|---|---|---|
snapapi/z-image | Text to Image (Z-Image) | 9 |
snapapi/qwen-image | Text to Image (Qwen) | 9 |
Python:
result = client.images.generate(
model='snapapi/z-image',
prompt='a cute cat sitting on a cloud',
size='1024x1024'
)
print(result.data[0].url)Node.js:
const result = await client.images.generate({
model: 'snapapi/z-image',
prompt: 'a cute cat sitting on a cloud',
size: '1024x1024'
});
console.log(result.data[0].url);size is auto-converted to aspect_ratio:
- 1024x1024 → 1:1
- 1792x1024 → 16:9
- 1024x1792 → 9:16
- 1536x1024 → 3:2
- 1024x1536 → 2:3
/v1/images/generations (OpenAI SDK)Authorization — This endpoint requires an API key. Pass it in the api-key header on every request. See the quickstart
Image generated successfullySingleImageResponse
| Name | Type | Description |
|---|---|---|
created | integer | Unix timestamp of when the response was created |
data | object[] | |
url | string | URL to download the result image |
curl -X POST "https://api.snapapi.ai/v1/images/generations (OpenAI SDK)" \
-H "api-key: YOUR_API_KEY"{
"created": 1745827200,
"data": [
{
"url": "https://outputs.snapapi.ai/outputs/abc123.png"
}
]
}