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

推荐订阅源

L
LangChain Blog
Engineering at Meta
Engineering at Meta
S
Securelist
M
MIT News - Artificial intelligence
GbyAI
GbyAI
O
OpenAI News
W
WeLiveSecurity
T
Troy Hunt's Blog
L
LINUX DO - 最新话题
博客园_首页
C
Check Point Blog
Martin Fowler
Martin Fowler
The Last Watchdog
The Last Watchdog
量子位
Cloudbric
Cloudbric
S
SegmentFault 最新的问题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
Forbes - Security
Forbes - Security
雷峰网
雷峰网
H
Heimdal Security Blog
P
Palo Alto Networks Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Y
Y Combinator Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
博客园 - 聂微东
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
Help Net Security
Help Net Security
U
Unit 42
N
News and Events Feed by Topic
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
TaoSecurity Blog
TaoSecurity Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
Jina AI
Jina AI
美团技术团队
L
LINUX DO - 热门话题
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
Security Latest
Security Latest
S
Secure Thoughts
Microsoft Azure Blog
Microsoft Azure Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
P
Privacy International News Feed
博客园 - 司徒正美

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 hook-conflict Errors node-js-module-in-workflow serialization-failed start-invalid-workflow-function step-not-registered timeout-in-workflow webhook-invalid-respond-with-value webhook-response-not-sent workflow-not-registered Errors & Retrying Hooks & Webhooks Idempotency Foundations Serialization Starting Workflows Streaming Versioning Workflows and Steps How the Directives Work Encryption Event Sourcing Framework Integrations Understanding Directives Migration Guides Migrating from AWS Step Functions Migrating from Inngest Migrating from Temporal Observability Testing Server-Based Testing createHook createWebhook defineHook FatalError fetch getStepMetadata getWorkflowMetadata getWritable workflow RetryableError sleep @workflow/vitest DurableAgent @workflow/ai WorkflowChatTransport getHookByToken getRun getWorld workflow/api resumeHook resumeWebhook Chat Session Modeling runtime-decryption-failed Upgrading Workflows abort-signal-timeout-in-workflow Cancellation How Cancellation Works Internal Serializable AbortController and AbortSignal Eager Processing of Steps & Incremental Event Replay TanStack Start Agent Cancellation Sequential & Parallel Execution Workflow Composition Local World | Workflow SDK Postgres World | Workflow SDK Vercel World | Workflow SDK Migrating from trigger.dev Secure Credential Handling Local World | Workflow SDK Postgres World | Workflow SDK Vercel World | Workflow SDK
fetch-in-workflow
2026-05-31 · via Workflow SDK Documentation

Use the workflow fetch step function instead of global fetch in workflows.

This error occurs when you try to use fetch() directly in a workflow function, or when a library (like the AI SDK) tries to call fetch() under the hood.

Global "fetch" is unavailable in workflow functions. Use the "fetch" step function from "workflow" to make HTTP requests.

Workflow functions run in a sandboxed environment without direct access to fetch().

Many libraries make HTTP requests under the hood. For example, the AI SDK's generateText() function calls fetch() to make HTTP requests to AI providers. When these libraries run inside a workflow function, they fail because the global fetch is not available.

Import the fetch step function from the workflow package and assign it to globalThis.fetch inside your workflow function. This version of fetch is a step function that wraps the standard fetch API, automatically handling serialization and providing retry capabilities. This will also make fetch() available to all functions and libraries in the current workflow function.

Before:

import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

export async function chatWorkflow(prompt: string) {
  "use workflow";

  // Error - generateText() calls fetch() under the hood
  const result = await generateText({ 
    model: openai("gpt-4"), 
    prompt, 
  }); 

  return result.text;
}

After:

import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { fetch } from "workflow"; 

export async function chatWorkflow(prompt: string) {
  "use workflow";

  globalThis.fetch = fetch; 

  // Now generateText() can make HTTP requests via the fetch step
  const result = await generateText({
    model: openai("gpt-4"),
    prompt,
  });

  return result.text;
}

AI SDK Integration

This is the most common scenario - using AI SDK functions that make HTTP requests:

import { generateText, streamText } from "ai";
import { openai } from "@ai-sdk/openai";
import { fetch } from "workflow"; 

export async function aiWorkflow(userMessage: string) {
  "use workflow";

  globalThis.fetch = fetch; 

  // generateText makes HTTP requests to OpenAI
  const response = await generateText({
    model: openai("gpt-4"),
    prompt: userMessage,
  });

  return response.text;
}

Direct API Calls

You can also use the fetch step function directly for your own HTTP requests:

import { fetch } from "workflow";

export async function dataWorkflow() {
  "use workflow";

  // Use fetch directly for HTTP requests
  const response = await fetch("https://api.example.com/data"); 
  const data = await response.json();

  return data;
}

For more details on the fetch step function, see the fetch API reference.