Images and video
Images
Text to image, or edit an existing image from a URL.
Image generation is at full capacity
We aren't taking new users for this endpoint right now. Contact us to join the waitlist and we'll let you know when a spot opens.
POST
/v1/imagesRequest body
| Field | Type | Description |
|---|---|---|
promptRequired | string | What to generate or how to edit the source. Up to 4,000 characters. |
image_urlOptional | string (URL) | An http or https image to edit. Leave it out for text to image. |
aspect_ratioOptional | string | One of 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, 9:21. Default 2:3. |
resolutionOptional | string | 512 (about 448×640), 1k (about 832×1280, default) or 2k (about 1344×2048). Sizes shown for 2:3. |
width / heightOptional | integer | Exact size instead of aspect_ratio and resolution. Send both, multiples of 64 between 256 and 2048, at most 4.2 megapixels. |
num_outputsOptional | integer | How many images to generate, 1 to 4. Default 1. |
output_formatOptional | string | webp (default, smallest), jpeg or png. |
output_qualityOptional | integer | Quality for webp and jpeg, 1 to 100. Default 90. |
webhook_urlOptional | string (URL) | An https URL to notify when this job finishes. See Webhooks. |
Example
curl
curl -X POST https://api.sweetrouter.com/v1/images \
-H "Authorization: Bearer $SWEETROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "a red apple on a wooden table, soft window light",
"aspect_ratio": "2:3",
"resolution": "1k",
"num_outputs": 2,
"output_format": "webp"
}'response
{
"id": "cmg8x2k0d0001",
"object": "job",
"type": "image",
"status": "queued",
"num_outputs": 2,
"outputs": [
{ "index": 0, "status": "pending", "url": null },
{ "index": 1, "status": "pending", "url": null }
],
"cost_usd": "0.10",
"expires_at": null
}The call returns the job right away with status queued. Poll GET /v1/jobs/:id or use a webhook, then download each outputs[].url.
Billing
Each requested image is charged when the job is created. If some outputs fail, they're refunded automatically. See Pricing.
Safe retries
Send an Idempotency-Key header. Retrying with the same key returns the original job instead of creating and charging a new one.
curl
curl -X POST https://api.sweetrouter.com/v1/images \
-H "Authorization: Bearer $SWEETROUTER_API_KEY" \
-H "Idempotency-Key: order-8812-hero" \
-H "Content-Type: application/json" \
-d '{"prompt": "a lighthouse at dusk"}'