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

# API quickstart

> Create an API key, check it, generate a LinkedIn post and schedule it, with curl, JavaScript and Python.

In four calls you create a key, read your workspaces, generate a post and schedule it. Generation costs 5 credits.

> [!NOTE]
>
> The API is on the Studio plan. Scheduling needs a connected LinkedIn account in the workspace.

**1. Create a key**

An owner opens **Settings → API keys**, selects **Create API key**, names it and copies the key. The key starts with `pc_live_` and is shown once. See [Authentication](/api/authentication.md).

Keep it out of your code. Put it in an environment variable:

```bash
export POSTCHAMP_API_KEY="pc_live_xxx"
```

**2. Check the key**

`GET /api/v1/key` tells you the plan, who the key acts as, and the workspaces it reaches. Copy the `id` of the workspace you want.

```bash curl
curl https://api.postchampai.com/api/v1/key \
  -H "x-api-key: $POSTCHAMP_API_KEY"
```

```javascript JavaScript
const res = await fetch("https://api.postchampai.com/api/v1/key", {
  headers: { "x-api-key": process.env.POSTCHAMP_API_KEY },
});
const info = await res.json();
const workspaceId = info.workspaces.find((w) => w.isMain).id;
```

```python Python
import os, requests

res = requests.get(
    "https://api.postchampai.com/api/v1/key",
    headers={"x-api-key": os.environ["POSTCHAMP_API_KEY"]},
)
info = res.json()
workspace_id = next(w["id"] for w in info["workspaces"] if w["isMain"])
```

```json Response 200
{
  "key": { "id": "d7937443-7bb4-4be7-aecb-8ec0fe5216f3", "prefix": "pc_live_hV4q42", "workspaceId": null },
  "organization": { "id": "f673ed0b-1bdf-5527-b0f0-35452df56cea", "plan": "studio" },
  "actingAs": { "userId": "14655453-0e13-547f-8ba2-14f2e8865e50", "name": "Dana Reyes" },
  "workspaces": [
    { "id": "953ea6f8-5384-5a52-aa3f-7311a47ac796", "name": "Main", "isMain": true },
    { "id": "3eeab7c7-d139-5477-8781-8b714ee5a7cc", "name": "Lumen Coffee", "isMain": false }
  ]
}
```

`"workspaceId": null` means the key reaches every workspace its creator can open.

**3. Generate a post**

Send a prompt. You must send an `Idempotency-Key` header: a retry with the same key and body returns the first answer and never charges twice. See [Idempotency](/api/idempotency.md).

```bash curl
curl -X POST "https://api.postchampai.com/api/v1/workspaces/$WORKSPACE_ID/posts/generate" \
  -H "x-api-key: $POSTCHAMP_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: quickstart-gen-001" \
  -d '{"prompt": "Why founders should write down their weekly wins", "versions": 1}'
```

