惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
罗磊的独立博客
H
Help Net Security
月光博客
月光博客
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
GbyAI
GbyAI
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

Workflow SDK Documentation

Patterns for Defining Tools Human-in-the-Loop Building Durable AI Agents Queueing User Messages Resumable Streams Sleep, Suspense, and Scheduling Streaming Updates from Tools API Reference Workflow Globals Changelog Resilient run start Cookbook Building a World Deploying Astro Express Fastify Hono Getting Started NestJS Next.js Nitro Nuxt Python SvelteKit Vite corrupted-event-log fetch-in-workflow hook-conflict Errors
getStepMetadata
2026-05-31 · via Workflow SDK Documentation

Access retry attempts and timing information within step functions.

Returns metadata available in the current step function.

You may want to use this function when you need to:

  • Track retry attempts in error handling
  • Access timing information of a step and execution metadata
  • Generate idempotency keys for external APIs

This function can only be called inside a step function.

import { getStepMetadata } from "workflow";

async function testWorkflow() {
  "use workflow";
  await logStepId();
}

async function logStepId() {
  "use step";
  const ctx = getStepMetadata(); 
  console.log(ctx.stepId); // Grab the current step ID
}

Example: Use stepId as an idempotency key

import { getStepMetadata } from "workflow";

async function chargeUser(userId: string, amount: number) {
  "use step";
  const { stepId } = getStepMetadata();

  await stripe.charges.create(
    {
      amount,
      currency: "usd",
      customer: userId,
    },
    {
      idempotencyKey: `charge:${stepId}`, 
    }
  );
}

Learn more about patterns and caveats in the Idempotency guide.

Parameters

This function does not accept any parameters.

Returns

NameTypeDescription
stepNamestringThe name of the step.
stepIdstringUnique identifier for the currently executing step. Useful to use as part of an idempotency key for critical operations that must only be executed once (such as charging a customer).
stepStartedAtDateTimestamp when the current step started.
attemptnumberThe number of times the current step has been executed. This will increase with each retry.