# Images API

> Generate and edit AI images, recommend a stock search query or image prompt, and search stock media.

Source: https://xbeast.io/docs/api-images

Generate AI images, edit an existing image, ask for a media recommendation, or search stock libraries. Every image endpoint except search consumes credits. Upload your own files with the [Media API](https://xbeast.io/docs/api-media.md).

### Generate an AI image

**`POST /api/v1/images`**

#### Body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| prompt | string | Yes | What the image should show. |
| model | string | No | AI image model id. |
| aspect_ratio | string | No | e.g. 1:1, 3:2, 2:3. |

```bash
curl -X POST "https://xbeast.io/api/v1/images" \
  -H "Authorization: Bearer xb_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "prompt": "Minimal desk setup at golden hour", "aspect_ratio": "3:2" }'
```

Response: `{ data: { image_url, credits_used, model, aspect_ratio } }`. Pass `image_url` as `tweets[].media_url` on a post.

### Edit an image

**`POST /api/v1/images/edit`**

Body: `image_url` (public HTTPS URL) and `prompt`. Costs 5 credits.

### Recommend media

**`POST /api/v1/images/recommend`**

#### Body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| tweet | string | Yes | Tweet text to find media for. |
| kind | string | No | search_query (stock search terms) or image_prompt (AI prompt). Default search_query. |

### Search stock media

**`GET /api/v1/images/search`**

#### Query

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| query | string | Yes | Search terms. |
| source | string | No | unsplash, pixabay, lexica or yandex. Default unsplash. |
| limit | number | No | 1–100. Default 10. |

```bash
curl "https://xbeast.io/api/v1/images/search?query=coffee&source=unsplash&limit=5" \
  -H "Authorization: Bearer xb_live_YOUR_KEY"
```

## Media tips

- Media URLs must be public HTTPS URLs. Private/LAN/metadata hosts are rejected.
- Image limits: 5 MB. Video limits: 100 MB.
- To store media permanently, use [POST /media](https://xbeast.io/docs/api-media.md) or `POST /media/from-url`.

## Related

- [Generate tweet text](https://xbeast.io/docs/api-generations.md)
- [Attach media to a post](https://xbeast.io/docs/api-posts.md)
- [Generate images from an AI agent over MCP](https://xbeast.io/docs/mcp.md)
