gitmyhub

openai-node

TypeScript ★ 11k updated 3d ago

Official JavaScript / TypeScript library for the OpenAI API

The official JavaScript and TypeScript library for connecting Node.js or browser apps to OpenAI's AI models including GPT. Install with one command, then send prompts and receive responses, including streamed, piece-by-piece output.

TypeScriptJavaScriptNode.jsDenoBunsetup: easycomplexity 2/5

This is the official JavaScript and TypeScript library for working with OpenAI's API. It lets developers connect their Node.js or browser-based applications to OpenAI's AI models, including GPT, without having to write low-level network code. You install it with a single command and then call functions to send prompts and receive responses.

The library supports the two main ways OpenAI lets you generate text: the newer Responses API and the older Chat Completions API, which remains supported. Both work by sending a message to the model and getting text back. You can also request streaming responses, where the text arrives piece by piece in real time rather than all at once after a delay.

Beyond basic text generation, the library handles file uploads (for tasks like fine-tuning a model on your own data), webhook verification (so your server can confirm that incoming notifications actually came from OpenAI), and automatic retries when requests fail. It also supports authenticated access for cloud environments, meaning you can use short-lived security tokens from services like Kubernetes, Azure, or Google Cloud instead of storing a long-lived API key.

The library includes helpers for pagination, so when a request returns a long list of results you can step through pages easily. It works in Node.js, Deno, Bun, and modern browsers, and the full list of available API calls is documented in a separate file within the repository. The code itself is auto-generated from OpenAI's official API specification.

Where it fits