OpenAICloudflare Developer PlatformJul 9, 2026, 12:00 PM

Workflows - Workflows now supports delay functions when retrying

A condensed section focused on the key takeaways first.

Original Post

Quick Digest

Summary

A condensed section focused on the key takeaways first.

openaienmodel: gpt-5-mini-2025-08-07

Workflows now supports delay functions when retrying

Key Points

  • retries.delay accepts a function
  • Function receives ctx and error
  • Return string, number, or Promise for duration

Summary

Workflows step retries can now accept a dynamic delay function via retries.delay. Instead of only fixed durations and static backoff strategies (constant, linear, exponential), you can supply a function that computes the next delay based on the retry context and the thrown error. This enables adaptive retry timing (for example, longer waits for rate-limit errors and shorter for transient network glitches) and can consume downstream guidance such as Retry-After headers.

Key Points

  • Use retries.delay: ({ ctx, error }) => … to compute delays dynamically.
  • The delay function may return a duration string (e.g. "10 seconds"), a number, or a Promise that resolves to a duration.
  • You still have existing backoff options, but delay functions let you add conditional logic (e.g. if (error.message.includes("rate limit")) return ${ctx.attempt * 30} seconds;).
  • Practical uses: respect API Retry-After, escalate wait times for rate limits, shorten waits for transient errors, or implement custom per-provider retry policies.
  • This avoids adding external queueing/scheduling just to vary retry timing.

See the "Sleeping and retrying" docs for exact duration formats and runtime behavior.

Full Translation

Translations

A translation section that keeps the flow of the original article.

openaijamodel: gpt-5-mini-2025-08-07

Workflows - 再試行時に遅延関数をサポート

Workflows — 再試行時に遅延関数をサポート

Workflows では、各ステップの組み込み再試行動作を構成できます。従来は秒・分・時間などの固定遅延や、constant、linear、exponential といったバックオフ戦略を設定できました。ステップの再試行は、動的な遅延関数をサポートするようになりました。

retries.delay に関数を渡すことで、単にベース遅延とバックオフ戦略を選ぶ代わりに、失敗した試行(attempt)や投げられた error から次の遅延を計算できます。これにより、再試行の動作を障害の種類に応じて調整できます。たとえば、レート制限エラーの後は長めに待ち、短時間のネットワーク障害の後は早めに再試行する、という処理が可能です。下流 API がエラー内で Retry-After 値を返すような場合にも、遅延関数でその指示に従わせることができます。

JavaScript

await step.do("sync customer", {
  retries: {
    limit: 5,
    delay: ({ ctx, error }) => {
      if (error.message.includes("rate limit")) {
        return `${ctx.attempt * 30} seconds`;
      }
      return "10 seconds";
    },
  },
}, async () => {
  await syncCustomer();
});

TypeScript

await step.do("sync customer", {
  retries: {
    limit: 5,
    delay: ({ ctx, error }) => {
      if (error.message.includes("rate limit")) {
        return `${ctx.attempt * 30} seconds`;
      }
      return "10 seconds";
    },
  },
}, async () => {
  await syncCustomer();
});

ポイント

  • 動的な遅延関数は、duration の文字列(例: "10 seconds")、数値、または duration に解決する Promise を返すことができます。
  • 再試行ロジックを別にキューやスケジューラで実装することなく、適応的な再試行を実現できます。

詳細は Sleeping and retrying を参照してください。