TS module for querying OpenAI's API in edge environments
Top 99.7% on sourcepulse
This module provides a lightweight, TypeScript-based client for querying OpenAI's API, specifically designed for edge environments like Next.js Edge API Routes. It replaces the official openai
module's axios
dependency with the native fetch
API, reducing bundle size and enabling faster, stream-friendly interactions.
How It Works
The library leverages the standard fetch
API for all HTTP requests to OpenAI endpoints. This approach is advantageous for edge runtimes, which often lack broad Node.js compatibility but have robust fetch
implementations. It also supports streaming responses directly to clients, a key feature for interactive AI applications. The module includes type assertions for response data using ResponseTypes
to ensure type safety.
Quick Start & Requirements
npm install openai-edge
or yarn add openai-edge
fetch
implementation (available in modern Node.js v18+, browsers, and edge runtimes) and FormData
(Node.js v18+).Configuration
and OpenAIApi
from openai-edge
.Highlighted Details
openai
module, aiming for feature parity with v3.3.0.fetch
and FormData
APIs.Maintenance & Community
The project is maintained by dan-kwiat. No specific community channels or roadmap links are provided in the README.
Licensing & Compatibility
The module is licensed under the MIT License, permitting commercial use and integration with closed-source projects.
Limitations & Caveats
As of November 2023, the official openai
library (v4) has adopted fetch
for edge runtimes, potentially making this module redundant. Migration involves changing imports from 'openai-edge'
to 'openai'
. The README does not specify compatibility with older Node.js versions lacking global fetch
or FormData
without polyfills.
3 months ago
1 week