openai/openai-node: Official JavaScript / TypeScript library for the OpenAI API

3 phút đọc

openai/openai-node: Official JavaScript / TypeScript library for the OpenAI API – Repository openai/openai-node. Mô tả: Official JavaScript / TypeScript library for the OpenAI API. 11207 stars, 1614 forks, ngôn ngữ chính TypeScript, cập nhật 2026-10-07.

1. Repository làm gì?

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

It is generated from our OpenAPI specification.

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

Deno can import the package directly from npm:

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.

2. Dữ liệu và cấu trúc đáng chú ý

When you manage Responses API conversation history manually, preserve output items in order. Filtering response.output to messages can drop required reasoning or tool-call items and cause the next request to fail.

Use the SDK's toResponseInputItems() helper to normalize all replayable output items before adding them to the next request. For simple continuation, you can pass previous_response_id instead.

See the manual conversation state example and conversation state guide.

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.

Use the Responses API to analyze images and generate text about visual content.

Workload Identity Authentication

For secure, automated environments like cloud-managed Kubernetes, Azure, and GCP, you can use workload identity authentication with short-lived tokens from cloud identity providers instead of long-lived API keys.

3. Khả năng ứng dụng và giới hạn

The workloadIdentity parameter is mutually exclusive with apiKey.

For subject-token workload identity, the required fields are identityProviderId, serviceAccountId, and provider. X.509 workload identity instead uses an enrolled client certificate and its separately configured transport.

Kubernetes (service account tokens)

You can also customize the subject-token refresh buffer (default is 1200 seconds (20 minutes) before expiration; the effective buffer is capped at half of the actual token lifetime):

Applications enrolled for X.509 workload identity can authenticate using a certificate-backed credential instead of a subject-token provider or API key. This Node.js-only integration requires the optional undici peer and currently supports only the global https://mtls.api.openai.com/v1 API endpoint.

The SDK owns the credential's verified TLS transport, caches short-lived tokens in memory, isolates certificate generations, and bounds retries and cancellation. Set refreshBufferSeconds on the credential to configure proactive refresh; it defaults to 1,200 seconds (20 minutes) and is capped at half of the token's lifetime. For CONNECT proxies, encrypted private keys, live verification, and certificate rotation, see the X.509 workload-identity example.

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

Request parameters that correspond to file uploads can be passed in many different forms:

Verifying webhook signatures is optional but encouraged.

Số liệu repository có thể thay đổi; nên mở liên kết nguồn để kiểm tra README, giấy phép và trạng thái phát hành.

Nguồn tham khảo: Xem bài gốc

📅 Âm: 4/10 · Canh Dần

📅 Lịch Âm Dương NsN

×
Hôm Nay · Thứ Năm
Âm Lịch: 4 Tháng 10
Năm Bính Ngọ
📌 Can Chi: Canh Dần
✨ Hoàng Đạo: Tý (23-1), Sửu (1-3), Thìn (7-9), Tỵ (9-11), Mùi (13-15), Tuất (19-21)
Vĩnh Phúc (Liên Bảo - Vĩnh Yên)
31°C
Nắng Đẹp
💧 83% | 💨 18 km/h
Hôm nay 32°
02/11 28°
03/11 30°
04/11 31°
05/11 31°