Signature
Returns
StepMetadata
Metadata about the current step.
Usage
Basic Usage
Get step metadata inside a step function:Idempotency Key
Use the step ID as an idempotency key for critical operations:Retry Tracking
Track retry attempts:Conditional Logic Based on Attempts
Adjust behavior based on retry count:Logging with Step Context
Include step metadata in logs:Unique File Names
Generate unique file names per step:Combining with Workflow Metadata
Use both step and workflow metadata:Calculate Step Duration
Track how long a step has been running:Notes
- Can only be called inside a step function (with
"use step") - Throws an error if called from a workflow function
- Uses
AsyncLocalStorageto retrieve the step context - The
stepIdis guaranteed to be unique for each step execution - The
attemptnumber starts at 1 and increments with each retry - The
stepStartedAttimestamp represents when the current attempt started, not when the step was first attempted
Related
- getWorkflowMetadata - Get workflow run metadata
- RetryableError - Control step retry behavior
- getWritable - Get a writable stream for the workflow