Error handling
Every Bearer route answers with the same envelope. Branch on success, then on error.code, not on the message text.
01The envelope
400Error
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "topic: String must contain at least 3 character(s), project_id: Required"
},
"meta": {
"timestamp": "2026-10-29T15:43:52.561Z"
}
}Every response, success or error, carries an X-Request-Id header. Quote it when you write to support. Errors raised before your request reaches the route (401, the consent 403 and the 429 rate limit) also repeat it as meta.request_id; the others do not, so read the header.
Some errors add fields inside error. The session-only key routes are the exception to the envelope; see API keys.
02Every code
| Status | Code | When | Retry? |
|---|---|---|---|
| 400 | VALIDATION_ERROR | Missing or malformed field, bad query value, body that is not JSON | No. Fix the request. |
| 400 | NO_PROJECT | Social generate with no project_id and no project on the account | No. Create a project in the app. |
| 401 | UNAUTHORIZED | No Bearer header, unknown key, revoked or expired key | No |
| 402 | INSUFFICIENT_CREDITS | The balance cannot cover the job. Nothing was charged. | Not until you top up |
| 403 | FORBIDDEN | The key lacks write, or lacks the projects scope (Actors, preflight) | No |
| 403 | CONSENT_REQUIRED | The account owner has not accepted the current Terms | After accepting them in the app |
| 404 | NOT_FOUND | Unknown id, or it belongs to another account | No |
| 409 | CONFLICT | Already published, Actor already generating, or the post price changed mid-request | Social price change: yes, once |
| 409 | THREAD_PROJECT_MISMATCH | Actor thread_id is in another project | No |
| 412 | PRECONDITION_FAILED | Publish before generation finished, nothing to publish, or no connected account | After the condition is met |
| 422 | ACTOR_REQUEST_REJECTED | The Actor request cannot be prepared | No |
| 429 | RATE_LIMIT_EXCEEDED | Per-key limit, preflight limit, or a generation burst limit | Yes, after Retry-After when present |
| 500 | INTERNAL_ERROR | Unexpected failure | Yes, with backoff. For social generate, check the content list first. |
| 502 | INTERNAL_ERROR | Scheduling failed on every channel | Check the message first |
| 503 | INTERNAL_ERROR / APPROVAL_UNAVAILABLE | A dependency is briefly unavailable | Yes, with backoff |
03Partial success
POST /social/publish with scheduled_at returns 207 when some channels were scheduled and others failed. The body has success: true, scheduled_channels and failed_channels (each with its error).
04A client that handles it
async function bp(path, init = {}, attempt = 0) {
const res = await fetch('https://www.brainpercent.app/api/v1' + path, {
...init,
headers: {
Authorization: `Bearer ${process.env.BP_KEY}`,
'Content-Type': 'application/json',
...init.headers,
},
});
const body = await res.json();
if (body.success) return body;
const retryable = res.status === 429 || res.status >= 500;
if (retryable && attempt < 4) {
const wait = Number(res.headers.get('Retry-After')) || 2 ** attempt;
await new Promise((r) => setTimeout(r, wait * 1000));
return bp(path, init, attempt + 1);
}
const err = new Error(`${body.error.code}: ${body.error.message}`);
err.requestId = res.headers.get('X-Request-Id');
throw err;
}Your codeBrainpercent
- Your code to Brainpercent:
POST /api/v1/social/generate - Brainpercent to Your code: 500
INTERNAL_ERRORThis can mean the payment could not be confirmed. - Your code to Brainpercent:
GET /api/v1/social/content?limit=5 - Brainpercent to Your code: Your newest itemsA new item is there: the job started, do not retry. No new item: retry.