# Generations API

> Generate AI, web search, YouTube, X rewrite, X news, link, list and article text, run Beast Mode, and chat-edit tweets.

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

Generate posts with the same engine as the XBeast app. Generation saves a **history** post, so nothing is scheduled or published until you call the posts endpoints. Every call consumes credits.

> **Full-access keys only**
>
> Read-only keys cannot generate. Check remaining credits with GET /api/v1/workspace or GET /api/v1/credits.

### Generate text

**`POST /api/v1/generations/text`**

#### Body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| type | string | Yes | ai, search, youtube, x, x-news, link, list or article. |
| format | string | No | tweet, thread, long, article or same (same only for type x). Default tweet. |
| prompt | string | see note | Required for ai, search, list and article. |
| style_id | string | No | Owned or community writing style. |
| account_id | string | see note | Required for x-news; used for voice and media otherwise. |
| media_type | string | No | off, images, videos, mixed or ai. Default off. |
| video_url | string | see note | YouTube URL for type youtube. |
| tweet_url | string | see note | X post URL for type x. |
| news_query | string | see note | Search query for type x-news. |
| link_url | string | see note | Web page URL for type link. |
| ai_image_model | string | No | AI image model id. |
| ai_image_aspect_ratio | string | No | e.g. 1:1, 3:2, 2:3. |

**Generate a thread from a topic**

```bash
curl -X POST "https://xbeast.io/api/v1/generations/text" \
  -H "Authorization: Bearer xb_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "ai",
    "format": "thread",
    "prompt": "5 lessons from shipping a micro-SaaS",
    "media_type": "off"
  }'
```

Response: `{ data: { post, tweets, article_title, credits_used } }`. Use `post.id` with `POST /api/v1/posts/:id/queue` or `PATCH /api/v1/posts/:id` to schedule it.

### Beast Mode

**`POST /api/v1/generations/beast-mode`**

One tweet built from the account's profile and recent history. Body: `account_id` (required) and optional `prompt`. Costs 1 credit.

### Chat-edit tweets

**`POST /api/v1/generations/chat`**

#### Body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| tweets | array | Yes | Current { text, media_url? } tweets. |
| message | string | Yes | Instruction, e.g. “shorten and add a hook”. |
| conversation_history | array | No | Previous user/assistant messages. |
| post_id | string | No | Owned post to update when save is true. |
| save | boolean | No | Persist the edited tweets into post_id. |

Returns the assistant response, annotations, edited `tweets`, media results and `credits_used`. Sent posts cannot be edited.

## Credits

- Text generation costs 1–10 credits depending on the source, format and media.
- Beast Mode costs 1 credit.
- Chat editing costs at least 1 credit, plus extra for edits and media.
- [GET /api/v1/workspace](https://xbeast.io/docs/api-workspace.md) shows available credits and the reset date.

## Related

- [Generate and edit images](https://xbeast.io/docs/api-images.md)
- [Create, schedule and publish the generated post](https://xbeast.io/docs/api-posts.md)
- [Run generation from an AI agent over MCP](https://xbeast.io/docs/mcp.md)
