POST
/
images
/
generations
Create image
curl --request POST \
  --url https://api.xtrix.workers.dev/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "dall-e-3",
  "prompt": "<string>"
}'
{
  "created": 123,
  "data": [
    {
      "b64_json": "<string>",
      "revised_prompt": "<string>"
    }
  ]
}

Request Body

model
string
required
Model to use (e.g., dall-e-3).
prompt
string
required
Text description of the image to generate.
n
integer
default:1
Number of images to generate (1-10).
size
string
default:"1024x1024"
Image size. Options: 256x256, 512x512, 1024x1024, 1792x1024, 1024x1792.

Example Request

curl https://api.xtrix.workers.dev/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "dall-e-3",
    "prompt": "A serene landscape with mountains",
    "n": 1,
    "size": "1024x1024"
  }'

Response

{
  "created": 1677858242,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==",
      "revised_prompt": "A serene landscape featuring majestic mountains"
    }
  ]
}

Working with Base64 Images

The API returns images as base64-encoded strings. To display in HTML:
<img src="data:image/png;base64,{b64_json_value}" alt="Generated image" />
To save as a file in Python:
import base64
from PIL import Image
import io

image_data = base64.b64decode(response.data[0].b64_json)
image = Image.open(io.BytesIO(image_data))
image.save("generated_image.png")

Authorizations

Authorization
string
header
required

API key authentication

Body

application/json

Response

200
application/json

Successful response

The response is of type object.