Concepts
Authentication, Scopes, AI access, errors, idempotency, limits, Workspaces and Jobs.
Base URL and versions
| Environment | Base URL |
|---|---|
| Production | https://app.cgenius.app |
| Local development | http://localhost:3000 |
Every path starts with /api/v1. The version in GET /api/v1/health and the OpenAPI document follows semver: additive changes keep v1; a breaking change gets /api/v2 and a deprecation period announced with Deprecation and Sunset headers.
Authentication
Send Authorization: Bearer <token> on every call except the public ones (/health, /openapi.json, the CLI login start and exchange). Two kinds of token work:
- API token (
cg_+ 64 hex characters): made in Settings → API Tokens or by the CLI login. It has Scopes and an expiry (default 90 days, at most 365). Only its SHA-256 is stored. - Cognito ID token of a signed-in app user. The app's own pages use it; it has every Scope.
The app's own routes (/api/... outside /api/v1) check no Scope. They accept only API tokens that hold every Scope, or legacy tokens made before Scopes existed; a token with limited Scopes gets 403 there. Integrations use /api/v1.
Scopes
A token can do only what its Scopes allow; anything else answers 403 insufficient_scope with error.details.missingScopes. Starting a Job needs the resource's write Scope and jobs:write.
| Scope | Allows |
|---|---|
content:read | Read content, blogs, ideas, brand voices, questionnaires; list assistants, projects, LeadGenius companies and social channel rules |
content:write | Create and change those; start content generation |
publish:read | Read publications, schedules, publishing endpoints, the Buffer connection and its channels |
publish:write | Publish and schedule (including Buffer posts) |
connections:manage | Connect and disconnect social and Buffer accounts |
media:read | Read the media library |
media:write | Upload and change media; keep generated images |
settings:read | Read settings and /me |
settings:write | Change settings |
jobs:read | Read Jobs |
jobs:write | Start, advance, cancel and resume Jobs |
tokens:manage | List, create and revoke API tokens; read the audit log |
maintenance:read | Read maintenance tickets |
maintenance:write | Create and change maintenance tickets |
Tokens created before Scopes existed show as full access, no AI access.
AI access
Operations that call EpsimoAgents (generation, credits) or read the Lead App need AI access. A token gets it when the user approves it in the browser and signs in once more on the Cognito page; the token then acts as that user, until the sign-in ends (the token page shows the end date). Without it these Operations answer 403 ai_access_unavailable. The reference marks them needs AI.
Errors
Every error has one shape:
{
"error": {
"code": "validation_failed",
"message": "Validation failed",
"correlationId": "4f1c…",
"fields": [{ "field": "requestData.topic", "message": "Required" }],
"details": {}
}
}
| Code | HTTP | What to do |
|---|---|---|
validation_failed | 400 | Fix the fields listed in error.fields and send again. |
unauthenticated | 401 | The token is missing, wrong, revoked or expired. Ask the user for a new token. |
credits_exhausted | 402 | The user is out of EpsimoAgents credits. Stop and tell the user. |
insufficient_scope | 403 | The token lacks a Scope (error.details.missingScopes). Ask the user for a token with it. |
ai_access_unavailable | 403 | The token has no AI access, or it ended. Ask the user to create a token with AI access. |
workspace_required | 403 | Send X-Workspace-Id with one of the Workspaces of GET /api/v1/me. |
forbidden | 403 | This caller may not do this (for example an API token approving tokens). Do not retry. |
not_found | 404 | The id does not exist or belongs to someone else. Do not retry. |
conflict | 409 | The resource is in a state that does not allow this (for example cancelling a finished Job). Read it again. |
account_link_required | 409 | The account needs linking by an administrator. Tell the user. |
idempotency_key_reused | 409 | The Idempotency-Key was used with another body. Use a new key. |
idempotency_in_progress | 409 | The first request with this key is still running. Wait and retry with the same key. |
version_conflict | 412 | The record changed since you read it. Read it again, then retry with the new version in If-Match. |
session_expired | 410 | The CLI login session expired or was denied. Start a new one. |
payload_too_large | 413 | The body is over 1 MB. Send less. |
unsupported_media_type | 415 | Send Content-Type: application/json (or the media type the Operation names). |
reference_not_found | 422 | An id in the body (assistant, project, content) does not exist. Fix it. |
network_rules_violation | 422 | The content breaks a social network rule (error.details). Shorten or change it. |
network_not_enabled | 422 | The network is not connected for this Workspace. |
url_not_allowed | 422 | The URL is not allowed (private address, wrong scheme or port). |
schedule_in_past | 422 | Pick a time in the future. |
connection_needs_reauth | 422 | The social connection must be reconnected by the user in the app. |
provider_limit_reached | 429 | The social network refused for quota reasons. Wait before retrying. |
rate_limited | 429 | Wait for Retry-After seconds, then retry. |
internal | 500 | Retry once after a few seconds; if it fails again, report the correlationId. |
upstream_unavailable | 503 | A dependency is down or not configured yet. Retry later with backoff. |
Idempotency
Operations marked idempotent accept Idempotency-Key (up to 255 characters). For 24 hours, the same key with the same body returns the first answer again, with Idempotent-Replay: true. The same key with another body answers 409 idempotency_key_reused; a key whose first request is still running answers 409 idempotency_in_progress.
Lists and pagination
List Operations take limit (1 to 100, default 25) and cursor, and answer {items, nextCursor?}. Pass nextCursor back unchanged with the same filters; a cursor from another list or filter answers 400.
Versions and If-Match
Records you can change carry version. Send it as If-Match: "3" on an update; if someone changed the record since, the answer is 412 version_conflict and nothing is written.
Rate limits
| Limit | Default |
|---|---|
| Requests per minute, per token (or per signed-in user) | 120 |
| Job starts per minute, per user | 10 |
| Jobs running at once, per user | 5 |
Over a limit, the answer is 429 rate_limited with Retry-After (seconds). GET /api/v1/me shows the limits that apply.
Request ids
Every answer has X-Request-Id, equal to error.correlationId on errors. You may send your own X-Request-Id (8 to 128 characters of A-Z a-z 0-9 . _ -) to tie the server logs to yours.
Workspaces
A user has one Workspace per LeadGenius company they own or are an active member of (c:<company id>), ordered by name, or a personal Workspace (u:<user id>) when they have no company. Content Operations act on the Active Workspace: the one named by X-Workspace-Id, else the first in GET /api/v1/me. A value that is not one of the caller's Workspaces is ignored. Memberships are read from LeadGenius and kept 5 minutes; if LeadGenius cannot be reached, these Operations answer 503 upstream_unavailable.
Jobs
Long work (writing a blog, generating an offer, analysing leads) is a Job.
| Field | Meaning |
|---|---|
status | PENDING → RUNNING → COMPLETED, FAILED or CANCELLED |
progress | 0 to 100; never goes down; 100 only with COMPLETED |
currentStep | the Step that runs now ('' when none) |
steps | each Step's status, and its result once completed |
partialContent | text written so far by the running Step |
result.resources | COMPLETED only: [{type, id}] of what the Job made (for example content, offer) |
error | FAILED only: {code, message, step}, with the codes of the table above |
origin | ui, api or scheduler |
How a Job moves:
GET /api/v1/jobs/{id}reads it and, when no one else is working on it and nothing changed in the last 2 seconds, runs it for up to 10 seconds first.POST /api/v1/jobs/{id}/advanceruns it for one request; withAccept: text/event-streamyou receive the text as it is written (chunk, thenview).- Jobs started with an API token also run on the server every minute, so a script may start one and come back later.
POST /api/v1/jobs/{id}/cancelstops a running Job;POST /api/v1/jobs/{id}/resumerestarts aFAILEDone from the failed Step.- A Job started with a token that is later revoked, or that loses AI access, fails with
ai_access_unavailable. Resume it with a valid token.
Polling: read every 2 to 5 seconds while RUNNING; a blog takes one to several minutes, an offer a few minutes.
CORS
Browsers may call the API only from the app's own origins (the Lead App and ContentGenius domains). Scripts, servers, CLIs and agents are not affected.