```javascript JavaScript
const gen = await fetch(
  `https://api.postchampai.com/api/v1/workspaces/${workspaceId}/posts/generate`,
  {
    method: "POST",
    headers: {
      "x-api-key": process.env.POSTCHAMP_API_KEY,
      "Content-Type": "application/json",
      "Idempotency-Key": "quickstart-gen-001",
    },
    body: JSON.stringify({
      prompt: "Why founders should write down their weekly wins",
      versions: 1,
    }),
  },
);
const result = await gen.json();
const postId = result.postIds[0];
```

```python Python
gen = requests.post(
    f"https://api.postchampai.com/api/v1/workspaces/{workspace_id}/posts/generate",
    headers={
        "x-api-key": os.environ["POSTCHAMP_API_KEY"],
        "Idempotency-Key": "quickstart-gen-001",
    },
    json={"prompt": "Why founders should write down their weekly wins", "versions": 1},
)
result = gen.json()
post_id = result["postIds"][0]
```

```json Response 200
{
  "status": "done",
  "generationGroupId": "8b365def-bd81-4d37-9af0-d00942205e87",
  "postIds": ["b77a4469-66cb-4363-bf37-97ef73784804"],
  "posts": [
    {
      "id": "b77a4469-66cb-4363-bf37-97ef73784804",
      "status": "draft",
      "content": "This is placeholder text from the test model.",
      "linkedInText": "This is placeholder text from the test model.",
      "charCount": 45,
      "origin": "api",
      "scheduledAt": null,
      "editable": true
    }
  ],
  "failed": 0,
  "suggestedFirstComment": null,
  "replayed": false,
  "creditsLeft": 7745
}
```

The answer here is shortened: each post also has `contentDoc`, `lock`, `createdAt` and more. The text is placeholder text because this example ran against a test model. Real answers contain a written post. The post is saved as a draft with `origin: "api"`.

> [!NOTE]
>
> When the model needs more detail it answers `"status": "needs_input"` with a `question`. Nothing is charged. Send the same request again with the same `Idempotency-Key` and an `answers` array. See the [recipe](/api/recipes/generate-and-schedule.md).

**4. Schedule it**

Pick a time at least one minute ahead. This call spends no credits, so it needs no idempotency key.

```bash curl
curl -X POST "https://api.postchampai.com/api/v1/workspaces/$WORKSPACE_ID/posts/$POST_ID/schedule" \
  -H "x-api-key: $POSTCHAMP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"scheduledAt": "2026-12-07T09:00:00Z"}'
```

```javascript JavaScript
const sched = await fetch(
  `https://api.postchampai.com/api/v1/workspaces/${workspaceId}/posts/${postId}/schedule`,
  {
    method: "POST",
    headers: {
      "x-api-key": process.env.POSTCHAMP_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ scheduledAt: "2026-12-07T09:00:00Z" }),
  },
);
console.log(await sched.json());
```

```python Python
sched = requests.post(
    f"https://api.postchampai.com/api/v1/workspaces/{workspace_id}/posts/{post_id}/schedule",
    headers={"x-api-key": os.environ["POSTCHAMP_API_KEY"]},
    json={"scheduledAt": "2026-12-07T09:00:00Z"},
)
print(sched.json())
```

```json Response 200
{
  "id": "b77a4469-66cb-4363-bf37-97ef73784804",
  "status": "scheduled",
  "scheduledAt": "2026-12-07T09:00:00.000Z",
  "local": { "date": "2026-12-07", "time": "04:00" },
  "timezone": "America/New_York",
  "scheduleVersion": 1,
  "publishedAt": null,
  "linkedinPostUrl": null,
  "lastErrorCode": null,
  "lastErrorMessage": null
}
```

To undo it, call `POST .../posts/{postId}/cancel-schedule`. The post goes back to a draft.

## If a call fails

| You see | Reason |
| - | - |
| `401 api_key_required` or `api_key_invalid` | The `x-api-key` header is missing, or the key is revoked, expired or mistyped. |
| `403 plan_limit` | The organization is not on the plan with API access. |
| `404 not_found` | The workspace id is wrong, or your key is scoped to another workspace. |
| `400 idempotency_key_required` | Add the `Idempotency-Key` header to the generate call. |
| `400 linkedin_not_connected` | Connect LinkedIn for the workspace in the app, then schedule again. |
| `400 scheduled_too_soon` | Use a time at least a minute from now. |

All codes are on the [Errors](/api/errors.md) page.

## Next steps

> [card] [Generate and schedule recipe](/api/recipes/generate-and-schedule.md)
>
> A complete script with retries and error handling.

> [card] [Carousels](/api/recipes/carousels.md)
>
> Create a carousel and follow its job.

> [card] [Rate limits](/api/rate-limits.md)
>
> How many calls a key can make.

> [card] [Jobs and streaming](/api/jobs-and-streaming.md)
>
> Stream a post as it is written.
