Skip to content

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 serverBrainpercent
  1. Your server to Brainpercent: POST /api/v1/articles/generate
  2. Brainpercent to Your server: 202 with a poll_urlThe job has started. Nothing will call you when it ends.
  3. Your server to Brainpercent: GET /api/v1/articles/{id}/statusEvery 30 seconds, until the answer below.
  4. Brainpercent to Your server: is_complete: trueDone. Stop polling.
An article job is shown. The table has the routes for social and Actor jobs.
JobPollDone whenHow often
ArticleGET /api/v1/articles/{id}/statusis_complete or is_failed is trueEvery 30 s, up to about 20 min
SocialGET /api/v1/social/content/{id}status is not generating or queuedEvery 5 to 10 s, up to about 15 min
ActorGET /api/v1/actors/approvals/{id}, then /actors/{id}approval executed, then Actor status ready or failedEvery 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

HeaderValue
Content-Typeapplication/json
User-AgentBrainpercent-Webhooks/1.0
X-Brainpercent-Eventarticle.published | article.updated | article.unpublished | test
X-Brainpercent-Signaturet=<unix seconds>,v1=<hex HMAC-SHA256>
X-Brainpercent-TimestampThe same unix seconds as t
X-Brainpercent-DeliveryDelivery id, identical on every retry of one event (also sent as Idempotency-Key)
200Body
{
  "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

BrainpercentYour endpoint
  1. Brainpercent to Your endpoint: POST article.publishedSigned in X-Brainpercent-Signature.
  2. Your endpoint to Brainpercent: A 5xx, or no answer within 15 seconds
  3. Brainpercent to Your endpoint: The same POST again, after a waitSame body and delivery id, fresh signature.
  4. Your endpoint to Brainpercent: 2xxDelivered.
One failed answer is shown. The table has every answer and what follows it.
Your answerWhat happens
2xx within 15 secondsDelivered
408, 409, 425, 429, 5xx, timeout, network error, any 4xx not listed belowRetried with backoff, up to 5 more attempts, same body and delivery id, fresh signature
3xxNot followed. Marked failed: use the final https address.
400, 401, 403, 404, 405, 410, 411, 413, 414, 415, 422Not 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"
FactValue
AuthX-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 } }
OnlyArticles published to this website, as they were when published
Errors401 { "error": "Invalid or missing key." }, 404 for a slug not live here, 429 with Retry-After, 503
LimitAbout 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.