Skip to content

Triggering from your app

Set up the client

Any backend can start a Bok Joy task and read its result. Point the client at a control plane, give it an environment API key, and call tasks.trigger.

On this page

The trigger client is part of the SDK. It runs in any Node or Python backend: a web app, a queue consumer, a cron job, a script. Your app holds an environment API key, and the key decides where runs go: every run uses that environment's current deployment and variables.

import { tasks } from '@bokjoy/sdk'; await tasks.trigger('email.send', { email, template: 'welcome' });

Install#

During the private alpha, install the SDK from a checkout of the Bok Joy repository (Installation):

npm install /path/to/bokjoy/sdk/node

The Node client is an ES module and needs Node 24 or later. The Python client needs Python 3.10 or later, uses only the standard library, and is synchronous.

Configure with environment variables#

The client reads two variables:

VariableValue
BOKJOY_API_URLThe control plane: https://api.bokjoy.dev for the hosted alpha. Default: http://127.0.0.1:19847, a local control plane.
BOKJOY_API_KEYAn environment API key, such as bjk_prod_....
Terminal
export BOKJOY_API_URL=https://api.bokjoy.devexport BOKJOY_API_KEY=bjk_prod_...

The shared tasks and runs read them on every call, so you can set them any time before the first one.

Configure in code#

configure sets options for the shared tasks and runs. Anything left out still comes from the environment. To use several keys at once, for example one per environment, make a client for each:

import { BokJoy, configure } from '@bokjoy/sdk'; configure({  url: 'https://api.bokjoy.dev',  apiKey: process.env.PROD_KEY,}); const staging = new BokJoy({  apiKey: process.env.STAGING_KEY,  timeoutMs: 10_000,  maxRetries: 1,});await staging.tasks.trigger('email.send', payload);
NodePythonDefault
urlurlBOKJOY_API_URL, then http://127.0.0.1:19847
apiKeyapi_keyBOKJOY_API_KEY
timeoutMstimeout (seconds)30 seconds per request
maxRetriesmax_retries2, from 0 to 10

Retries#

The client retries a request after a network failure, a timeout, or a 408, 425, 429 or 5xx answer, up to maxRetries times. It honors Retry-After up to 10 seconds.

A retried trigger sends the same idempotency key as the first try, so a retry never starts a second run, even when the first request reached the control plane and only the answer was lost. See Idempotency.

Security#

The key travels with every request, so the client protects it:

  • HTTPS only, except to this machine (localhost, 127.x.x.x or ::1) or a private network address (a *.internal host or an fdaa: address). Any other http:// URL is refused before a request is sent.
  • No redirects. A redirect would carry the key to wherever it points, so the client never follows one. Set the URL to the address the control plane serves on.
  • No proxy for plain HTTP. Python never sends a plain http:// request through HTTP_PROXY. Node's fetch uses a proxy only when NODE_USE_ENV_PROXY=1 or --use-env-proxy is set, and then the client refuses a plain http:// call unless NO_PROXY names the host.
  • Errors never contain the key.

Older variable names#

Before the SDK was renamed, the client read DC_API_URL and DC_API_TOKEN. It still does, as a pair, but only when no URL or key is set in code and neither BOKJOY_ variable is set. New apps should use the BOKJOY_ names.