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

推荐订阅源

WordPress大学
WordPress大学
爱范儿
爱范儿
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
P
Palo Alto Networks Blog
博客园 - 司徒正美
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
美团技术团队
罗磊的独立博客
阮一峰的网络日志
阮一峰的网络日志
The Register - Security
The Register - Security
D
DataBreaches.Net
A
Arctic Wolf
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Privacy & Cybersecurity Law Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog
V
Vulnerabilities – Threatpost
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
GbyAI
GbyAI
Recent Announcements
Recent Announcements
T
The Blog of Author Tim Ferriss
Simon Willison's Weblog
Simon Willison's Weblog
Cyberwarzone
Cyberwarzone
C
Cisco Blogs
G
GRAHAM CLULEY
宝玉的分享
宝玉的分享
T
Threat Research - Cisco Blogs
C
Check Point Blog
W
WeLiveSecurity
F
Fortinet All Blogs
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
月光博客
月光博客
Project Zero
Project Zero
Know Your Adversary
Know Your Adversary
V
Visual Studio Blog
H
Help Net Security
H
Hacker News: Front Page
Webroot Blog
Webroot Blog
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
O
OpenAI News
The Cloudflare Blog
Attack and Defense Labs
Attack and Defense Labs

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.