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

# Generating content with AI

> Write post copy, generate images, video and speech, and use the results in posts.

Every generation is an **AI result**: start it, let it run (often in the background), then read its text or media. Send `company_id` every time: it picks the brand voice and the plan that pays.

## What you can generate

| Endpoint | Makes |
| - | - |
| [`POST /aiResults/copy/post`](https://docs.followr.ai/api-reference/ai-copywriting/write-post-copy) | Posts for one network, in the company's voice |
| [`POST /aiResults/copy/title`](https://docs.followr.ai/api-reference/ai-copywriting/write-a-post-title) | Titles for Pinterest, YouTube and Medium |
| [`POST /aiResults/copy/thread`](https://docs.followr.ai/api-reference/ai-copywriting/split-a-post-into-a-thread) | A thread for X, Threads or Bluesky, from a long text |
| [`POST /aiResults/chat`](https://docs.followr.ai/api-reference/ai-generation/generate-text) | Any text, from your prompt |
| [`POST /aiResults/image`](https://docs.followr.ai/api-reference/ai-generation/generate-an-image) | Images, from a prompt and optional reference pictures |
| [`POST /aiResults/video`](https://docs.followr.ai/api-reference/ai-generation/generate-a-video) | Video clips |
| [`POST /aiResults/audio`](https://docs.followr.ai/api-reference/ai-generation/generate-speech) | Speech from text |
| [`POST /companies/{company_id}/videoProjects`](https://docs.followr.ai/api-reference/video/create-a-video-project) | Avatar videos and short videos, built from several clips |
| [`POST /companies/{company_id}/creative`](https://docs.followr.ai/api-reference/creative-studio/create-a-design) | Graphics and carousels (Creative Studio) |

Each reference page lists the endpoint's models and options.

## Credits

* **Text** (copy and chat) uses AI words: the answer's words times the model's rate.
* **Images, video and music** use media credits. A video needs its full price available to start.
* A finished result's `words` is its cost. **Failed generations cost nothing.**

Running out answers `402` (see [Errors](#errors)). Check balances with `GET /subscriptions/balance`, and see [Plans and usage](https://docs.followr.ai/api/plans-and-usage.md).

## Run it in the background

**1. Start**

Send the request in background mode (table below). You get `201`, an `id` and `status: pending`.

**2. Poll**

Call `GET /aiResults/{id}` until `status` is `completed` or `failed`.

**3. Read**

`response` holds the text or the file's URL. On `failed`, read `status_message`.

| What | Background | Poll every | Give up after |
| - | - | - | - |
| Copy and chat | `async: true` | 2 seconds | 10 minutes |
| Images and speech | `queue: true` | 5 seconds | 10 minutes |
| Video clips | Always | 15 to 20 seconds | 30 minutes |
| Video projects (`GET /videoProjects/{id}`) | Always | 10 seconds | 45 minutes, then the project fails |
| Creative Studio (`GET /creative/{groupId}`) | Always | 5 seconds | 15 minutes |

Polling faster doesn't bring results sooner, and counts against your [rate limit](https://docs.followr.ai/api/rate-limits.md).

```python Python theme={null}
import os
import time

import requests

API = "https://api.followr.ai/api"
session = requests.Session()
session.headers.update({
    "Authorization": f"Bearer {os.environ['FOLLOWR_API_KEY']}",
    "Accept": "application/json",
})


def wait_for_result(result_id, every=5, timeout=600):
    deadline = time.monotonic() + timeout
    while time.monotonic() < deadline:
        response = session.get(f"{API}/aiResults/{result_id}", timeout=30)
        response.raise_for_status()
        result = response.json()["data"]
        if result["status"] == "completed":
            return result
        if result["status"] == "failed":
            raise RuntimeError(result["status_message"] or "Generation failed")
        time.sleep(every)
    raise TimeoutError(f"AI result {result_id} did not finish in {timeout} seconds")


started = session.post(f"{API}/aiResults/image", json={
    "q": "A flat white on a marble counter, morning light, shallow depth of field",
    "driver": "fal",
    "model": "nano_banana_2_1",
    "aspect_ratio": "4:5",
    "company_id": 1287,
    "queue": True,
}, timeout=70)
started.raise_for_status()

image = wait_for_result(started.json()["data"]["id"])
print("Image URL:", image["response"], "cost:", image["words"])
```

```javascript JavaScript theme={null}
const API = "https://api.followr.ai/api";
const headers = {
  Authorization: `Bearer ${process.env.FOLLOWR_API_KEY}`,
  Accept: "application/json",
  "Content-Type": "application/json",
};
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

async function waitForResult(id, everyMs = 5000, timeoutMs = 600000) {
  const deadline = Date.now() + timeoutMs;
  while (Date.now() < deadline) {
    const response = await fetch(`${API}/aiResults/${id}`, { headers });
    if (!response.ok) throw new Error(`Polling failed with ${response.status}`);
    const { data } = await response.json();
    if (data.status === "completed") return data;
    if (data.status === "failed") throw new Error(data.status_message ?? "Generation failed");
    await sleep(everyMs);
  }
  throw new Error(`AI result ${id} did not finish in time`);
}

const started = await fetch(`${API}/aiResults/image`, {
  method: "POST",
  headers,
  body: JSON.stringify({
    q: "A flat white on a marble counter, morning light, shallow depth of field",
    driver: "fal",
    model: "nano_banana_2_1",
    aspect_ratio: "4:5",
    company_id: 1287,
    queue: true,
  }),
});
if (!started.ok) throw new Error(`Start failed with ${started.status}: ${await started.text()}`);

const image = await waitForResult((await started.json()).data.id);
console.log("Image URL:", image.response, "cost:", image.words);
```

## Write post copy

The copywriting endpoints build the prompt from structured fields, in the company's voice and language:

```bash cURL theme={null}
curl --request POST https://api.followr.ai/api/aiResults/copy/post \
  --header "Authorization: Bearer $FOLLOWR_API_KEY" \
  --header "Accept: application/json" \
  --header "Content-Type: application/json" \
  --data '{
    "company_id": 1287,
    "network": "instagram",
    "brief": "Launch of our maple oat latte, available from December 15 for the winter season.",
    "tone": "Warm and playful",
    "cta": "Visit us this week",
    "variations": 2
  }'
```

The result's `response` is a JSON string. Parse it:

```json theme={null}
{
  "posts": [
    { "text": "Meet the cup that makes winter worth it...", "length": 158 },
    { "text": "Cold outside, maple inside...", "length": 150 }
  ]
}
```

The maximum `variations` per request depends on the network: 1 for LinkedIn, YouTube and Medium, up to 5 for X, Threads and Bluesky.

## Use a generated image in a post

A finished image's `response` is a URL. To post it, copy it into the media library:

**1. Create an asset**

`POST /companies/1287/assets` with `{"name": "Winter latte", "type": "image"}`.

**2. Attach the file**

`POST /assets/{id}/image` with `{"filename": "winter-latte.jpg", "url": "<the result's response>", "visibility": "public"}`. Followr downloads it.

**3. Add it to a post**

List the asset in `assets_ids`. See [Publishing posts](https://docs.followr.ai/guides/publishing-posts.md).

A finished video project is already in the library: use `final.media_id` as the asset ID.

## Errors

| Status | Meaning |
| - | - |
| `400` | A generation run inside the request failed (see the message). Nothing is charged. |
| `402` | Not enough AI words (`entity: words`) or media credits (`images`, or `premium_images` for premium models), or the model needs a plan feature. |
| `403` | The key's user is a `client`, or not a member of the company. |
| `422` | An option is invalid for the model, or the model isn't available to the company. |
| `502` | Copywriting got an incomplete answer. Retry. Nothing is charged. |

A background generation that fails ends with `status: failed`, not an error status.


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