Skip to content

Run State — api.runStore

api.runStore lets you persist values between steps within the same run. All keys are scoped to the current run and are deleted automatically when the run completes.

MethodDescription
api.runStore.get(key)Read a stored value (returns null if not set)
api.runStore.set(key, value)Write any JSON-serialisable value
api.runStore.push(key, item)Append an item to an ordered list
api.runStore.increment(key, delta?)Atomically increment a counter (default delta: 1)
api.runStore.delete(key)Remove a key
class Workflow {
async start(data, headers, api) {
// Store the customer ID before scheduling the next step
await api.runStore.set('customerId', data.customer.id);
await api.scheduleNextStep({
delay: 10,
action: 'sendEmail',
payload: {},
});
}
async sendEmail(data, headers, api) {
// Retrieve the value stored in the previous step
const customerId = await api.runStore.get('customerId');
api.log('Sending to customer:', customerId);
}
}

Collecting results across fan-out branches

Section titled “Collecting results across fan-out branches”

api.runStore.push() is safe to call from concurrent parallel branches — all items are stored in order:

class Workflow {
async start(data, headers, api) {
// Fan out — schedule one branch per line item
for (const item of data.line_items) {
await api.scheduleNextStep({
delay: 10,
action: 'processItem',
payload: { item },
});
}
}
async processItem({ item }, headers, api) {
// Each parallel branch pushes its result
await api.runStore.push('results', { id: item.id, status: 'done' });
}
}

api.runStore.increment() is safe for concurrent fan-out use. The optional second argument adds or subtracts that delta:

const newCount = await api.runStore.increment('processedCount');
// Decrement:
const newCount = await api.runStore.increment('processedCount', -1);

The method returns the new value after the increment.