@vercel/ai-sdk-openai-websocket-fetch
v1.0.0
Published
WebSocket transport for the AI SDK OpenAI provider — drop-in fetch replacement that routes streaming requests through a persistent WebSocket connection.
Downloads
88
Maintainers
Readme
ai-sdk-openai-websocket-fetch
Drop-in fetch replacement that routes OpenAI Responses API streaming requests through a persistent WebSocket connection instead of HTTP.
Installation
npm install ai-sdk-openai-websocket-fetchUsage
import { streamText } from 'ai';
import { createOpenAI } from '@ai-sdk/openai';
import { createWebSocketFetch } from 'ai-sdk-openai-websocket-fetch';
const wsFetch = createWebSocketFetch();
const openai = createOpenAI({ fetch: wsFetch });
const result = streamText({
model: openai('gpt-4.1-mini'),
prompt: 'Hello!',
onFinish: () => wsFetch.close(),
});Why?
OpenAI's WebSocket API keeps a persistent connection open. After the initial handshake, subsequent requests skip TCP/TLS/HTTP negotiation entirely — reducing TTFB in multi-step agentic workflows where the model makes many tool calls.
License
MIT
