Botpress Execute Code card: call Sume's API without waiting on the run

Botpress's Execute Code card offers Axios for HTTP and no external libraries. Start a Sume run in one card and collect the result by webhook, not a wait loop.

4 min readSume
All posts

Start the Sume run in one Execute Code card and do not wait for it. Botpress documents Axios as the way to make API requests there and says you cannot import external libraries, so the card is a good place for a single POST and a poor place for a polling loop. Sume returns 202 right away, which fits.

What the Botpress page says

The Execute Code card runs JavaScript inside a node. The docs say you cannot import external libraries, point to Axios for API requests, and recommend handling slow or failed requests with try and catch, timeouts or fallback flows. It does not state an execution time limit, so design as if the card should finish quickly.

Split the work in two

One Botpress card per job (read 2026-10-06)
StageWhat happensSume side
StartAxios POST with the instruction, a cap and a callback URL202 and an agent.run receipt with id and status_url
StoreWrite the run id to a Botpress variable or tableReceipt id equals the later webhook request_id
ReceiveA webhook route in your own backend or integrationOne signed POST on agent.run.terminal
ReplySend the text or media URL back to the useroutput.text, output.images, output.videos

The request

Send this body from the card with Axios, with the key read from a secret rather than typed into the card. Use one credential header, either Authorization: Bearer or x-api-key.

Keep the instruction short and put variable data in the input object when the agent needs structured context. Sume writes it to a file the agent reads as data, rather than mixing it into the prompt, which keeps user text from rewriting your instruction.

{
  "instruction": "Write a friendly two-line reply about the order status",
  "generation_spend_cap_usd": 0.5,
  "communication": { "webhook_url": "https://example.com/hooks/sume" }
}

Handling failure

Wrap the call in try and catch and route a failure to a fallback message. Distinguish errors: a 400 invalid_request usually means the cap is missing, a 403 insufficient_scope means the key lacks agent_completions:write, and a 429 names the bucket in error.details.scope, with retry-after telling you when to try again. Writes have their own per-minute bucket by plan, so a busy bot on a free plan can hit it before a larger one would.

If the webhook never arrives, a manual GET /v1/agent-runs/{id} from a later turn returns the same receipt. A delivery failure does not change the run. Keep the cap small for chat use, because an unattended agent turn can generate media, and the cap is what stops a loop from spending more than you intended.

Finally, give each run an Idempotency-Key built from the conversation and message ids. If Botpress retries the card after a timeout, Sume returns the original receipt with idempotency_hit: true instead of starting a second, paid run.

Sources

More in Integrations

All Integrations posts

Written by Sume