Skip to main content
Returns metadata about the currently executing step function, including the step ID, start time, and attempt number.

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 AsyncLocalStorage to retrieve the step context
  • The stepId is guaranteed to be unique for each step execution
  • The attempt number starts at 1 and increments with each retry
  • The stepStartedAt timestamp represents when the current attempt started, not when the step was first attempted