Skip to content

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

StatusCodeWhenRetry?
400VALIDATION_ERRORMissing or malformed field, bad query value, body that is not JSONNo. Fix the request.
400NO_PROJECTSocial generate with no project_id and no project on the accountNo. Create a project in the app.
401UNAUTHORIZEDNo Bearer header, unknown key, revoked or expired keyNo
402INSUFFICIENT_CREDITSThe balance cannot cover the job. Nothing was charged.Not until you top up
403FORBIDDENThe key lacks write, or lacks the projects scope (Actors, preflight)No
403CONSENT_REQUIREDThe account owner has not accepted the current TermsAfter accepting them in the app
404NOT_FOUNDUnknown id, or it belongs to another accountNo
409CONFLICTAlready published, Actor already generating, or the post price changed mid-requestSocial price change: yes, once
409THREAD_PROJECT_MISMATCHActor thread_id is in another projectNo
412PRECONDITION_FAILEDPublish before generation finished, nothing to publish, or no connected accountAfter the condition is met
422ACTOR_REQUEST_REJECTEDThe Actor request cannot be preparedNo
429RATE_LIMIT_EXCEEDEDPer-key limit, preflight limit, or a generation burst limitYes, after Retry-After when present
500INTERNAL_ERRORUnexpected failureYes, with backoff. For social generate, check the content list first.
502INTERNAL_ERRORScheduling failed on every channelCheck the message first
503INTERNAL_ERROR / APPROVAL_UNAVAILABLEA dependency is briefly unavailableYes, 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
  1. Your code to Brainpercent: POST /api/v1/social/generate
  2. Brainpercent to Your code: 500 INTERNAL_ERRORThis can mean the payment could not be confirmed.
  3. Your code to Brainpercent: GET /api/v1/social/content?limit=5
  4. Brainpercent to Your code: Your newest itemsA new item is there: the job started, do not retry. No new item: retry.