Registry / ai-ml / agents-sdk-openai-websocket-fetch

agents-sdk-openai-websocket-fetch

JSON →
library0.0.1jsnpmunverified

Cloudflare Workers port of ai-sdk-openai-websocket-fetch — a drop-in fetch replacement that routes OpenAI Responses API streaming requests through a persistent WebSocket connection, reducing TTFB in multi-step agentic workflows. Version 0.0.1, pre-release. Key differentiator: uses Workers-native WebSocket API instead of Node.js 'ws' package, enabling persistent connections in edge environments. Inspired by Vercel Labs' original but adapted for Workers runtime constraints. Ships TypeScript types.

npm install agents-sdk-openai-websocket-fetch
INSTALL
IMPORT
SIG · AGENTS-SDK-OPENAI-
A
agents-sdk-openai-websocket-fetch
ai-mljavascriptv0.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createWebSocketFetch
import { createWebSocketFetch } from 'agents-sdk-openai-websocket-fetch'
import createWebSocketFetch from 'agents-sdk-openai-websocket-fetch'
Named export only; default import will fail.
OpenAI
import OpenAI from 'openai'; const openai = new OpenAI({ fetch: wsFetch })
import { OpenAI } from 'openai'
OpenAI SDK default export is the class.
streamText
import { streamText } from 'ai'
import streamText from 'ai'
Named export from the 'ai' package.

Demonstrates creating a WebSocket fetch, integrating with OpenAI SDK, and streaming text with cleanup.

import { createWebSocketFetch } from 'agents-sdk-openai-websocket-fetch'; import { streamText } from 'ai'; import { createOpenAI } from '@ai-sdk/openai'; const wsFetch = createWebSocketFetch(); const openai = createOpenAI({ fetch: wsFetch }); const result = streamText({ model: openai('gpt-4.1-mini'), prompt: 'Hello!', onFinish: () => wsFetch.close(), }); for await (const chunk of result.textStream) { console.log(chunk); }
Debug
Known issues
breakingRequires Cloudflare Workers runtime — does not work in Node.js or browsers.
fix
Run in a Cloudflare Worker environment or use the original Node.js package ai-sdk-openai-websocket-fetch.
affects: >=0.0.1
gotchaMust call wsFetch.close() after use to avoid dangling connections and potentially exhausting Workers WebSocket limits.
fix
Add onFinish handler as shown in quickstart.
affects: >=0.0.1
gotchaOnly OpenAI Responses API streaming requests (POST /v1/responses with stream: true) are routed via WebSocket. Other requests fall through to global fetch.
fix
Ensure your OpenAI client uses the Responses API endpoint.
affects: >=0.0.1
deprecatedPackage is pre-release (v0.0.1); API may change without notice.
fix
Pin to exact version in production.
affects: 0.0.1
Errors
Common errors & fixes
ReferenceError: WebSocket is not defined
Running outside Cloudflare Workers (e.g., Node.js or browser).
fix
Use a Cloudflare Worker environment. For Node.js, use the original ai-sdk-openai-websocket-fetch package.
TypeError: createWebSocketFetch is not a function
Incorrect import (default import instead of named import).
fix
Use `import { createWebSocketFetch } from 'agents-sdk-openai-websocket-fetch'`.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
38 hits · last 30 days
node
28
OpenAI (training)
2
Resources
agents-sdk-openai-websocket-fetch — npm install agents-sdk-openai-websocket-fetch · libregistry