OpenAI
Official TypeScript SDK for accessing OpenAI APIs including GPT and embeddings.
Model SDKsNPM
3. Used by agents' projects
Dependency in 286 public GitHub projects set up for AI coding agents that we scanned (4.6%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
platform.openai.com/docs/llms.txtFrom the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What OpenAI does
This is OpenAI's own TypeScript/JavaScript client, generated from the API's OpenAPI spec. Beyond model calls it ships retries, per-status error classes, webhook signature checks, and auth with short-lived tokens from cloud identity providers.
OpenAI popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How OpenAI is used
- OpenAI is a dependency in 286 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (5.9% of the 4,867 JavaScript/TypeScript ones), #1 of 92 in model sdks.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,397; those are left out of every share on this page.
- The most used alternative in our scan is Anthropic SDK (238 projects).
- Projects that use it most often also use dotenv (58.0%), Zod (60.8%), TypeScript (88.8%).
- It is more common in projects set up for Continue (14.3%) than for OpenAI Codex (2.1%).
By coding agent
Often used with
OpenAI in practice
Strengths
Connection errors, 408, 409, 429 and 5xx responses are retried twice with a short exponential backoff. The <code>maxRetries</code> option configures or disables this, either on the client or on a single request.
Failures throw subclasses of <code>APIError</code>, such as <code>RateLimitError</code> for 429 and <code>AuthenticationError</code> for 401. The README's example reads <code>requestID</code>, <code>status</code> and <code>headers</code> from the caught error.
Object responses carry a <code>_request_id</code> property taken from the <code>x-request-id</code> header. For streams, <code>.withResponse()</code> returns the ID next to the data.
The client accepts a <code>workloadIdentity</code> option, which is mutually exclusive with <code>apiKey</code>. The SDK ships token providers for Kubernetes service accounts, Azure managed identity and GCP. You can also supply your own JWT provider.
Watch out for
If you keep only the message items from <code>response.output</code>, you can drop reasoning or tool-call items, and the next request may fail. The README points to <code>toResponseInputItems()</code>, or to <code>previous_response_id</code> for simple continuation.
By default a request times out after 10 minutes, and you can change this with the <code>timeout</code> option. The README notes that timed-out requests are also retried twice by default.
Certificate-based workload identity needs the optional <code>undici</code> peer. It currently supports only the global <code>https://mtls.api.openai.com/v1</code> endpoint.
Generate text with the Responses API
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});
const response = await client.responses.create({
model: 'gpt-5.5',
instructions: 'You are a coding assistant that talks like a pirate',
input: 'Are semicolons optional in JavaScript?',
});
console.log(response.output_text);More about OpenAI
Agent Skills for it
- : Skills Catalog for Codex
- openai-docs: Use when the user asks how to build with OpenAI products or APIs and needs up-to-date official documentation with citations (for example: Co
- openai-tts: OpenAI Text-to-Speech API for high-quality speech synthesis. Use for generating natural-sounding audio from text with customizable voices an
- openai: Check OpenAI API access and list the models your key can use. Read-only. Trigger phrases: openai, openai models, what models do I have acces
- openai-frontend-design: This skill should be used when the user asks for "visual concepts", "image-led website design", or "concept fidelity". Create visual concept
Head to head
- OpenAI vs Anthropic SDK used together in 88 projects
- OpenAI vs Google Generative AI used together in 51 projects
Packages around it
- dotenv: Env file loader
- zod: Schema validation
- typescript: Typed JavaScript
- next: React framework
- tailwindcss: Utility CSS
- lucide-react: Icon components
Alternatives
OpenAI This page
Official TypeScript SDK for calling Claude API and building agent applications.
Official SDK for Google Gemini API to build AI-powered applications.
Official JavaScript client library for Ollama to run and interact with local language models.
Official TypeScript SDK for calling Groq's fast language models API.
Official TypeScript SDK for calling Mistral's language models and APIs.
JavaScript client library for calling Replicate's AI model API.
Get started
Install it.
npm install openaiRules for your agent
## OpenAI (openai)
- Use the Responses API (`client.responses.create`) for new code. The README calls Chat Completions the previous standard, which is still supported indefinitely.
- The client reads `OPENAI_API_KEY` by default, so `apiKey` can be omitted. `workloadIdentity` and `apiKey` are mutually exclusive, so pass only one.
- When replaying conversation history by hand, pass the output through `toResponseInputItems()` instead of filtering it to messages. For simple continuation, use `previous_response_id`.
- In webhook handlers, pass the raw request text (not parsed JSON) to `client.webhooks.unwrap()` or `verifySignature()`, and `await` it before trusting the event.
- Catch `OpenAI.APIError` and branch on subclasses such as `RateLimitError`. Log `err.requestID`, or `response._request_id` on successful object responses.
- Retries (2 by default) and the timeout (10 minutes by default) are set with `maxRetries` and `timeout`, on the client or per request.
- Use `toStreamingFile()` instead of `toFile()` when uploading a stream, because `toFile()` buffers stream inputs.