# Agent Image Generation

Use Codex, Claude Code, or Cursor to generate and save images through Kaien API.

You can use an agent to generate images without writing an API integration by installing the Kaien GPT Image 2 skill and then describing the image you need.

## What you need

- A Kaien API key with access to an image model.
- Codex, Claude Code, Cursor, or another supported agent tool.
- A local project directory where generated images can be saved.

## Install the skill

Choose the command that matches your agent:

```bash
npx skills add https://kaienapi.com/docs/en/skill.md -g
```

After installation, restart the agent if it does not discover the new skill automatically.

## Configure the API key

When the agent asks for a key, provide it through the tool's supported secret or environment-variable mechanism. Do not paste a real key into a committed file.

A typical environment setup is:

```bash

```

## Ask for an image

Give the agent a concrete request:

```text
Create a square product image of a silver camera on a clean studio background and save the final PNG in ./output/camera.png.
```

The agent should select a model, create an asynchronous image job, poll its status, and save the result locally.

## Reference images

Give the agent a public image URL or a local path when the installed skill supports local upload. Describe what each reference image controls:

```text
Use the first image for the product shape and the second image for the background style. Save a 4:5 PNG in ./output.
```

## When a task fails

Ask the agent to inspect the original error response and task ID before retrying. A temporary polling error should not create a duplicate job. Common causes include an unavailable model, an expired reference URL, an unsupported size, or a missing API key.

## Continue reading

- [Image Generation](/docs/en/images-video/images)
- [GPT Image 2](/docs/en/images-video/gpt-image-2)
- [Copy as Markdown](/docs/en/ai/copy-as-markdown)
