> ## Documentation Index
> Fetch the complete documentation index at: https://krastieai.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Content generation endpoints

> Generate visibility-optimized content, score SEO, and improve pages via the REST API.

Base path: `/v1/ai/generate`

These endpoints support the content side of your AI visibility workflow — creating and improving pages that help AI models mention and cite your brand. For visibility reporting, see [AI visibility endpoints](/api-reference/ai-visibility).

## POST `/text`

Generate content from a prompt. Use this to create pages targeting prompts from your visibility report.

**Body:**

| Field | Type | Required | Description |
| - | - | - | - |
| `text` | string | Yes | Prompt / user message |
| `model` | string | Yes | Model ID (OpenAI, Anthropic, or Gemini family) |
| `systemPrompt` | string | No | Custom system instructions |
| `brandVoiceId` | string | No | Apply a saved brand voice |
| `brandVoice` | boolean | No | Enable brand voice context |
| `file` | string | No | Attachment reference for context |
| `useWorker` | boolean | No | Queue async job instead of synchronous response |
| `jobType` | string | No | Worker job name when `useWorker` is true (default: `ai_tool_content`) |
| `options` | object | No | Extra options passed to the worker |

**Sync response (200):**

```json theme={null}
{
  "message": "Generated AI successfully.",
  "data": "Generated text content..."
}
```

**Async response (202)** when `useWorker: true`:

```json theme={null}
{
  "message": "Content generation queued",
  "jobId": "12345"
}
```

**Example:**

```bash theme={null}
curl -X POST https://api.krastie.ai/v1/ai/generate/text \
  -H "Content-Type: application/json" \
  -H "api-key: krastie_YOUR_KEY" \
  -d '{
    "text": "Write an FAQ page answering: What are the best tools for AI search visibility?",
    "model": "gpt-4o",
    "brandVoiceId": "BRAND_VOICE_ID"
  }'
```

## POST `/chat`

Conversational AI with workspace visibility context. Enable `useWorkspaceContext` to include your latest visibility scores, traffic data, and documents.

**Body:**

| Field | Type | Required | Description |
| - | - | - | - |
| `text` | string | Yes | User message |
| `model` | string | Yes | Model ID |
| `sessionId` | string | No | Existing chat session (created if omitted) |
| `systemPrompt` | string | No | Custom system prompt |
| `useWorkspaceContext` | boolean | No | Include visibility and workspace data (default: `true`) |
| `brandVoiceId` | string | No | Brand voice context |
| `webpageContext` | string | No | Raw page text for context |
| `webSearch` | boolean | No | Enable web search (OpenAI models only) |

**Response (200):**

```json theme={null}
{
  "message": "Generated AI successfully.",
  "sessionId": "abc123",
  "data": {
    "content": "Assistant reply...",
    "title": "User message"
  },
  "contextSources": []
}
```

## POST `/calculate-seo-score`

Score content for SEO before publishing visibility-optimized pages.

**Body:**

| Field | Type | Required | Description |
| - | - | - | - |
| `content` | string | Yes | Body text to analyze |
| `title` | string | No | Page title |
| `keywords` | string\[] | No | Target keywords from your visibility report |
| `autoExtractKeywords` | boolean | No | Extract keywords when none provided (default: `true`) |

## POST `/improve-content-simple`

Single-pass AI content improvement with before/after SEO scores. Use on existing pages that underperform in visibility reports.

**Body:**

| Field | Type | Required | Description |
| - | - | - | - |
| `content` | string | Yes | Content to improve |
| `improvePrompt` | string | Yes | Improvement instructions |
| `metricType` | string | No | Metric label (default: `general`) |

## POST `/improve-content-with-validation`

Iterative content improvement with validation. Requires a paid plan.

## POST `/process-blog-post-with-images`

Process a blog post and generate associated images.

## POST `/image`

Generate an image.

**Body:**

| Field | Type | Required | Description |
| - | - | - | - |
| `text` | string | Yes | Image prompt |
| `model` | string | Yes | `dall-e-3` or `stability-ultra` |
| `size` | string | Yes | DALL·E size (e.g. `1024x1024`) or Stability aspect ratio |

**Response (200):** Provider-specific image payload in `data`.

## Brand voice (generate routes)

Create brand voices that keep visibility-optimized content on-brand.

| Method | Endpoint | Description |
| - | - | - |
| `POST` | `/brand-voice/website` | Generate brand voice from a website URL |
| `POST` | `/brand-voice/text` | Generate brand voice from sample text |
| `POST` | `/brand-voice/file` | Generate brand voice from an uploaded file |

Manage saved voices via [Brand voice library](/api-reference/brand-voice).

## POST `/feedback`

Submit feedback on AI output quality.

## GET `/job/:jobId`

Poll async job status (content, SEO, or AI queues).

**Response (200):**

```json theme={null}
{
  "jobId": "12345",
  "name": "ai_tool_content",
  "state": "completed",
  "progress": 100,
  "result": {},
  "failedReason": null,
  "attemptsMade": 1,
  "processedOn": 1717776000000,
  "finishedOn": 1717776005000,
  "queue": "aiQueue"
}
```

Job states follow BullMQ conventions: `waiting`, `active`, `completed`, `failed`, etc.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.