openai-node  by openai

TypeScript/JavaScript SDK for the OpenAI API

created 3 years ago
9,525 stars

Top 5.3% on sourcepulse

GitHubView on GitHub
Project Summary

This library provides a robust and officially supported JavaScript/TypeScript interface for interacting with the OpenAI API. It's designed for developers building applications that leverage OpenAI's language models, offering convenient access to features like text generation, streaming responses, file uploads, and error handling.

How It Works

The library is generated directly from OpenAI's OpenAPI specification using Stainless, ensuring fidelity to the API's structure. It supports both the newer "Responses" API for text generation and the established "Chat Completions" API. Key features include automatic retries for transient errors, configurable timeouts, and support for Server-Sent Events (SSE) for streaming responses.

Quick Start & Requirements

  • Install via npm: npm install openai
  • Install via JSR: deno add jsr:@openai/openai or npx jsr add @openai/openai
  • Supported runtimes: Node.js 18+, Deno 1.28+, Bun 1.0+, Cloudflare Workers, Vercel Edge Runtime, Jest 28+, Nitro 2.6+. Browser support requires dangerouslyAllowBrowser: true.
  • Browser support is disabled by default due to security risks of exposing API keys.

Highlighted Details

  • Supports both Responses and Chat Completions APIs.
  • Handles file uploads via fs.ReadStream, File objects, fetch Responses, or a toFile helper.
  • Provides detailed error handling with specific APIError subclasses.
  • Features automatic pagination for list methods and configurable retry logic.
  • Includes a beta Realtime API for low-latency, multi-modal conversational experiences via WebSockets.
  • Offers an AzureOpenAI class for Azure OpenAI service integration.

Maintenance & Community

  • Actively maintained by OpenAI.
  • Feedback and issues can be raised on GitHub.

Licensing & Compatibility

  • MIT License.
  • Compatible with commercial and closed-source applications.

Limitations & Caveats

  • Browser support requires explicit enabling (dangerouslyAllowBrowser: true) and carries security risks if API keys are exposed client-side.
  • React Native is not currently supported.
  • The Azure API integration notes that static types may not always be perfectly accurate due to API shape differences.
Health Check
Last commit

3 days ago

Responsiveness

1 day

Pull Requests (30d)
25
Issues (30d)
22
Star History
460 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.