> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dreamlayer.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Text-to-image

> Submit a managed text-to-image operation and follow its durable event stream.

# Text-to-image

## What this lets you do

Generate one image from a text prompt through a durable managed execution.

## What you need

* A server-side DreamLayer test or live key
* A unique idempotency key for this logical turn
* One available live credit when using a live key

## Steps

### 1. Send the request

```bash theme={null}
curl --no-buffer https://api.dreamlayer.io/v1/execute \
  -H "Authorization: Bearer $DREAMLAYER_API_KEY" \
  -H "DreamLayer-Version: 1" \
  -H "Idempotency-Key: greenhouse-text-001" \
  -H "Accept: text/event-stream" \
  -H "Content-Type: application/json" \
  -d '{"prompt":"A glass greenhouse at dusk","aspect_ratio":"1:1","max_credits":1}'
```

### 2. Check the request schema

```json theme={null}
{
  "prompt": "A glass greenhouse at dusk",
  "aspect_ratio": "1:1",
  "max_credits": 1
}
```

`prompt` is required and accepts 1 to 4,000 characters. `max_credits` is fixed at `1` in V1.

### 3. Read the result

A successful stream emits one `asset` event and ends with `done` status `completed`. The asset object contains an opaque ID, owned download URL, PNG content type, width, and height.

One completed text-to-image operation uses one live credit.

## Confirm it worked

The stream emits one `asset` and ends with `done` status `completed`. The live credit changes from reserved to settled only after delivery.

## Common errors

* `400`: fix a missing or out-of-range request field.
* `402`: add credits or switch to a test key.
* `409`: do not reuse the idempotency key for different request bytes.

## Troubleshooting

If the connection closes, read canonical execution state before retrying. Reuse the same idempotency key only for the same logical request.

## Next steps

* [Resume event streams](/agent-api/jobs-and-events)
* [Run image-to-image](/agent-api/image-to-image)
