Concepts
API keys and variables
An environment API key lets an app start and read runs in one environment. Variables are encrypted values, such as secrets, that every run in the environment receives.
On this page
API keys#
An environment API key is what your app holds. It looks like this:
bjk_prod_<32 hex characters>_<64 hex characters>The part after bjk_ names the environment: dev, staging, prod or preview. Every run the key starts lands in that environment and runs its current deployment.
What a key can do#
In its own environment, a key can:
- Start runs, one at a time or in a batch.
- List, read, cancel, reschedule and follow runs, send them events, and retry a failed workflow from failure.
- Create and manage schedules, and read queues.
- Mint public access tokens that let a web page follow one run.
- List the environment's tasks with
GET /v1/tasks.
A run of another environment answers 404, exactly like a run that does not exist. Every other route, such as variables, keys or workers, answers 403.
A key cannot run another deployment's code: naming any deployment_id other than the environment's current one answers 404. So a prod key can never run a preview's code with production's variables.
Create, list and revoke keys#
Create a key with the CLI. The token is shown once, when you create it. Bok Joy keeps only its SHA-256 hash, and records when the key was last used.
durable-compute api-keys create --env prod --name "billing app"durable-compute api-keys list --env proddurable-compute api-keys revoke <key id>A name is 1 to 64 printable characters. Managing keys needs the operator token, or the personal access token of a member of the key's project. During the alpha, the Bok Joy team creates your first keys.
The operator token#
The operator token is the control plane's administrator credential. It can do everything, in every environment, including managing keys, variables, deployments and workers. Apps should never hold it. Use an environment API key instead.
Variables#
Variables are the values your task code reads from its environment: API keys for other services, connection strings, feature switches. Each environment has its own set.
const stripe = new Stripe(process.env.STRIPE_KEY);Set a variable#
Set a variable with the CLI, with a personal access token or the operator token. The value comes from standard input or a file, never from the command line, so it stays out of your shell history:
printf '%s' "$STRIPE_KEY" | durable-compute variables set STRIPE_KEY --env proddurable-compute variables list --env proddurable-compute variables delete STRIPE_KEY --env prodValues are write-only. No route, command or page ever shows a value again: list returns names only.
How runs receive them#
- A run keeps the values it started with. Bok Joy snapshots the variables when it accepts the run. Its retries, its workflow steps and its children see those same values. A change reaches runs triggered after it.
- They arrive as environment variables. The SDK runner sets them before it imports your module, so module-level code can read them.
- They stay out of logs. Values travel to the runner inside the attempt's input, never as container settings or command-line arguments. Your own code can still print them, so don't.
- Previews inherit staging. A preview gets staging's value for every name it does not set itself. Deleting a preview's own value brings staging's back.
Bok Joy encrypts every value with XChaCha20-Poly1305, bound to its environment and name.
What else your task's environment holds#
Your task starts with a nearly empty environment. Nothing from the machine it runs on is passed through. Besides your variables, it holds:
- A fixed
PATH, andPYTHONPATHfor a Python task. BOKJOY_ENVIRONMENT: the run's environment,dev,staging,prodorpreview/<branch>. The same asctx.environment.slug.BOKJOY_DEPLOYMENT_ID: the deployment the attempt runs.BOKJOY_WORKER_ID, when the attempt runs on a worker: the worker's ID, the sameworkerId(worker_id) the attempt reports. Use it to tell which worker ran what.
These three names are reserved, so no variable of yours can replace them.
console.log(`converted batch 7 on ${process.env.BOKJOY_WORKER_ID ?? 'this machine'}`);Rules#
| Rule | Limit |
|---|---|
| Name | 1 to 128 characters of A-Z, a-z, 0-9 and _, not starting with a digit |
| Reserved names | PATH, HOME, NODE_OPTIONS, PYTHONPATH, PYTHONHOME, BOKJOY_ENVIRONMENT, BOKJOY_DEPLOYMENT_ID, BOKJOY_WORKER_ID, and any name starting with DC_, LD_ or DYLD_, in any case |
| Value | At most 16 KiB |
| Per environment | At most 100 variables |
| Per run | At most 256 KiB in all, as JSON. A write that would push a run past it is refused. |