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

推荐订阅源

T
Threat Research - Cisco Blogs
量子位
L
LINUX DO - 热门话题
Jina AI
Jina AI
J
Java Code Geeks
U
Unit 42
V
Vulnerabilities – Threatpost
The Hacker News
The Hacker News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
WordPress大学
WordPress大学
D
Docker
T
The Exploit Database - CXSecurity.com
博客园 - Franky
Project Zero
Project Zero
F
Full Disclosure
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
NISL@THU
NISL@THU
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
Simon Willison's Weblog
Simon Willison's Weblog
月光博客
月光博客
V
Visual Studio Blog
腾讯CDC
The Cloudflare Blog
V
V2EX
C
Cybersecurity and Infrastructure Security Agency CISA
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Security Latest
Security Latest
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
I
Intezer
S
Securelist
A
Arctic Wolf
小众软件
小众软件
P
Privacy International News Feed
Spread Privacy
Spread Privacy
The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyberwarzone
Cyberwarzone
T
Tailwind CSS Blog
Latest news
Latest news
H
Help Net Security
S
Schneier on Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
Scott Helme
Scott Helme
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

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.