# AI Content Drafts

RankWiz can generate AI-powered content rewrite drafts for pages that lost traffic. This feature uses OpenAI's API with a "Bring Your Own Key" (BYOK) model — you provide your own OpenAI API key and pay OpenAI directly for usage.

## Setup

Before generating drafts, you need to add your OpenAI API key:

1. Go to **Settings > AI** (from the user menu)
2. Enter your OpenAI API key (starts with `sk-`)
3. Click **Save**
4. Click **Test Key** to validate it works

See [AI Settings](../settings/ai-settings.md) for details on key management and validation.

## Generating a Single Draft

1. Navigate to the [Recommendations](recommendations.md) page
2. Find a **Content Rewrite** recommendation
3. Click **Generate Draft**
4. The draft is generated in a few seconds and appears inline

## Generating Drafts in Batch

1. On the Recommendations page, click **Generate All Drafts**
2. Confirm in the dialog — this generates drafts for all content rewrite recommendations
3. A progress bar shows completion (e.g., "12/25 drafts completed")
4. You can navigate away — the job runs in the background

**Maximum batch size:** 50 recommendations per batch.

## Viewing Drafts

Each generated draft shows:

- **Original content** — the current WordPress page content (left side)
- **AI rewrite** — the generated replacement content (right side)
- **Token usage** — prompt and completion tokens consumed
- **Model** — which OpenAI model was used

Drafts are for review purposes. RankWiz does not automatically publish rewrites to your WordPress site.

## Supported Models

| Model | Description |
|-------|-------------|
| **gpt-4o-mini** (default) | Fast, cost-effective, good for most content |
| **gpt-4o** | More capable, better for complex content |
| **gpt-4-turbo** | High capability with larger context window |

You can change the model per site in [Site AI Settings](../settings/ai-settings.md).

## Per-Site Configuration

Each site can have its own AI settings. Go to your site's **Settings > AI** page to customize:

| Setting | Default | Range | Description |
|---------|---------|-------|-------------|
| **Model** | gpt-4o-mini | gpt-4o, gpt-4o-mini, gpt-4-turbo | More capable models cost more |
| **Temperature** | 0.3 | 0.0 - 1.2 | Lower = more focused; higher = more creative |
| **Top P** | 1.0 | 0.1 - 1.0 | Controls output diversity |
| **Max output tokens** | 1,200 | 200 - 4,000 | Maximum length of generated content |
| **Custom instructions** | (none) | Up to 2,000 characters | Additional guidelines for the AI (e.g., tone, audience, keywords to include) |

## Limits

| Resource | Limit |
|----------|-------|
| Drafts per month | 50 (resets on the 1st of each month) |
| Concurrent AI jobs | 2 |
| Batch size | 50 recommendations per job |

The limits bar in the sidebar shows your current draft usage (e.g., "12/50 drafts").

## Cost

RankWiz does not charge for AI features. You pay OpenAI directly based on your API usage. Token consumption depends on the model chosen and the length of the original content.

Each draft shows the tokens used so you can monitor spending.

## Troubleshooting

**"Please add and validate an AI API key in Settings"**
- Go to Settings > AI and add your OpenAI key

**"Your AI API key is invalid"**
- Your key may have been revoked or expired — generate a new one at [platform.openai.com](https://platform.openai.com)

**"Monthly draft limit exceeded"**
- You've reached 50 drafts this month. The limit resets on the 1st of next month.

**"AI rate limit reached"**
- OpenAI is throttling your API key. Wait a few minutes and try again.

**Draft quality is poor**
- Try adjusting the temperature (lower for more focused output)
- Add custom instructions to guide the AI (e.g., "Write for a technical audience" or "Include the keyword 'example' naturally")
- Try a more capable model (gpt-4o instead of gpt-4o-mini)
