Concepts

Authentication, Scopes, AI access, errors, idempotency, limits, Workspaces and Jobs.

Base URL and versions

EnvironmentBase URL
Productionhttps://app.cgenius.app
Local developmenthttp://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.

ScopeAllows
content:readRead content, blogs, ideas, brand voices, questionnaires; list assistants, projects, LeadGenius companies and social channel rules
content:writeCreate and change those; start content generation
publish:readRead publications, schedules, publishing endpoints, the Buffer connection and its channels
publish:writePublish and schedule (including Buffer posts)
connections:manageConnect and disconnect social and Buffer accounts
media:readRead the media library
media:writeUpload and change media; keep generated images
settings:readRead settings and /me
settings:writeChange settings
jobs:readRead Jobs
jobs:writeStart, advance, cancel and resume Jobs
tokens:manageList, create and revoke API tokens; read the audit log
maintenance:readRead maintenance tickets
maintenance:writeCreate 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": {}
  }
}
CodeHTTPWhat to do
validation_failed400Fix the fields listed in error.fields and send again.
unauthenticated401The token is missing, wrong, revoked or expired. Ask the user for a new token.
credits_exhausted402The user is out of EpsimoAgents credits. Stop and tell the user.
insufficient_scope403The token lacks a Scope (error.details.missingScopes). Ask the user for a token with it.
ai_access_unavailable403The token has no AI access, or it ended. Ask the user to create a token with AI access.
workspace_required403Send X-Workspace-Id with one of the Workspaces of GET /api/v1/me.
forbidden403This caller may not do this (for example an API token approving tokens). Do not retry.
not_found404The id does not exist or belongs to someone else. Do not retry.
conflict409The resource is in a state that does not allow this (for example cancelling a finished Job). Read it again.
account_link_required409The account needs linking by an administrator. Tell the user.
idempotency_key_reused409The Idempotency-Key was used with another body. Use a new key.
idempotency_in_progress409The first request with this key is still running. Wait and retry with the same key.
version_conflict412The record changed since you read it. Read it again, then retry with the new version in If-Match.
session_expired410The CLI login session expired or was denied. Start a new one.
payload_too_large413The body is over 1 MB. Send less.
unsupported_media_type415Send Content-Type: application/json (or the media type the Operation names).
reference_not_found422An id in the body (assistant, project, content) does not exist. Fix it.
network_rules_violation422The content breaks a social network rule (error.details). Shorten or change it.
network_not_enabled422The network is not connected for this Workspace.
url_not_allowed422The URL is not allowed (private address, wrong scheme or port).
schedule_in_past422Pick a time in the future.
connection_needs_reauth422The social connection must be reconnected by the user in the app.
provider_limit_reached429The social network refused for quota reasons. Wait before retrying.
rate_limited429Wait for Retry-After seconds, then retry.
internal500Retry once after a few seconds; if it fails again, report the correlationId.
upstream_unavailable503A 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

LimitDefault
Requests per minute, per token (or per signed-in user)120
Job starts per minute, per user10
Jobs running at once, per user5

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.

FieldMeaning
statusPENDING → RUNNING → COMPLETED, FAILED or CANCELLED
progress0 to 100; never goes down; 100 only with COMPLETED
currentStepthe Step that runs now ('' when none)
stepseach Step's status, and its result once completed
partialContenttext written so far by the running Step
result.resourcesCOMPLETED only: [{type, id}] of what the Job made (for example content, offer)
errorFAILED only: {code, message, step}, with the codes of the table above
originui, 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}/advance runs it for one request; with Accept: text/event-stream you receive the text as it is written (chunk, then view).
  • 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}/cancel stops a running Job; POST /api/v1/jobs/{id}/resume restarts a FAILED one 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.