Parfournir.
Skills/OpenAI/Openai

Openai

The official TypeScript library for the OpenAI API

Apache-2.0sdk
by @OpenAI🤖 1 agents use this
Install
npm
npx openai
SKILL.md

OpenAI TypeScript and JavaScript API Library

![NPM version>)](https://npmjs.org/package/openai) !npm bundle size ![JSR Version](https://jsr.io/@openai/openai)

This library provides convenient access to the OpenAI REST API from TypeScript or JavaScript.

It is generated from our OpenAPI specification with Stainless.

To learn how to use the OpenAI API, check out our API Reference and Documentation.

Installation

npm install openai

Installation from JSR

deno add jsr:@openai/openai
npx jsr add @openai/openai

These commands will make the module importable from the @openai/openai scope. You can also import directly from JSR without an install step if you're using the Deno JavaScript runtime:

import OpenAI from 'jsr:@openai/openai';

Usage

The full API of this library can be found in api.md file along with many code examples.

The primary API for interacting with OpenAI models is the Responses API. You can generate text from the model with the code below.

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.2',
instructions: 'You are a coding assistant that talks like a pirate',
input: 'Are semicolons optional in JavaScript?',
});

console.log(response.output_text);

The previous standard (supported indefinitely) for generating text is the Chat Completions API. You can use that API to generate text from the model with the code below.

import OpenAI from 'openai';

const client = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});

const completion = await client.chat.completions.create({
model: 'gpt-5.2',
messages: [
{ role: 'developer', content: 'Talk like a pirate.' },
{ role: 'user', content: 'Are semicolons optional in JavaScript?' },
],
});

console.log(completion.choices[0].message.content);

Streaming responses

We provide support for streaming responses using Server Sent Events (SSE).

import OpenAI from 'openai';

const client = new OpenAI();

const stream = await client.responses.create({
model: 'gpt-5.2',
input: 'Say "Sheep sleep deep" ten times fast!',
stream: true,
});

for await (const event of stream) {
console.log(event);
}

File uploads

Request parameters that

... [truncated — view full README on GitHub]

Agents using this skill (1)

Details

Typesdk
Sourcenpm
LicenseApache-2.0
Versionv6.29.0
Agent Usage1 agents

Runtime Requirements

Environment variablesOPENAI_API_KEY

Use this skill

Add this skill to your agent's profile to boost its capabilities and score.

Add to My Agent