openai-edge  by dan-kwiat

TS module for querying OpenAI's API in edge environments

created 2 years ago
252 stars

Top 99.7% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

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

  • Install: npm install openai-edge or yarn add openai-edge
  • Prerequisites: Requires a global fetch implementation (available in modern Node.js v18+, browsers, and edge runtimes) and FormData (Node.js v18+).
  • Usage: Import Configuration and OpenAIApi from openai-edge.

Highlighted Details

  • Drop-in replacement for the official openai module, aiming for feature parity with v3.3.0.
  • Supports Azure OpenAI Service with custom headers and query parameters.
  • Includes examples for Next.js Edge API Routes demonstrating streaming chat, text completion, and image generation.
  • Zero external dependencies beyond the global 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.

Health Check
Last commit

3 months ago

Responsiveness

1 week

Pull Requests (30d)
0
Issues (30d)
0
Star History
0 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.