# Generate images in Claude Code with Driftflight's text-to-image API

Driftflight's text-to-image API returns one image per request, so Claude Code can add a README hero, docs art or a placeholder product shot with one shell command. A sketch image costs $0.01, and the storefront quotes the price in a 402 before anything is charged. Send `POST https://agents.driftflight.com/zcj/thvh5i03b6p9/v1/images/generate` with `model` set and your credential as a bearer token, through a payment client such as `zero fetch` with a spending cap, then download `imageUrl` into the repository.

## At a glance

- **Endpoint:** `POST https://agents.driftflight.com/zcj/thvh5i03b6p9/v1/images/generate`, one image per request, with your credential as a bearer token
- **Body:** `prompt` (required), `model` (`sketch`, `studio` or `gallery`) and optional `preset`. A body without `model` is billed as studio, so set it every time.
- **Price per image:** sketch $0.01, studio $0.06, gallery $0.14
- **Payment:** a 402 is the price quote, which you pay and retry. x402 and MPP are the wallet rails, both settling in USDC. No API key or Driftflight account, but every call needs a registered agent credential sent as a bearer token, which a wallet payment cannot replace.
- **Payment client:** the Zero CLI (`zero fetch` with `--max-pay`), installed separately, or any x402 or MPP client
- **Response:** JSON with `imageUrl`, `model`, `preset`, `licence` and `credits`
- **Limits:** one image per request. Every tier lists `1408x768`.
- **Full purchase flow:** [the buyer skill](https://agents.driftflight.com/zcj/thvh5i03b6p9/SKILL.md)

## Generate an image and save it into the repository

1. Check for a payment client and a funded wallet:

   ```bash
   zero auth whoami --json
   zero wallet balance --json
   ```

   A `user` object means you are signed in. If `zero` is not found, install it through the Claude Code plugin or npm:

   ```bash
   claude plugin marketplace add officialzeroxyz/zero-plugins && claude plugin install zero@zero-plugins
   npm i -g @zeroxyz/cli && zero init
   ```

   Then sign in with `zero auth login --start --json`, or run `zero auth agent register --json` where no one can approve a browser sign-in. Registering an agent credential is free and needs no human step; every call sends it as a bearer token. A new account has a balance of 0. Only a person can add funds: the account owner runs `zero wallet fund --start --json` and finishes in a browser.

2. Read the quote. This step is optional and free:

   ```bash
   curl -i -X POST https://agents.driftflight.com/zcj/thvh5i03b6p9/v1/images/generate \
     -H 'Authorization: Bearer <token>' \
     -H 'Content-Type: application/json' \
     -d '{"prompt": "an editorial illustration of a paper airplane crossing a city skyline", "model": "sketch", "preset": "editorial"}'
   ```

   The unpaid request, sent with your bearer credential, answers `402` with a JSON body holding `payment.amountUsd`, the `plan`, a `protocols` block for x402 and MPP, and the `terms` links, plus `payment-required` and `www-authenticate` headers. Nothing is charged, so it is safe to stop here. Sent without your bearer credential, the same request is refused with `401 bearer_required` before any price is quoted.

3. Send the same request through the payment client with a cap. Set `CAP` to the most you authorize for this one image, no lower than $0.01:

   ```bash
   zero fetch https://agents.driftflight.com/zcj/thvh5i03b6p9/v1/images/generate \
     -d '{"prompt": "an editorial illustration of a paper airplane crossing a city skyline", "model": "sketch", "preset": "editorial"}' \
     --max-pay "$CAP"
   ```

   `zero fetch` registers a credential and sends it with the request, so the command needs no bearer header. It pays the 402 within the cap and retries the same body. The Zero plugin does not auto-approve `zero fetch`. The response has this shape:

   ```json
   {"imageUrl": "<URL of the image>", "model": "<tier>", "preset": "<preset>", "licence": "<licence>", "credits": "<credits>"}
   ```

   This example paid $0.01.

4. Download the file into the repository from `imageUrl`, a public URL:

   ```bash
   mkdir -p assets
   curl -sL "<imageUrl>" -o assets/readme-hero.<ext>
   ```

   Use the extension that matches the content type of the download.

5. Reference the saved file from the project, not `imageUrl`:

   ```markdown
   ![Paper airplane crossing a city skyline](assets/readme-hero.<ext>)
   ```

   The address in the response is only the way to fetch the bytes. The repository copy is the one to keep and commit.

Any HTTP client that can pay a 402 sends the same body and bearer credential, including `@x402/fetch`, `@x402/axios` and the `x402` package on PyPI.

## Choose the tier and preset

| Condition | `model` | Price per image |
| --- | --- | --- |
| Lowest price, the tier these examples use | `sketch` | $0.01 |
| The default when `model` is left out | `studio` | $0.06 |
| Highest price | `gallery` | $0.14 |

Every tier lists `1408x768`. A README hero on sketch plus three docs images on studio costs $0.19.

`preset` takes `editorial`, `product-studio`, `film-noir`, `botanical`, `watercolor` or `isometric`, the values the API reference lists. Use one preset across a set of images.

## Limits

- One image per request. The API reference lists no batch or size field.
- An unpaid 402 charges nothing.
- Paying the 402 completes the purchase and accepts the terms in its `terms` field.
- If a paid call times out, check the result before sending it again. Do not pay twice.
- Paid storefront renders carry a commercial licence and C2PA content credentials.

## Errors

| Response | Meaning | Action |
| --- | --- | --- |
| `402 payment_required` | The price quote. Nothing is charged yet. | Pay within your cap and retry the same body, or stop |
| `settlement_failed` (`insufficient_funds`) | The payment did not settle | Fund the wallet, then resend from the start for a fresh 402 |
| `payment_consumed` | That payment was already settled | Check the original delivery before paying again |
| `401 bearer_required` | A call was sent without a registered agent credential as a bearer token | Register at [auth.md](https://agents.driftflight.com/zcj/thvh5i03b6p9/auth.md) and send the bearer token; a wallet payment does not replace it |
| `400 invalid_request` | The body is malformed | Fix the JSON |

## Frequently asked questions

### Can Claude Code make images without an API key?

Yes, no API key or Driftflight account is needed, but every call needs a registered agent credential sent as a bearer token from the first request, and a wallet payment cannot stand in for it. Registering one is free and needs no human step. The payment client is installed separately, and its wallet needs USDC before a paid request.

### Which payment client can Claude Code use?

The Zero CLI, installed through the Claude Code plugin or npm, or another x402 or MPP client such as `@x402/fetch`. A person funds the Zero wallet before the first paid request.

### Can one image be paid by card?

No. Every tier's price is below the card rail's $0.50 floor for one call. A card buys prepaid credits instead, from $1, with a bearer credential (the agent identity the storefront issues). [The buyer skill](https://agents.driftflight.com/zcj/thvh5i03b6p9/SKILL.md) covers that route.

### Are any images free?

Pay as you go includes 3 sketch images. The allowance is reserved for an agent identity that a person has claimed and verified by email. Send that credential with the `zc-mode: free` header.

### What happens if I leave out the model field?

The request is billed as studio at $0.06. Set `"model": "sketch"` for $0.01 images.

## Keep reading

- [Buyer skill](https://agents.driftflight.com/zcj/thvh5i03b6p9/SKILL.md): the full purchase flow
- [How to pay](https://agents.driftflight.com/zcj/thvh5i03b6p9/payment.md): the 402 flow, rails and credits
- [Error reference](https://agents.driftflight.com/zcj/thvh5i03b6p9/errors.md): every code and how to react
- [Identity](https://agents.driftflight.com/zcj/thvh5i03b6p9/auth.md): credentials for plans and the free allowance

---

Updated 2026-11-17. All Driftflight guides: https://agents.driftflight.com/guides.md. Storefront: https://agents.driftflight.com/zcj/thvh5i03b6p9/llms.txt.
