Webhooks and async jobs
Generating takes minutes, so the generate routes return 202 at once and you poll. Separately, articles you publish can be delivered to your own website: as a signed webhook POST, or through a private read API your site calls.
01Async jobs: poll
No callback fires when a generate job finishes. Poll the poll_url from the 202 (prefix it with https://www.brainpercent.app).
- Your server to Brainpercent:
POST /api/v1/articles/generate - Brainpercent to Your server: 202 with a
poll_urlThe job has started. Nothing will call you when it ends. - Your server to Brainpercent:
GET /api/v1/articles/{id}/statusEvery 30 seconds, until the answer below. - Brainpercent to Your server:
is_complete: trueDone. Stop polling.
| Job | Poll | Done when | How often |
|---|---|---|---|
| Article | GET /api/v1/articles/{id}/status | is_complete or is_failed is true | Every 30 s, up to about 20 min |
| Social | GET /api/v1/social/content/{id} | status is not generating or queued | Every 5 to 10 s, up to about 15 min |
| Actor | GET /api/v1/actors/approvals/{id}, then /actors/{id} | approval executed, then Actor status ready or failed | Every 30 s |
const H = { Authorization: `Bearer ${process.env.BP_KEY}` };
async function waitForArticle(id) {
for (let i = 0; i < 40; i += 1) {
const { data } = await fetch(`https://www.brainpercent.app/api/v1/articles/${id}/status`, { headers: H })
.then((r) => r.json());
if (data.is_failed) throw new Error('Article failed; the charge was refunded');
if (data.is_complete) return data;
await new Promise((r) => setTimeout(r, 30_000));
}
throw new Error('Still running after 20 minutes');
}02Outgoing webhooks for published articles
When you publish, update or unpublish an article to a website that is connected as a webhook, Brainpercent sends a signed HTTPS POST to your endpoint. Generate jobs, social posts and credit changes do not send webhooks.
Set it up
In the app, open Connections for the project, then Websites, choose Add website and pick Send to your site. Enter a public https:// endpoint (no redirects, no private addresses). The signing secret (whsec_β¦) is shown once; you can replace it and Send test event from the same screen. The screen also gives you a ready-made brief to paste into an AI coding assistant. Websites belong to one project.
The request
| Header | Value |
|---|---|
| Content-Type | application/json |
| User-Agent | Brainpercent-Webhooks/1.0 |
| X-Brainpercent-Event | article.published | article.updated | article.unpublished | test |
| X-Brainpercent-Signature | t=<unix seconds>,v1=<hex HMAC-SHA256> |
| X-Brainpercent-Timestamp | The same unix seconds as t |
| X-Brainpercent-Delivery | Delivery id, identical on every retry of one event (also sent as Idempotency-Key) |
{
"id": "evt_3f9cβ¦",
"type": "article.published",
"created_at": "2026-10-26T09:00:00.000Z",
"destination_id": "6b1dβ¦",
"article": {
"id": "ed234978-8cae-4f3c-83d2-ed57d9f5020b",
"slug": "how-to-dial-in-a-cold-brew-ratio-at-home",
"title": "How to dial in a cold brew ratio at home",
"html": "<p>β¦</p>",
"markdown": "β¦",
"excerpt": "β¦",
"cover_image_url": "https://β¦ or null",
"language": "en",
"tags": [
"cold brew"
],
"canonical_url": "https://northwind.coffee/blog/how-to-dial-in-a-cold-brew-ratio-at-home or null",
"published_at": "2026-10-26T09:00:00.000Z",
"updated_at": "2026-10-26T09:00:00.000Z"
}
}article is null on test. Save on article.published and article.updated by article.id (replace, never duplicate); hide it on article.unpublished.
Verify the signature
Compute HMAC-SHA256 with your secret over <t>.<raw body>, compare it with v1 in constant time, and reject anything where t is more than 300 seconds from now. Use the raw bytes, not re-serialized JSON.
import crypto from 'node:crypto';
import express from 'express';
const app = express();
const SECRET = process.env.BRAINPERCENT_WEBHOOK_SECRET; // whsec_...
// Keep the raw bytes: the signature is over the exact body we sent.
app.post('/brainpercent/webhook', express.raw({ type: 'application/json' }), (req, res) => {
const header = req.get('X-Brainpercent-Signature') || '';
const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
const t = Number(parts.t);
const given = parts.v1 || '';
const raw = req.body.toString('utf8');
const expected = crypto.createHmac('sha256', SECRET).update(`${t}.${raw}`).digest('hex');
const fresh = Math.abs(Date.now() / 1000 - t) <= 300;
const ok = fresh && given.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected));
if (!ok) return res.status(401).end();
const event = JSON.parse(raw);
// Use X-Brainpercent-Delivery (same as event.id) to ignore repeats.
if (event.type === 'article.published' || event.type === 'article.updated') {
// save or replace by event.article.id
} else if (event.type === 'article.unpublished') {
// hide event.article.id
}
res.status(200).end(); // answer within 15 seconds
});Answers and retries
- Brainpercent to Your endpoint: POST
article.publishedSigned inX-Brainpercent-Signature. - Your endpoint to Brainpercent: A 5xx, or no answer within 15 seconds
- Brainpercent to Your endpoint: The same POST again, after a waitSame body and delivery id, fresh signature.
- Your endpoint to Brainpercent: 2xxDelivered.
| Your answer | What happens |
|---|---|
| 2xx within 15 seconds | Delivered |
| 408, 409, 425, 429, 5xx, timeout, network error, any 4xx not listed below | Retried with backoff, up to 5 more attempts, same body and delivery id, fresh signature |
| 3xx | Not followed. Marked failed: use the final https address. |
| 400, 401, 403, 404, 405, 410, 411, 413, 414, 415, 422 | Not retried. Marked failed. |
The last delivery result and any error show on the website in Connections.
03Site read API
The other option: choose Site feed under Add website, and your site fetches its articles. You get a read key (bpk_β¦, shown once) and the website id. Call it from your server or at build time, never from a browser.
# Newest first. limit 1-50 (default 20), offset, optional language
curl "https://www.brainpercent.app/api/public/sites/$SITE_ID/articles?limit=20&offset=0" \
-H "X-Brainpercent-Key: $BRAINPERCENT_SITE_KEY"
# One article with html and markdown
curl "https://www.brainpercent.app/api/public/sites/$SITE_ID/articles/how-to-dial-in-a-cold-brew-ratio-at-home" \
-H "X-Brainpercent-Key: $BRAINPERCENT_SITE_KEY"| Fact | Value |
|---|---|
| Auth | X-Brainpercent-Key: bpk_β¦ (or Authorization: Bearer bpk_β¦). A bp_ API key does not work here. |
| List body | { "articles": [...], "next_offset": 20 | null }, without html and markdown |
| One article | { "article": { id, slug, title, html, markdown, excerpt, cover_image_url, language, tags, canonical_url, published_at, updated_at } } |
| Only | Articles published to this website, as they were when published |
| Errors | 401 { "error": "Invalid or missing key." }, 404 for a slug not live here, 429 with Retry-After, 503 |
| Limit | About 120 requests a minute per website. Responses may be cached for 60 seconds. |
Using Claude instead? The MCP server polls for you; see Use Brainpercent from Claude.