Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update dependency openai to v4.76.3 #222

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Dec 18, 2024

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
openai 4.76.0 -> 4.76.3 age adoption passing confidence

Release Notes

openai/openai-node (openai)

v4.76.3

Compare Source

Full Changelog: v4.76.2...v4.76.3

Chores
  • internal: better ecosystem test debugging (86fc0a8)
Documentation

v4.76.2

Compare Source

Full Changelog: v4.76.1...v4.76.2

Chores

v4.76.1

Compare Source

Full Changelog: v4.76.0...v4.76.1

Chores

Configuration

📅 Schedule: Branch creation - "* 0-4 * * 3" (UTC), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@brave brave deleted a comment from github-actions bot Dec 19, 2024
@brave brave deleted a comment from github-actions bot Dec 19, 2024
@brave brave deleted a comment from github-actions bot Dec 19, 2024
@renovate renovate bot force-pushed the renovate/openai-4.x-lockfile branch from 4fd9893 to 49b8850 Compare December 19, 2024 18:42
@renovate renovate bot changed the title fix(deps): update dependency openai to v4.76.3 fix(deps): update dependency openai to v4.76.2 Dec 19, 2024
Copy link

openai debug - [puLL-Merge] - openai/[email protected]

Diff
diff --git .release-please-manifest.json .release-please-manifest.json
index 1cc8c9627..47a7d26b6 100644
--- .release-please-manifest.json
+++ .release-please-manifest.json
@@ -1,3 +1,3 @@
 {
-  ".": "4.76.0"
+  ".": "4.76.2"
 }
diff --git CHANGELOG.md CHANGELOG.md
index e68b45e8a..27946ddea 100644
--- CHANGELOG.md
+++ CHANGELOG.md
@@ -1,5 +1,23 @@
 # Changelog
 
+## 4.76.2 (2024-12-12)
+
+Full Changelog: [v4.76.1...v4.76.2](https://github.com/openai/openai-node/compare/v4.76.1...v4.76.2)
+
+### Chores
+
+* **internal:** update isAbsoluteURL ([#1223](https://github.com/openai/openai-node/issues/1223)) ([e908ed7](https://github.com/openai/openai-node/commit/e908ed759996fb7706baf46d094fc77419423971))
+* **types:** nicer error class types + jsdocs ([#1219](https://github.com/openai/openai-node/issues/1219)) ([576d24c](https://github.com/openai/openai-node/commit/576d24cc4b3d766dfe28a6031bdc24ac1b711655))
+
+## 4.76.1 (2024-12-10)
+
+Full Changelog: [v4.76.0...v4.76.1](https://github.com/openai/openai-node/compare/v4.76.0...v4.76.1)
+
+### Chores
+
+* **internal:** bump cross-spawn to v7.0.6 ([#1217](https://github.com/openai/openai-node/issues/1217)) ([c07ad29](https://github.com/openai/openai-node/commit/c07ad298d58e5aeaf816ee3de65fd59bf3fc8b66))
+* **internal:** remove unnecessary getRequestClient function ([#1215](https://github.com/openai/openai-node/issues/1215)) ([bef3925](https://github.com/openai/openai-node/commit/bef392526cd339f45c574bc476649c77be36c612))
+
 ## 4.76.0 (2024-12-05)
 
 Full Changelog: [v4.75.0...v4.76.0](https://github.com/openai/openai-node/compare/v4.75.0...v4.76.0)
diff --git jsr.json jsr.json
index 2c6820969..101edee15 100644
--- jsr.json
+++ jsr.json
@@ -1,6 +1,6 @@
 {
   "name": "@openai/openai",
-  "version": "4.76.0",
+  "version": "4.76.2",
   "exports": "./index.ts",
   "publish": {
     "exclude": [
diff --git package.json package.json
index fae301ee7..53b82f070 100644
--- package.json
+++ package.json
@@ -1,6 +1,6 @@
 {
   "name": "openai",
-  "version": "4.76.0",
+  "version": "4.76.2",
   "description": "The official TypeScript library for the OpenAI API",
   "author": "OpenAI <[email protected]>",
   "types": "dist/index.d.ts",
diff --git src/core.ts src/core.ts
index 0c8e69ffc..e1a93f272 100644
--- src/core.ts
+++ src/core.ts
@@ -558,19 +558,13 @@ export abstract class APIClient {
     const timeout = setTimeout(() => controller.abort(), ms);
 
     return (
-      this.getRequestClient()
-        // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
-        .fetch.call(undefined, url, { signal: controller.signal as any, ...options })
-        .finally(() => {
-          clearTimeout(timeout);
-        })
+      // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
+      this.fetch.call(undefined, url, { signal: controller.signal as any, ...options }).finally(() => {
+        clearTimeout(timeout);
+      })
     );
   }
 
-  protected getRequestClient(): RequestClient {
-    return { fetch: this.fetch };
-  }
-
   private shouldRetry(response: Response): boolean {
     // Note this is not a standard header.
     const shouldRetryHeader = response.headers.get('x-should-retry');
@@ -1019,8 +1013,8 @@ export const safeJSON = (text: string) => {
   }
 };
 
-// https://stackoverflow.com/a/19709846
-const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
+// https://url.spec.whatwg.org/#url-scheme-string
+const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
 const isAbsoluteURL = (url: string): boolean => {
   return startsWithSchemeRegexp.test(url);
 };
diff --git src/error.ts src/error.ts
index 72b4f7bfd..f3dc57610 100644
--- src/error.ts
+++ src/error.ts
@@ -4,10 +4,17 @@ import { castToError, Headers } from './core';
 
 export class OpenAIError extends Error {}
 
-export class APIError extends OpenAIError {
-  readonly status: number | undefined;
-  readonly headers: Headers | undefined;
-  readonly error: Object | undefined;
+export class APIError<
+  TStatus extends number | undefined = number | undefined,
+  THeaders extends Headers | undefined = Headers | undefined,
+  TError extends Object | undefined = Object | undefined,
+> extends OpenAIError {
+  /** HTTP status for the response that caused the error */
+  readonly status: TStatus;
+  /** HTTP headers for the response that caused the error */
+  readonly headers: THeaders;
+  /** JSON body of the response that caused the error */
+  readonly error: TError;
 
   readonly code: string | null | undefined;
   readonly param: string | null | undefined;
@@ -15,19 +22,14 @@ export class APIError extends OpenAIError {
 
   readonly request_id: string | null | undefined;
 
-  constructor(
-    status: number | undefined,
-    error: Object | undefined,
-    message: string | undefined,
-    headers: Headers | undefined,
-  ) {
+  constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
     super(`${APIError.makeMessage(status, error, message)}`);
     this.status = status;
     this.headers = headers;
     this.request_id = headers?.['x-request-id'];
+    this.error = error;
 
     const data = error as Record<string, any>;
-    this.error = data;
     this.code = data?.['code'];
     this.param = data?.['param'];
     this.type = data?.['type'];
@@ -60,7 +62,7 @@ export class APIError extends OpenAIError {
     message: string | undefined,
     headers: Headers | undefined,
   ): APIError {
-    if (!status) {
+    if (!status || !headers) {
       return new APIConnectionError({ message, cause: castToError(errorResponse) });
     }
 
@@ -102,17 +104,13 @@ export class APIError extends OpenAIError {
   }
 }
 
-export class APIUserAbortError extends APIError {
-  override readonly status: undefined = undefined;
-
+export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
   constructor({ message }: { message?: string } = {}) {
     super(undefined, undefined, message || 'Request was aborted.', undefined);
   }
 }
 
-export class APIConnectionError extends APIError {
-  override readonly status: undefined = undefined;
-
+export class APIConnectionError extends APIError<undefined, undefined, undefined> {
   constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
     super(undefined, undefined, message || 'Connection error.', undefined);
     // in some environments the 'cause' property is already declared
@@ -127,35 +125,21 @@ export class APIConnectionTimeoutError extends APIConnectionError {
   }
 }
 
-export class BadRequestError extends APIError {
-  override readonly status: 400 = 400;
-}
+export class BadRequestError extends APIError<400, Headers> {}
 
-export class AuthenticationError extends APIError {
-  override readonly status: 401 = 401;
-}
+export class AuthenticationError extends APIError<401, Headers> {}
 
-export class PermissionDeniedError extends APIError {
-  override readonly status: 403 = 403;
-}
+export class PermissionDeniedError extends APIError<403, Headers> {}
 
-export class NotFoundError extends APIError {
-  override readonly status: 404 = 404;
-}
+export class NotFoundError extends APIError<404, Headers> {}
 
-export class ConflictError extends APIError {
-  override readonly status: 409 = 409;
-}
+export class ConflictError extends APIError<409, Headers> {}
 
-export class UnprocessableEntityError extends APIError {
-  override readonly status: 422 = 422;
-}
+export class UnprocessableEntityError extends APIError<422, Headers> {}
 
-export class RateLimitError extends APIError {
-  override readonly status: 429 = 429;
-}
+export class RateLimitError extends APIError<429, Headers> {}
 
-export class InternalServerError extends APIError {}
+export class InternalServerError extends APIError<number, Headers> {}
 
 export class LengthFinishReasonError extends OpenAIError {
   constructor() {
diff --git src/version.ts src/version.ts
index b4cc35ca9..7117b1feb 100644
--- src/version.ts
+++ src/version.ts
@@ -1 +1 @@
-export const VERSION = '4.76.0'; // x-release-please-version
+export const VERSION = '4.76.2'; // x-release-please-version

Description

This pull request updates the package version from 4.76.0 to 4.76.2 across multiple files. The motivation derrière these changes is to incorporate minor code improvements and bug fixes. These improvements mainly focus on code style enhancements and documentation improvements.

Possible Issues

None identified.

Security Hotspots

None identified.

Changes

Changes

.release-please-manifest.json

  • Updated the version from 4.76.0 to 4.76.2

CHANGELOG.md

  • Added changelog entries for version 4.76.1 and 4.76.2

jsr.json

  • Updated the version from 4.76.0 to 4.76.2

package.json

  • Updated the version from 4.76.0 to 4.76.2

src/core.ts

  • Removed the getRequestClient method.
  • Updated the isAbsoluteURL method's regular expression for URL scheme checking.

src/error.ts

  • Refactored APIError class to use generic types for status, headers, and error.
  • Updated constructors and subclasses of APIError to match new type definitions.
  • Enhanced code documentation within the APIError class.

src/version.ts

  • Updated the version constant from 4.76.0 to 4.76.2
sequenceDiagram
    participant Developer
    participant VersionFile
    participant CoreFile
    participant ErrorFile
    participant JSONConfigs
    participant CHANGELOG
    
    Developer->>VersionFile: Update version to 4.76.2
    Developer->>JSONConfigs: Update jsr.json and package.json versions
    Developer->>CoreFile: Remove getRequestClient, update isAbsoluteURL regex
    Developer->>ErrorFile: Refactor APIError with generics
    Developer->>CHANGELOG: Add changelog entries for 4.76.1 and 4.76.2
Loading

Copy link

anthropic debug - [puLL-Merge] - openai/[email protected]

Diff
diff --git .release-please-manifest.json .release-please-manifest.json
index 1cc8c9627..47a7d26b6 100644
--- .release-please-manifest.json
+++ .release-please-manifest.json
@@ -1,3 +1,3 @@
 {
-  ".": "4.76.0"
+  ".": "4.76.2"
 }
diff --git CHANGELOG.md CHANGELOG.md
index e68b45e8a..27946ddea 100644
--- CHANGELOG.md
+++ CHANGELOG.md
@@ -1,5 +1,23 @@
 # Changelog
 
+## 4.76.2 (2024-12-12)
+
+Full Changelog: [v4.76.1...v4.76.2](https://github.com/openai/openai-node/compare/v4.76.1...v4.76.2)
+
+### Chores
+
+* **internal:** update isAbsoluteURL ([#1223](https://github.com/openai/openai-node/issues/1223)) ([e908ed7](https://github.com/openai/openai-node/commit/e908ed759996fb7706baf46d094fc77419423971))
+* **types:** nicer error class types + jsdocs ([#1219](https://github.com/openai/openai-node/issues/1219)) ([576d24c](https://github.com/openai/openai-node/commit/576d24cc4b3d766dfe28a6031bdc24ac1b711655))
+
+## 4.76.1 (2024-12-10)
+
+Full Changelog: [v4.76.0...v4.76.1](https://github.com/openai/openai-node/compare/v4.76.0...v4.76.1)
+
+### Chores
+
+* **internal:** bump cross-spawn to v7.0.6 ([#1217](https://github.com/openai/openai-node/issues/1217)) ([c07ad29](https://github.com/openai/openai-node/commit/c07ad298d58e5aeaf816ee3de65fd59bf3fc8b66))
+* **internal:** remove unnecessary getRequestClient function ([#1215](https://github.com/openai/openai-node/issues/1215)) ([bef3925](https://github.com/openai/openai-node/commit/bef392526cd339f45c574bc476649c77be36c612))
+
 ## 4.76.0 (2024-12-05)
 
 Full Changelog: [v4.75.0...v4.76.0](https://github.com/openai/openai-node/compare/v4.75.0...v4.76.0)
diff --git jsr.json jsr.json
index 2c6820969..101edee15 100644
--- jsr.json
+++ jsr.json
@@ -1,6 +1,6 @@
 {
   "name": "@openai/openai",
-  "version": "4.76.0",
+  "version": "4.76.2",
   "exports": "./index.ts",
   "publish": {
     "exclude": [
diff --git package.json package.json
index fae301ee7..53b82f070 100644
--- package.json
+++ package.json
@@ -1,6 +1,6 @@
 {
   "name": "openai",
-  "version": "4.76.0",
+  "version": "4.76.2",
   "description": "The official TypeScript library for the OpenAI API",
   "author": "OpenAI <[email protected]>",
   "types": "dist/index.d.ts",
diff --git src/core.ts src/core.ts
index 0c8e69ffc..e1a93f272 100644
--- src/core.ts
+++ src/core.ts
@@ -558,19 +558,13 @@ export abstract class APIClient {
     const timeout = setTimeout(() => controller.abort(), ms);
 
     return (
-      this.getRequestClient()
-        // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
-        .fetch.call(undefined, url, { signal: controller.signal as any, ...options })
-        .finally(() => {
-          clearTimeout(timeout);
-        })
+      // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
+      this.fetch.call(undefined, url, { signal: controller.signal as any, ...options }).finally(() => {
+        clearTimeout(timeout);
+      })
     );
   }
 
-  protected getRequestClient(): RequestClient {
-    return { fetch: this.fetch };
-  }
-
   private shouldRetry(response: Response): boolean {
     // Note this is not a standard header.
     const shouldRetryHeader = response.headers.get('x-should-retry');
@@ -1019,8 +1013,8 @@ export const safeJSON = (text: string) => {
   }
 };
 
-// https://stackoverflow.com/a/19709846
-const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
+// https://url.spec.whatwg.org/#url-scheme-string
+const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
 const isAbsoluteURL = (url: string): boolean => {
   return startsWithSchemeRegexp.test(url);
 };
diff --git src/error.ts src/error.ts
index 72b4f7bfd..f3dc57610 100644
--- src/error.ts
+++ src/error.ts
@@ -4,10 +4,17 @@ import { castToError, Headers } from './core';
 
 export class OpenAIError extends Error {}
 
-export class APIError extends OpenAIError {
-  readonly status: number | undefined;
-  readonly headers: Headers | undefined;
-  readonly error: Object | undefined;
+export class APIError<
+  TStatus extends number | undefined = number | undefined,
+  THeaders extends Headers | undefined = Headers | undefined,
+  TError extends Object | undefined = Object | undefined,
+> extends OpenAIError {
+  /** HTTP status for the response that caused the error */
+  readonly status: TStatus;
+  /** HTTP headers for the response that caused the error */
+  readonly headers: THeaders;
+  /** JSON body of the response that caused the error */
+  readonly error: TError;
 
   readonly code: string | null | undefined;
   readonly param: string | null | undefined;
@@ -15,19 +22,14 @@ export class APIError extends OpenAIError {
 
   readonly request_id: string | null | undefined;
 
-  constructor(
-    status: number | undefined,
-    error: Object | undefined,
-    message: string | undefined,
-    headers: Headers | undefined,
-  ) {
+  constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
     super(`${APIError.makeMessage(status, error, message)}`);
     this.status = status;
     this.headers = headers;
     this.request_id = headers?.['x-request-id'];
+    this.error = error;
 
     const data = error as Record<string, any>;
-    this.error = data;
     this.code = data?.['code'];
     this.param = data?.['param'];
     this.type = data?.['type'];
@@ -60,7 +62,7 @@ export class APIError extends OpenAIError {
     message: string | undefined,
     headers: Headers | undefined,
   ): APIError {
-    if (!status) {
+    if (!status || !headers) {
       return new APIConnectionError({ message, cause: castToError(errorResponse) });
     }
 
@@ -102,17 +104,13 @@ export class APIError extends OpenAIError {
   }
 }
 
-export class APIUserAbortError extends APIError {
-  override readonly status: undefined = undefined;
-
+export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
   constructor({ message }: { message?: string } = {}) {
     super(undefined, undefined, message || 'Request was aborted.', undefined);
   }
 }
 
-export class APIConnectionError extends APIError {
-  override readonly status: undefined = undefined;
-
+export class APIConnectionError extends APIError<undefined, undefined, undefined> {
   constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
     super(undefined, undefined, message || 'Connection error.', undefined);
     // in some environments the 'cause' property is already declared
@@ -127,35 +125,21 @@ export class APIConnectionTimeoutError extends APIConnectionError {
   }
 }
 
-export class BadRequestError extends APIError {
-  override readonly status: 400 = 400;
-}
+export class BadRequestError extends APIError<400, Headers> {}
 
-export class AuthenticationError extends APIError {
-  override readonly status: 401 = 401;
-}
+export class AuthenticationError extends APIError<401, Headers> {}
 
-export class PermissionDeniedError extends APIError {
-  override readonly status: 403 = 403;
-}
+export class PermissionDeniedError extends APIError<403, Headers> {}
 
-export class NotFoundError extends APIError {
-  override readonly status: 404 = 404;
-}
+export class NotFoundError extends APIError<404, Headers> {}
 
-export class ConflictError extends APIError {
-  override readonly status: 409 = 409;
-}
+export class ConflictError extends APIError<409, Headers> {}
 
-export class UnprocessableEntityError extends APIError {
-  override readonly status: 422 = 422;
-}
+export class UnprocessableEntityError extends APIError<422, Headers> {}
 
-export class RateLimitError extends APIError {
-  override readonly status: 429 = 429;
-}
+export class RateLimitError extends APIError<429, Headers> {}
 
-export class InternalServerError extends APIError {}
+export class InternalServerError extends APIError<number, Headers> {}
 
 export class LengthFinishReasonError extends OpenAIError {
   constructor() {
diff --git src/version.ts src/version.ts
index b4cc35ca9..7117b1feb 100644
--- src/version.ts
+++ src/version.ts
@@ -1 +1 @@
-export const VERSION = '4.76.0'; // x-release-please-version
+export const VERSION = '4.76.2'; // x-release-please-versi,on

Description

This pull request updates the OpenAI Node.js library from version 4.76.0 to 4.76.2. It includes minor changes, bug fixes, and internal improvements. The main changes are version updates, changelog additions, and some code refactoring for improved security and performance.

Changes

Changes

  1. .release-please-manifest.json:

    • Updated version from 4.76.0 to 4.76.2
  2. CHANGELOG.md:

    • Added entries for versions 4.76.2 and 4.76.1
    • Documented internal updates and chores
  3. jsr.json and package.json:

    • Updated version from 4.76.0 to 4.76.2
  4. src/core.ts:

    • Removed getRequestClient method
    • Updated isAbsoluteURL function with a more precise regular expression
  5. src/error.ts:

    • Improved type definitions for APIError and its subclasses
    • Added generic type parameters to APIError for better type inference
  6. src/version.ts:

    • Updated version string to 4.76.2
sequenceDiagram
    participant Dev as Developer
    participant Git as Git Repository
    participant NPM as NPM Registry

    Dev->>Git: Update version numbers
    Dev->>Git: Update CHANGELOG.md
    Dev->>Git: Refactor core.ts
    Dev->>Git: Improve error.ts type definitions
    Dev->>Git: Commit changes
    Git->>NPM: Publish new version 4.76.2
    NPM-->>Dev: Confirm publication
Loading

Security Hotspots

  • The update to the isAbsoluteURL function in src/core.ts uses a more precise regular expression for URL scheme detection. This change reduces the risk of false positives in URL validation, potentially improving security.

Copy link

bedrock debug - [puLL-Merge] - openai/[email protected]

Diff
diff --git .release-please-manifest.json .release-please-manifest.json
index 1cc8c9627..47a7d26b6 100644
--- .release-please-manifest.json
+++ .release-please-manifest.json
@@ -1,3 +1,3 @@
 {
-  ".": "4.76.0"
+  ".": "4.76.2"
 }
diff --git CHANGELOG.md CHANGELOG.md
index e68b45e8a..27946ddea 100644
--- CHANGELOG.md
+++ CHANGELOG.md
@@ -1,5 +1,23 @@
 # Changelog
 
+## 4.76.2 (2024-12-12)
+
+Full Changelog: [v4.76.1...v4.76.2](https://github.com/openai/openai-node/compare/v4.76.1...v4.76.2)
+
+### Chores
+
+* **internal:** update isAbsoluteURL ([#1223](https://github.com/openai/openai-node/issues/1223)) ([e908ed7](https://github.com/openai/openai-node/commit/e908ed759996fb7706baf46d094fc77419423971))
+* **types:** nicer error class types + jsdocs ([#1219](https://github.com/openai/openai-node/issues/1219)) ([576d24c](https://github.com/openai/openai-node/commit/576d24cc4b3d766dfe28a6031bdc24ac1b711655))
+
+## 4.76.1 (2024-12-10)
+
+Full Changelog: [v4.76.0...v4.76.1](https://github.com/openai/openai-node/compare/v4.76.0...v4.76.1)
+
+### Chores
+
+* **internal:** bump cross-spawn to v7.0.6 ([#1217](https://github.com/openai/openai-node/issues/1217)) ([c07ad29](https://github.com/openai/openai-node/commit/c07ad298d58e5aeaf816ee3de65fd59bf3fc8b66))
+* **internal:** remove unnecessary getRequestClient function ([#1215](https://github.com/openai/openai-node/issues/1215)) ([bef3925](https://github.com/openai/openai-node/commit/bef392526cd339f45c574bc476649c77be36c612))
+
 ## 4.76.0 (2024-12-05)
 
 Full Changelog: [v4.75.0...v4.76.0](https://github.com/openai/openai-node/compare/v4.75.0...v4.76.0)
diff --git jsr.json jsr.json
index 2c6820969..101edee15 100644
--- jsr.json
+++ jsr.json
@@ -1,6 +1,6 @@
 {
   "name": "@openai/openai",
-  "version": "4.76.0",
+  "version": "4.76.2",
   "exports": "./index.ts",
   "publish": {
     "exclude": [
diff --git package.json package.json
index fae301ee7..53b82f070 100644
--- package.json
+++ package.json
@@ -1,6 +1,6 @@
 {
   "name": "openai",
-  "version": "4.76.0",
+  "version": "4.76.2",
   "description": "The official TypeScript library for the OpenAI API",
   "author": "OpenAI <[email protected]>",
   "types": "dist/index.d.ts",
diff --git src/core.ts src/core.ts
index 0c8e69ffc..e1a93f272 100644
--- src/core.ts
+++ src/core.ts
@@ -558,19 +558,13 @@ export abstract class APIClient {
     const timeout = setTimeout(() => controller.abort(), ms);
 
     return (
-      this.getRequestClient()
-        // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
-        .fetch.call(undefined, url, { signal: controller.signal as any, ...options })
-        .finally(() => {
-          clearTimeout(timeout);
-        })
+      // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
+      this.fetch.call(undefined, url, { signal: controller.signal as any, ...options }).finally(() => {
+        clearTimeout(timeout);
+      })
     );
   }
 
-  protected getRequestClient(): RequestClient {
-    return { fetch: this.fetch };
-  }
-
   private shouldRetry(response: Response): boolean {
     // Note this is not a standard header.
     const shouldRetryHeader = response.headers.get('x-should-retry');
@@ -1019,8 +1013,8 @@ export const safeJSON = (text: string) => {
   }
 };
 
-// https://stackoverflow.com/a/19709846
-const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
+// https://url.spec.whatwg.org/#url-scheme-string
+const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
 const isAbsoluteURL = (url: string): boolean => {
   return startsWithSchemeRegexp.test(url);
 };
diff --git src/error.ts src/error.ts
index 72b4f7bfd..f3dc57610 100644
--- src/error.ts
+++ src/error.ts
@@ -4,10 +4,17 @@ import { castToError, Headers } from './core';
 
 export class OpenAIError extends Error {}
 
-export class APIError extends OpenAIError {
-  readonly status: number | undefined;
-  readonly headers: Headers | undefined;
-  readonly error: Object | undefined;
+export class APIError<
+  TStatus extends number | undefined = number | undefined,
+  THeaders extends Headers | undefined = Headers | undefined,
+  TError extends Object | undefined = Object | undefined,
+> extends OpenAIError {
+  /** HTTP status for the response that caused the error */
+  readonly status: TStatus;
+  /** HTTP headers for the response that caused the error */
+  readonly headers: THeaders;
+  /** JSON body of the response that caused the error */
+  readonly error: TError;
 
   readonly code: string | null | undefined;
   readonly param: string | null | undefined;
@@ -15,19 +22,14 @@ export class APIError extends OpenAIError {
 
   readonly request_id: string | null | undefined;
 
-  constructor(
-    status: number | undefined,
-    error: Object | undefined,
-    message: string | undefined,
-    headers: Headers | undefined,
-  ) {
+  constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
     super(`${APIError.makeMessage(status, error, message)}`);
     this.status = status;
     this.headers = headers;
     this.request_id = headers?.['x-request-id'];
+    this.error = error;
 
     const data = error as Record<string, any>;
-    this.error = data;
     this.code = data?.['code'];
     this.param = data?.['param'];
     this.type = data?.['type'];
@@ -60,7 +62,7 @@ export class APIError extends OpenAIError {
     message: string | undefined,
     headers: Headers | undefined,
   ): APIError {
-    if (!status) {
+    if (!status || !headers) {
       return new APIConnectionError({ message, cause: castToError(errorResponse) });
     }
 
@@ -102,17 +104,13 @@ export class APIError extends OpenAIError {
   }
 }
 
-export class APIUserAbortError extends APIError {
-  override readonly status: undefined = undefined;
-
+export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
   constructor({ message }: { message?: string } = {}) {
     super(undefined, undefined, message || 'Request was aborted.', undefined);
   }
 }
 
-export class APIConnectionError extends APIError {
-  override readonly status: undefined = undefined;
-
+export class APIConnectionError extends APIError<undefined, undefined, undefined> {
   constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
     super(undefined, undefined, message || 'Connection error.', undefined);
     // in some environments the 'cause' property is already declared
@@ -127,35 +125,21 @@ export class APIConnectionTimeoutError extends APIConnectionError {
   }
 }
 
-export class BadRequestError extends APIError {
-  override readonly status: 400 = 400;
-}
+export class BadRequestError extends APIError<400, Headers> {}
 
-export class AuthenticationError extends APIError {
-  override readonly status: 401 = 401;
-}
+export class AuthenticationError extends APIError<401, Headers> {}
 
-export class PermissionDeniedError extends APIError {
-  override readonly status: 403 = 403;
-}
+export class PermissionDeniedError extends APIError<403, Headers> {}
 
-export class NotFoundError extends APIError {
-  override readonly status: 404 = 404;
-}
+export class NotFoundError extends APIError<404, Headers> {}
 
-export class ConflictError extends APIError {
-  override readonly status: 409 = 409;
-}
+export class ConflictError extends APIError<409, Headers> {}
 
-export class UnprocessableEntityError extends APIError {
-  override readonly status: 422 = 422;
-}
+export class UnprocessableEntityError extends APIError<422, Headers> {}
 
-export class RateLimitError extends APIError {
-  override readonly status: 429 = 429;
-}
+export class RateLimitError extends APIError<429, Headers> {}
 
-export class InternalServerError extends APIError {}
+export class InternalServerError extends APIError<number, Headers> {}
 
 export class LengthFinishReasonError extends OpenAIError {
   constructor() {
diff --git src/version.ts src/version.ts
index b4cc35ca9..7117b1feb 100644
--- src/version.ts
+++ src/version.ts
@@ -1 +1 @@
-export const VERSION = '4.76.0'; // x-release-please-version
+export const VERSION = '4.76.2'; // x-release-please-version

Description

This PR updates the OpenAI Node.js library from version 4.76.0 to 4.76.2. It includes minor chores, internal updates, and type improvements. The changes are primarily focused on maintenance and small enhancements rather than introducing new features.

Changes

Changes

  1. .release-please-manifest.json:

    • Updated version from 4.76.0 to 4.76.2
  2. CHANGELOG.md:

    • Added entries for versions 4.76.2 and 4.76.1
    • Includes chores related to internal updates and type improvements
  3. jsr.json and package.json:

    • Updated version from 4.76.0 to 4.76.2
  4. src/core.ts:

    • Removed getRequestClient method
    • Updated isAbsoluteURL function with a more precise regular expression
  5. src/error.ts:

    • Improved type definitions for APIError and its subclasses
    • Added generic type parameters to APIError for better type inference
  6. src/version.ts:

    • Updated version from 4.76.0 to 4.76.2
sequenceDiagram
    participant Dev as Developer
    participant Git as Git Repository
    participant NPM as NPM Registry

    Dev->>Git: Update version numbers
    Dev->>Git: Update CHANGELOG.md
    Dev->>Git: Refactor error handling in src/error.ts
    Dev->>Git: Update isAbsoluteURL in src/core.ts
    Dev->>Git: Remove getRequestClient method
    Dev->>Git: Commit changes
    Git->>NPM: Publish new version 4.76.2
    NPM-->>Dev: Confirm publication
Loading

Possible Issues

No major issues are apparent in this PR. The changes are mostly related to version updates and minor improvements.

Security Hotspots

There are no significant security hotspots in this PR. The changes do not introduce any new vulnerabilities or security risks.

@renovate renovate bot force-pushed the renovate/openai-4.x-lockfile branch from 49b8850 to 3f7a14a Compare December 20, 2024 16:18
@renovate renovate bot changed the title fix(deps): update dependency openai to v4.76.2 fix(deps): update dependency openai to v4.76.3 Dec 20, 2024
Copy link

anthropic debug - [puLL-Merge] - openai/[email protected]

Diff
diff --git .release-please-manifest.json .release-please-manifest.json
index 1cc8c9627..52c31fe71 100644
--- .release-please-manifest.json
+++ .release-please-manifest.json
@@ -1,3 +1,3 @@
 {
-  ".": "4.76.0"
+  ".": "4.76.3"
 }
diff --git CHANGELOG.md CHANGELOG.md
index e68b45e8a..4b6f57fe4 100644
--- CHANGELOG.md
+++ CHANGELOG.md
@@ -1,5 +1,36 @@
 # Changelog
 
+## 4.76.3 (2024-12-13)
+
+Full Changelog: [v4.76.2...v4.76.3](https://github.com/openai/openai-node/compare/v4.76.2...v4.76.3)
+
+### Chores
+
+* **internal:** better ecosystem test debugging ([86fc0a8](https://github.com/openai/openai-node/commit/86fc0a81ede2780d3fcebaabff3d9fa9a36cc9c0))
+
+
+### Documentation
+
+* **README:** fix helpers section links ([#1224](https://github.com/openai/openai-node/issues/1224)) ([efbe30a](https://github.com/openai/openai-node/commit/efbe30a156cec1836d3db28f663066b33be57ba2))
+
+## 4.76.2 (2024-12-12)
+
+Full Changelog: [v4.76.1...v4.76.2](https://github.com/openai/openai-node/compare/v4.76.1...v4.76.2)
+
+### Chores
+
+* **internal:** update isAbsoluteURL ([#1223](https://github.com/openai/openai-node/issues/1223)) ([e908ed7](https://github.com/openai/openai-node/commit/e908ed759996fb7706baf46d094fc77419423971))
+* **types:** nicer error class types + jsdocs ([#1219](https://github.com/openai/openai-node/issues/1219)) ([576d24c](https://github.com/openai/openai-node/commit/576d24cc4b3d766dfe28a6031bdc24ac1b711655))
+
+## 4.76.1 (2024-12-10)
+
+Full Changelog: [v4.76.0...v4.76.1](https://github.com/openai/openai-node/compare/v4.76.0...v4.76.1)
+
+### Chores
+
+* **internal:** bump cross-spawn to v7.0.6 ([#1217](https://github.com/openai/openai-node/issues/1217)) ([c07ad29](https://github.com/openai/openai-node/commit/c07ad298d58e5aeaf816ee3de65fd59bf3fc8b66))
+* **internal:** remove unnecessary getRequestClient function ([#1215](https://github.com/openai/openai-node/issues/1215)) ([bef3925](https://github.com/openai/openai-node/commit/bef392526cd339f45c574bc476649c77be36c612))
+
 ## 4.76.0 (2024-12-05)
 
 Full Changelog: [v4.75.0...v4.76.0](https://github.com/openai/openai-node/compare/v4.75.0...v4.76.0)
diff --git README.md README.md
index ac9c84a42..b03bcd870 100644
--- README.md
+++ README.md
@@ -200,7 +200,7 @@ main();
 \`\`\`
 
 Streaming with `openai.beta.chat.completions.stream({…})` exposes
-[various helpers for your convenience](helpers.md#events) including event handlers and promises.
+[various helpers for your convenience](helpers.md#chat-events) including event handlers and promises.
 
 Alternatively, you can use `openai.chat.completions.create({ stream: true, … })`
 which only returns an async iterable of the chunks in the stream and thus uses less memory
@@ -285,12 +285,12 @@ main();
 // Final content: "It's looking cold and rainy - you might want to wear a jacket!"

-Like with .stream(), we provide a variety of helpers and events.
+Like with .stream(), we provide a variety of helpers and events.

Note that runFunctions was previously available as well, but has been deprecated in favor of runTools.

Read more about various examples such as with integrating with zod,
-next.js, and proxying a stream to the browser.
+next.js, and proxying a stream to the browser.

File uploads

diff --git ecosystem-tests/cli.ts ecosystem-tests/cli.ts
index 4803b47c2..00120e5f9 100644
--- ecosystem-tests/cli.ts
+++ ecosystem-tests/cli.ts
@@ -4,6 +4,10 @@ import yargs from 'yargs';
import assert from 'assert';
import path from 'path';

+// @ts-ignore
+var SegfaultHandler = require('segfault-handler');
+SegfaultHandler.registerHandler('crash.log');
+
const TAR_NAME = 'openai.tgz';
const PACK_FOLDER = '.pack';
const PACK_FILE = ${PACK_FOLDER}/${TAR_NAME};
diff --git jsr.json jsr.json
index 2c6820969..ef9ce6848 100644
--- jsr.json
+++ jsr.json
@@ -1,6 +1,6 @@
{
"name": "@openai/openai",

  • "version": "4.76.0",
  • "version": "4.76.3",
    "exports": "./index.ts",
    "publish": {
    "exclude": [
    diff --git package.json package.json
    index fae301ee7..47f363ba1 100644
    --- package.json
    +++ package.json
    @@ -1,6 +1,6 @@
    {
    "name": "openai",
  • "version": "4.76.0",
  • "version": "4.76.3",
    "description": "The official TypeScript library for the OpenAI API",
    "author": "OpenAI [email protected]",
    "types": "dist/index.d.ts",
    @@ -41,11 +41,12 @@
    "eslint": "^8.49.0",
    "eslint-plugin-prettier": "^5.0.1",
    "eslint-plugin-unused-imports": "^3.0.0",
  • "iconv-lite": "^0.6.3",
    "fast-check": "^3.22.0",
  • "iconv-lite": "^0.6.3",
    "jest": "^29.4.0",
    "prettier": "^3.0.0",
    "prettier-2": "npm:prettier@^2",

  • "segfault-handler": "^1.3.0",
    "ts-jest": "^29.1.0",
    "ts-node": "^10.5.0",
    "tsc-multi": "^1.1.0",
    diff --git src/core.ts src/core.ts
    index 0c8e69ffc..e1a93f272 100644
    --- src/core.ts
    +++ src/core.ts
    @@ -558,19 +558,13 @@ export abstract class APIClient {
    const timeout = setTimeout(() => controller.abort(), ms);

    return (

  •  this.getRequestClient()
    
  •    // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
    
  •    .fetch.call(undefined, url, { signal: controller.signal as any, ...options })
    
  •    .finally(() => {
    
  •      clearTimeout(timeout);
    
  •    })
    
  •  // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
    
  •  this.fetch.call(undefined, url, { signal: controller.signal as any, ...options }).finally(() => {
    
  •    clearTimeout(timeout);
    
  •  })
    
    );
    }
  • protected getRequestClient(): RequestClient {
  • return { fetch: this.fetch };
  • }
  • private shouldRetry(response: Response): boolean {
    // Note this is not a standard header.
    const shouldRetryHeader = response.headers.get('x-should-retry');
    @@ -1019,8 +1013,8 @@ export const safeJSON = (text: string) => {
    }
    };

-// https://stackoverflow.com/a/19709846
-const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
+// https://url.spec.whatwg.org/#url-scheme-string
+const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
const isAbsoluteURL = (url: string): boolean => {
return startsWithSchemeRegexp.test(url);
};
diff --git src/error.ts src/error.ts
index 72b4f7bfd..f3dc57610 100644
--- src/error.ts
+++ src/error.ts
@@ -4,10 +4,17 @@ import { castToError, Headers } from './core';

export class OpenAIError extends Error {}

-export class APIError extends OpenAIError {

  • readonly status: number | undefined;
  • readonly headers: Headers | undefined;
  • readonly error: Object | undefined;
    +export class APIError<
  • TStatus extends number | undefined = number | undefined,

  • THeaders extends Headers | undefined = Headers | undefined,

  • TError extends Object | undefined = Object | undefined,
    +> extends OpenAIError {

  • /** HTTP status for the response that caused the error */

  • readonly status: TStatus;

  • /** HTTP headers for the response that caused the error */

  • readonly headers: THeaders;

  • /** JSON body of the response that caused the error */

  • readonly error: TError;

    readonly code: string | null | undefined;
    readonly param: string | null | undefined;
    @@ -15,19 +22,14 @@ export class APIError extends OpenAIError {

    readonly request_id: string | null | undefined;

  • constructor(
  • status: number | undefined,
  • error: Object | undefined,
  • message: string | undefined,
  • headers: Headers | undefined,
  • ) {
  • constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
    super(${APIError.makeMessage(status, error, message)});
    this.status = status;
    this.headers = headers;
    this.request_id = headers?.['x-request-id'];

  • this.error = error;

    const data = error as Record<string, any>;

  • this.error = data;
    this.code = data?.['code'];
    this.param = data?.['param'];
    this.type = data?.['type'];
    @@ -60,7 +62,7 @@ export class APIError extends OpenAIError {
    message: string | undefined,
    headers: Headers | undefined,
    ): APIError {
  • if (!status) {
  • if (!status || !headers) {
    return new APIConnectionError({ message, cause: castToError(errorResponse) });
    }

@@ -102,17 +104,13 @@ export class APIError extends OpenAIError {
}
}

-export class APIUserAbortError extends APIError {

  • override readonly status: undefined = undefined;

+export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
constructor({ message }: { message?: string } = {}) {
super(undefined, undefined, message || 'Request was aborted.', undefined);
}
}

-export class APIConnectionError extends APIError {

  • override readonly status: undefined = undefined;

+export class APIConnectionError extends APIError<undefined, undefined, undefined> {
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
super(undefined, undefined, message || 'Connection error.', undefined);
// in some environments the 'cause' property is already declared
@@ -127,35 +125,21 @@ export class APIConnectionTimeoutError extends APIConnectionError {
}
}

-export class BadRequestError extends APIError {

  • override readonly status: 400 = 400;
    -}
    +export class BadRequestError extends APIError<400, Headers> {}

-export class AuthenticationError extends APIError {

  • override readonly status: 401 = 401;
    -}
    +export class AuthenticationError extends APIError<401, Headers> {}

-export class PermissionDeniedError extends APIError {

  • override readonly status: 403 = 403;
    -}
    +export class PermissionDeniedError extends APIError<403, Headers> {}

-export class NotFoundError extends APIError {

  • override readonly status: 404 = 404;
    -}
    +export class NotFoundError extends APIError<404, Headers> {}

-export class ConflictError extends APIError {

  • override readonly status: 409 = 409;
    -}
    +export class ConflictError extends APIError<409, Headers> {}

-export class UnprocessableEntityError extends APIError {

  • override readonly status: 422 = 422;
    -}
    +export class UnprocessableEntityError extends APIError<422, Headers> {}

-export class RateLimitError extends APIError {

  • override readonly status: 429 = 429;
    -}
    +export class RateLimitError extends APIError<429, Headers> {}

-export class InternalServerError extends APIError {}
+export class InternalServerError extends APIError<number, Headers> {}

export class LengthFinishReasonError extends OpenAIError {
constructor() {
diff --git src/version.ts src/version.ts
index b4cc35ca9..01cd56405 100644
--- src/version.ts
+++ src/version.ts
@@ -1 +1 @@
-export const VERSION = '4.76.0'; // x-release-please-version
+export const VERSION = '4.76.3'; // x-release-please-version


</details>

### Description
This PR updates the OpenAI Node.js library from version 4.76.0 to 4.76.3. It includes various minor improvements, bug fixes, and documentation updates.

<details>
<summary><i>Changes</i></summary>

### Changes

1. `.release-please-manifest.json`:
   - Updated version from 4.76.0 to 4.76.3

2. `CHANGELOG.md`:
   - Added entries for versions 4.76.3, 4.76.2, and 4.76.1
   - New changes include internal improvements, documentation updates, and dependency updates

3. `README.md`:
   - Fixed links in the documentation for helpers and event handlers

4. `ecosystem-tests/cli.ts`:
   - Added a segfault handler for better debugging

5. `jsr.json` and `package.json`:
   - Updated version to 4.76.3
   - Added `segfault-handler` as a dev dependency

6. `src/core.ts`:
   - Removed unnecessary `getRequestClient` function
   - Updated `isAbsoluteURL` regex for better URL scheme detection

7. `src/error.ts`:
   - Improved type definitions for `APIError` and its subclasses
   - Enhanced error handling and type safety

8. `src/version.ts`:
   - Updated version to 4.76.3

```mermaid
sequenceDiagram
    participant Dev as Developer
    participant NPM as NPM Registry
    participant Lib as OpenAI Library
    participant API as OpenAI API

    Dev->>NPM: Update to [email protected]
    NPM-->>Dev: Deliver updated package
    Dev->>Lib: Use updated library
    Lib->>API: Make API calls with improved error handling
    API-->>Lib: Return response
    Lib-->>Dev: Provide response with enhanced type safety

Possible Issues

The addition of the segfault handler in ecosystem-tests/cli.ts might introduce unexpected behavior in certain environments if not properly configured.

Copy link

bedrock debug - [puLL-Merge] - openai/[email protected]

Diff
diff --git .release-please-manifest.json .release-please-manifest.json
index 1cc8c9627..52c31fe71 100644
--- .release-please-manifest.json
+++ .release-please-manifest.json
@@ -1,3 +1,3 @@
 {
-  ".": "4.76.0"
+  ".": "4.76.3"
 }
diff --git CHANGELOG.md CHANGELOG.md
index e68b45e8a..4b6f57fe4 100644
--- CHANGELOG.md
+++ CHANGELOG.md
@@ -1,5 +1,36 @@
 # Changelog
 
+## 4.76.3 (2024-12-13)
+
+Full Changelog: [v4.76.2...v4.76.3](https://github.com/openai/openai-node/compare/v4.76.2...v4.76.3)
+
+### Chores
+
+* **internal:** better ecosystem test debugging ([86fc0a8](https://github.com/openai/openai-node/commit/86fc0a81ede2780d3fcebaabff3d9fa9a36cc9c0))
+
+
+### Documentation
+
+* **README:** fix helpers section links ([#1224](https://github.com/openai/openai-node/issues/1224)) ([efbe30a](https://github.com/openai/openai-node/commit/efbe30a156cec1836d3db28f663066b33be57ba2))
+
+## 4.76.2 (2024-12-12)
+
+Full Changelog: [v4.76.1...v4.76.2](https://github.com/openai/openai-node/compare/v4.76.1...v4.76.2)
+
+### Chores
+
+* **internal:** update isAbsoluteURL ([#1223](https://github.com/openai/openai-node/issues/1223)) ([e908ed7](https://github.com/openai/openai-node/commit/e908ed759996fb7706baf46d094fc77419423971))
+* **types:** nicer error class types + jsdocs ([#1219](https://github.com/openai/openai-node/issues/1219)) ([576d24c](https://github.com/openai/openai-node/commit/576d24cc4b3d766dfe28a6031bdc24ac1b711655))
+
+## 4.76.1 (2024-12-10)
+
+Full Changelog: [v4.76.0...v4.76.1](https://github.com/openai/openai-node/compare/v4.76.0...v4.76.1)
+
+### Chores
+
+* **internal:** bump cross-spawn to v7.0.6 ([#1217](https://github.com/openai/openai-node/issues/1217)) ([c07ad29](https://github.com/openai/openai-node/commit/c07ad298d58e5aeaf816ee3de65fd59bf3fc8b66))
+* **internal:** remove unnecessary getRequestClient function ([#1215](https://github.com/openai/openai-node/issues/1215)) ([bef3925](https://github.com/openai/openai-node/commit/bef392526cd339f45c574bc476649c77be36c612))
+
 ## 4.76.0 (2024-12-05)
 
 Full Changelog: [v4.75.0...v4.76.0](https://github.com/openai/openai-node/compare/v4.75.0...v4.76.0)
diff --git README.md README.md
index ac9c84a42..b03bcd870 100644
--- README.md
+++ README.md
@@ -200,7 +200,7 @@ main();
 \`\`\`
 
 Streaming with `openai.beta.chat.completions.stream({…})` exposes
-[various helpers for your convenience](helpers.md#events) including event handlers and promises.
+[various helpers for your convenience](helpers.md#chat-events) including event handlers and promises.
 
 Alternatively, you can use `openai.chat.completions.create({ stream: true, … })`
 which only returns an async iterable of the chunks in the stream and thus uses less memory
@@ -285,12 +285,12 @@ main();
 // Final content: "It's looking cold and rainy - you might want to wear a jacket!"

-Like with .stream(), we provide a variety of helpers and events.
+Like with .stream(), we provide a variety of helpers and events.

Note that runFunctions was previously available as well, but has been deprecated in favor of runTools.

Read more about various examples such as with integrating with zod,
-next.js, and proxying a stream to the browser.
+next.js, and proxying a stream to the browser.

File uploads

diff --git ecosystem-tests/cli.ts ecosystem-tests/cli.ts
index 4803b47c2..00120e5f9 100644
--- ecosystem-tests/cli.ts
+++ ecosystem-tests/cli.ts
@@ -4,6 +4,10 @@ import yargs from 'yargs';
import assert from 'assert';
import path from 'path';

+// @ts-ignore
+var SegfaultHandler = require('segfault-handler');
+SegfaultHandler.registerHandler('crash.log');
+
const TAR_NAME = 'openai.tgz';
const PACK_FOLDER = '.pack';
const PACK_FILE = ${PACK_FOLDER}/${TAR_NAME};
diff --git jsr.json jsr.json
index 2c6820969..ef9ce6848 100644
--- jsr.json
+++ jsr.json
@@ -1,6 +1,6 @@
{
"name": "@openai/openai",

  • "version": "4.76.0",
  • "version": "4.76.3",
    "exports": "./index.ts",
    "publish": {
    "exclude": [
    diff --git package.json package.json
    index fae301ee7..47f363ba1 100644
    --- package.json
    +++ package.json
    @@ -1,6 +1,6 @@
    {
    "name": "openai",
  • "version": "4.76.0",
  • "version": "4.76.3",
    "description": "The official TypeScript library for the OpenAI API",
    "author": "OpenAI [email protected]",
    "types": "dist/index.d.ts",
    @@ -41,11 +41,12 @@
    "eslint": "^8.49.0",
    "eslint-plugin-prettier": "^5.0.1",
    "eslint-plugin-unused-imports": "^3.0.0",
  • "iconv-lite": "^0.6.3",
    "fast-check": "^3.22.0",
  • "iconv-lite": "^0.6.3",
    "jest": "^29.4.0",
    "prettier": "^3.0.0",
    "prettier-2": "npm:prettier@^2",

  • "segfault-handler": "^1.3.0",
    "ts-jest": "^29.1.0",
    "ts-node": "^10.5.0",
    "tsc-multi": "^1.1.0",
    diff --git src/core.ts src/core.ts
    index 0c8e69ffc..e1a93f272 100644
    --- src/core.ts
    +++ src/core.ts
    @@ -558,19 +558,13 @@ export abstract class APIClient {
    const timeout = setTimeout(() => controller.abort(), ms);

    return (

  •  this.getRequestClient()
    
  •    // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
    
  •    .fetch.call(undefined, url, { signal: controller.signal as any, ...options })
    
  •    .finally(() => {
    
  •      clearTimeout(timeout);
    
  •    })
    
  •  // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
    
  •  this.fetch.call(undefined, url, { signal: controller.signal as any, ...options }).finally(() => {
    
  •    clearTimeout(timeout);
    
  •  })
    
    );
    }
  • protected getRequestClient(): RequestClient {
  • return { fetch: this.fetch };
  • }
  • private shouldRetry(response: Response): boolean {
    // Note this is not a standard header.
    const shouldRetryHeader = response.headers.get('x-should-retry');
    @@ -1019,8 +1013,8 @@ export const safeJSON = (text: string) => {
    }
    };

-// https://stackoverflow.com/a/19709846
-const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
+// https://url.spec.whatwg.org/#url-scheme-string
+const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
const isAbsoluteURL = (url: string): boolean => {
return startsWithSchemeRegexp.test(url);
};
diff --git src/error.ts src/error.ts
index 72b4f7bfd..f3dc57610 100644
--- src/error.ts
+++ src/error.ts
@@ -4,10 +4,17 @@ import { castToError, Headers } from './core';

export class OpenAIError extends Error {}

-export class APIError extends OpenAIError {

  • readonly status: number | undefined;
  • readonly headers: Headers | undefined;
  • readonly error: Object | undefined;
    +export class APIError<
  • TStatus extends number | undefined = number | undefined,

  • THeaders extends Headers | undefined = Headers | undefined,

  • TError extends Object | undefined = Object | undefined,
    +> extends OpenAIError {

  • /** HTTP status for the response that caused the error */

  • readonly status: TStatus;

  • /** HTTP headers for the response that caused the error */

  • readonly headers: THeaders;

  • /** JSON body of the response that caused the error */

  • readonly error: TError;

    readonly code: string | null | undefined;
    readonly param: string | null | undefined;
    @@ -15,19 +22,14 @@ export class APIError extends OpenAIError {

    readonly request_id: string | null | undefined;

  • constructor(
  • status: number | undefined,
  • error: Object | undefined,
  • message: string | undefined,
  • headers: Headers | undefined,
  • ) {
  • constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
    super(${APIError.makeMessage(status, error, message)});
    this.status = status;
    this.headers = headers;
    this.request_id = headers?.['x-request-id'];

  • this.error = error;

    const data = error as Record<string, any>;

  • this.error = data;
    this.code = data?.['code'];
    this.param = data?.['param'];
    this.type = data?.['type'];
    @@ -60,7 +62,7 @@ export class APIError extends OpenAIError {
    message: string | undefined,
    headers: Headers | undefined,
    ): APIError {
  • if (!status) {
  • if (!status || !headers) {
    return new APIConnectionError({ message, cause: castToError(errorResponse) });
    }

@@ -102,17 +104,13 @@ export class APIError extends OpenAIError {
}
}

-export class APIUserAbortError extends APIError {

  • override readonly status: undefined = undefined;

+export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
constructor({ message }: { message?: string } = {}) {
super(undefined, undefined, message || 'Request was aborted.', undefined);
}
}

-export class APIConnectionError extends APIError {

  • override readonly status: undefined = undefined;

+export class APIConnectionError extends APIError<undefined, undefined, undefined> {
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
super(undefined, undefined, message || 'Connection error.', undefined);
// in some environments the 'cause' property is already declared
@@ -127,35 +125,21 @@ export class APIConnectionTimeoutError extends APIConnectionError {
}
}

-export class BadRequestError extends APIError {

  • override readonly status: 400 = 400;
    -}
    +export class BadRequestError extends APIError<400, Headers> {}

-export class AuthenticationError extends APIError {

  • override readonly status: 401 = 401;
    -}
    +export class AuthenticationError extends APIError<401, Headers> {}

-export class PermissionDeniedError extends APIError {

  • override readonly status: 403 = 403;
    -}
    +export class PermissionDeniedError extends APIError<403, Headers> {}

-export class NotFoundError extends APIError {

  • override readonly status: 404 = 404;
    -}
    +export class NotFoundError extends APIError<404, Headers> {}

-export class ConflictError extends APIError {

  • override readonly status: 409 = 409;
    -}
    +export class ConflictError extends APIError<409, Headers> {}

-export class UnprocessableEntityError extends APIError {

  • override readonly status: 422 = 422;
    -}
    +export class UnprocessableEntityError extends APIError<422, Headers> {}

-export class RateLimitError extends APIError {

  • override readonly status: 429 = 429;
    -}
    +export class RateLimitError extends APIError<429, Headers> {}

-export class InternalServerError extends APIError {}
+export class InternalServerError extends APIError<number, Headers> {}

export class LengthFinishReasonError extends OpenAIError {
constructor() {
diff --git src/version.ts src/version.ts
index b4cc35ca9..01cd56405 100644
--- src/version.ts
+++ src/version.ts
@@ -1 +1 @@
-export const VERSION = '4.76.0'; // x-release-please-version
+export const VERSION = '4.76.3'; // x-release-please-version


</details>

### Description
This PR updates the OpenAI Node.js library from version 4.76.0 to 4.76.3. It includes various minor improvements, documentation updates, and internal changes.

<details>
<summary><i>Changes</i></summary>

### Changes

1. `.release-please-manifest.json`:
   - Updated version from 4.76.0 to 4.76.3

2. `CHANGELOG.md`:
   - Added entries for versions 4.76.3, 4.76.2, and 4.76.1
   - Documented various chores, documentation updates, and internal changes

3. `README.md`:
   - Fixed links in the helpers section

4. `ecosystem-tests/cli.ts`:
   - Added SegfaultHandler for improved debugging

5. `jsr.json` and `package.json`:
   - Updated version to 4.76.3
   - Added `segfault-handler` as a dev dependency

6. `src/core.ts`:
   - Removed `getRequestClient` method
   - Updated `isAbsoluteURL` function with a more precise regular expression

7. `src/error.ts`:
   - Improved type definitions for `APIError` and its subclasses
   - Added more specific JSDoc comments

8. `src/version.ts`:
   - Updated version to 4.76.3

```mermaid
sequenceDiagram
    participant Dev as Developer
    participant Git as Git Repository
    participant NPM as NPM Registry

    Dev->>Git: Update version numbers
    Dev->>Git: Update CHANGELOG.md
    Dev->>Git: Fix README links
    Dev->>Git: Add SegfaultHandler to cli.ts
    Dev->>Git: Refactor core.ts
    Dev->>Git: Improve error.ts type definitions
    Dev->>Git: Commit changes
    Git->>NPM: Publish new version 4.76.3
    NPM-->>Dev: Confirm publication

Copy link

openai debug - [puLL-Merge] - openai/[email protected]

Diff
diff --git .release-please-manifest.json .release-please-manifest.json
index 1cc8c9627..52c31fe71 100644
--- .release-please-manifest.json
+++ .release-please-manifest.json
@@ -1,3 +1,3 @@
 {
-  ".": "4.76.0"
+  ".": "4.76.3"
 }
diff --git CHANGELOG.md CHANGELOG.md
index e68b45e8a..4b6f57fe4 100644
--- CHANGELOG.md
+++ CHANGELOG.md
@@ -1,5 +1,36 @@
 # Changelog
 
+## 4.76.3 (2024-12-13)
+
+Full Changelog: [v4.76.2...v4.76.3](https://github.com/openai/openai-node/compare/v4.76.2...v4.76.3)
+
+### Chores
+
+* **internal:** better ecosystem test debugging ([86fc0a8](https://github.com/openai/openai-node/commit/86fc0a81ede2780d3fcebaabff3d9fa9a36cc9c0))
+
+
+### Documentation
+
+* **README:** fix helpers section links ([#1224](https://github.com/openai/openai-node/issues/1224)) ([efbe30a](https://github.com/openai/openai-node/commit/efbe30a156cec1836d3db28f663066b33be57ba2))
+
+## 4.76.2 (2024-12-12)
+
+Full Changelog: [v4.76.1...v4.76.2](https://github.com/openai/openai-node/compare/v4.76.1...v4.76.2)
+
+### Chores
+
+* **internal:** update isAbsoluteURL ([#1223](https://github.com/openai/openai-node/issues/1223)) ([e908ed7](https://github.com/openai/openai-node/commit/e908ed759996fb7706baf46d094fc77419423971))
+* **types:** nicer error class types + jsdocs ([#1219](https://github.com/openai/openai-node/issues/1219)) ([576d24c](https://github.com/openai/openai-node/commit/576d24cc4b3d766dfe28a6031bdc24ac1b711655))
+
+## 4.76.1 (2024-12-10)
+
+Full Changelog: [v4.76.0...v4.76.1](https://github.com/openai/openai-node/compare/v4.76.0...v4.76.1)
+
+### Chores
+
+* **internal:** bump cross-spawn to v7.0.6 ([#1217](https://github.com/openai/openai-node/issues/1217)) ([c07ad29](https://github.com/openai/openai-node/commit/c07ad298d58e5aeaf816ee3de65fd59bf3fc8b66))
+* **internal:** remove unnecessary getRequestClient function ([#1215](https://github.com/openai/openai-node/issues/1215)) ([bef3925](https://github.com/openai/openai-node/commit/bef392526cd339f45c574bc476649c77be36c612))
+
 ## 4.76.0 (2024-12-05)
 
 Full Changelog: [v4.75.0...v4.76.0](https://github.com/openai/openai-node/compare/v4.75.0...v4.76.0)
diff --git README.md README.md
index ac9c84a42..b03bcd870 100644
--- README.md
+++ README.md
@@ -200,7 +200,7 @@ main();
 \`\`\`
 
 Streaming with `openai.beta.chat.completions.stream({…})` exposes
-[various helpers for your convenience](helpers.md#events) including event handlers and promises.
+[various helpers for your convenience](helpers.md#chat-events) including event handlers and promises.
 
 Alternatively, you can use `openai.chat.completions.create({ stream: true, … })`
 which only returns an async iterable of the chunks in the stream and thus uses less memory
@@ -285,12 +285,12 @@ main();
 // Final content: "It's looking cold and rainy - you might want to wear a jacket!"

-Like with .stream(), we provide a variety of helpers and events.
+Like with .stream(), we provide a variety of helpers and events.

Note that runFunctions was previously available as well, but has been deprecated in favor of runTools.

Read more about various examples such as with integrating with zod,
-next.js, and proxying a stream to the browser.
+next.js, and proxying a stream to the browser.

File uploads

diff --git ecosystem-tests/cli.ts ecosystem-tests/cli.ts
index 4803b47c2..00120e5f9 100644
--- ecosystem-tests/cli.ts
+++ ecosystem-tests/cli.ts
@@ -4,6 +4,10 @@ import yargs from 'yargs';
import assert from 'assert';
import path from 'path';

+// @ts-ignore
+var SegfaultHandler = require('segfault-handler');
+SegfaultHandler.registerHandler('crash.log');
+
const TAR_NAME = 'openai.tgz';
const PACK_FOLDER = '.pack';
const PACK_FILE = ${PACK_FOLDER}/${TAR_NAME};
diff --git jsr.json jsr.json
index 2c6820969..ef9ce6848 100644
--- jsr.json
+++ jsr.json
@@ -1,6 +1,6 @@
{
"name": "@openai/openai",

  • "version": "4.76.0",
  • "version": "4.76.3",
    "exports": "./index.ts",
    "publish": {
    "exclude": [
    diff --git package.json package.json
    index fae301ee7..47f363ba1 100644
    --- package.json
    +++ package.json
    @@ -1,6 +1,6 @@
    {
    "name": "openai",
  • "version": "4.76.0",
  • "version": "4.76.3",
    "description": "The official TypeScript library for the OpenAI API",
    "author": "OpenAI [email protected]",
    "types": "dist/index.d.ts",
    @@ -41,11 +41,12 @@
    "eslint": "^8.49.0",
    "eslint-plugin-prettier": "^5.0.1",
    "eslint-plugin-unused-imports": "^3.0.0",
  • "iconv-lite": "^0.6.3",
    "fast-check": "^3.22.0",
  • "iconv-lite": "^0.6.3",
    "jest": "^29.4.0",
    "prettier": "^3.0.0",
    "prettier-2": "npm:prettier@^2",

  • "segfault-handler": "^1.3.0",
    "ts-jest": "^29.1.0",
    "ts-node": "^10.5.0",
    "tsc-multi": "^1.1.0",
    diff --git src/core.ts src/core.ts
    index 0c8e69ffc..e1a93f272 100644
    --- src/core.ts
    +++ src/core.ts
    @@ -558,19 +558,13 @@ export abstract class APIClient {
    const timeout = setTimeout(() => controller.abort(), ms);

    return (

  •  this.getRequestClient()
    
  •    // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
    
  •    .fetch.call(undefined, url, { signal: controller.signal as any, ...options })
    
  •    .finally(() => {
    
  •      clearTimeout(timeout);
    
  •    })
    
  •  // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
    
  •  this.fetch.call(undefined, url, { signal: controller.signal as any, ...options }).finally(() => {
    
  •    clearTimeout(timeout);
    
  •  })
    
    );
    }
  • protected getRequestClient(): RequestClient {
  • return { fetch: this.fetch };
  • }
  • private shouldRetry(response: Response): boolean {
    // Note this is not a standard header.
    const shouldRetryHeader = response.headers.get('x-should-retry');
    @@ -1019,8 +1013,8 @@ export const safeJSON = (text: string) => {
    }
    };

-// https://stackoverflow.com/a/19709846
-const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
+// https://url.spec.whatwg.org/#url-scheme-string
+const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
const isAbsoluteURL = (url: string): boolean => {
return startsWithSchemeRegexp.test(url);
};
diff --git src/error.ts src/error.ts
index 72b4f7bfd..f3dc57610 100644
--- src/error.ts
+++ src/error.ts
@@ -4,10 +4,17 @@ import { castToError, Headers } from './core';

export class OpenAIError extends Error {}

-export class APIError extends OpenAIError {

  • readonly status: number | undefined;
  • readonly headers: Headers | undefined;
  • readonly error: Object | undefined;
    +export class APIError<
  • TStatus extends number | undefined = number | undefined,

  • THeaders extends Headers | undefined = Headers | undefined,

  • TError extends Object | undefined = Object | undefined,
    +> extends OpenAIError {

  • /** HTTP status for the response that caused the error */

  • readonly status: TStatus;

  • /** HTTP headers for the response that caused the error */

  • readonly headers: THeaders;

  • /** JSON body of the response that caused the error */

  • readonly error: TError;

    readonly code: string | null | undefined;
    readonly param: string | null | undefined;
    @@ -15,19 +22,14 @@ export class APIError extends OpenAIError {

    readonly request_id: string | null | undefined;

  • constructor(
  • status: number | undefined,
  • error: Object | undefined,
  • message: string | undefined,
  • headers: Headers | undefined,
  • ) {
  • constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
    super(${APIError.makeMessage(status, error, message)});
    this.status = status;
    this.headers = headers;
    this.request_id = headers?.['x-request-id'];

  • this.error = error;

    const data = error as Record<string, any>;

  • this.error = data;
    this.code = data?.['code'];
    this.param = data?.['param'];
    this.type = data?.['type'];
    @@ -60,7 +62,7 @@ export class APIError extends OpenAIError {
    message: string | undefined,
    headers: Headers | undefined,
    ): APIError {
  • if (!status) {
  • if (!status || !headers) {
    return new APIConnectionError({ message, cause: castToError(errorResponse) });
    }

@@ -102,17 +104,13 @@ export class APIError extends OpenAIError {
}
}

-export class APIUserAbortError extends APIError {

  • override readonly status: undefined = undefined;

+export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
constructor({ message }: { message?: string } = {}) {
super(undefined, undefined, message || 'Request was aborted.', undefined);
}
}

-export class APIConnectionError extends APIError {

  • override readonly status: undefined = undefined;

+export class APIConnectionError extends APIError<undefined, undefined, undefined> {
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
super(undefined, undefined, message || 'Connection error.', undefined);
// in some environments the 'cause' property is already declared
@@ -127,35 +125,21 @@ export class APIConnectionTimeoutError extends APIConnectionError {
}
}

-export class BadRequestError extends APIError {

  • override readonly status: 400 = 400;
    -}
    +export class BadRequestError extends APIError<400, Headers> {}

-export class AuthenticationError extends APIError {

  • override readonly status: 401 = 401;
    -}
    +export class AuthenticationError extends APIError<401, Headers> {}

-export class PermissionDeniedError extends APIError {

  • override readonly status: 403 = 403;
    -}
    +export class PermissionDeniedError extends APIError<403, Headers> {}

-export class NotFoundError extends APIError {

  • override readonly status: 404 = 404;
    -}
    +export class NotFoundError extends APIError<404, Headers> {}

-export class ConflictError extends APIError {

  • override readonly status: 409 = 409;
    -}
    +export class ConflictError extends APIError<409, Headers> {}

-export class UnprocessableEntityError extends APIError {

  • override readonly status: 422 = 422;
    -}
    +export class UnprocessableEntityError extends APIError<422, Headers> {}

-export class RateLimitError extends APIError {

  • override readonly status: 429 = 429;
    -}
    +export class RateLimitError extends APIError<429, Headers> {}

-export class InternalServerError extends APIError {}
+export class InternalServerError extends APIError<number, Headers> {}

export class LengthFinishReasonError extends OpenAIError {
constructor() {
diff --git src/version.ts src/version.ts
index b4cc35ca9..01cd56405 100644
--- src/version.ts
+++ src/version.ts
@@ -1 +1 @@
-export const VERSION = '4.76.0'; // x-release-please-version
+export const VERSION = '4.76.3'; // x-release-please-version


</details>

### Description
This pull request updates the version of the OpenAI Node SDK from `4.76.0` to `4.76.3`. It includes improvements in test debugging, various documentation fixes, enhances the error class types, and introduces a segfault handler for better error handling in ecosystem tests.

<details>
<summary><i>Changes</i></summary>

### Changes

#### Filename: .release-please-manifest.json
- Updated version
```diff
- { ".": "4.76.0" }
+ { ".": "4.76.3" }

Filename: CHANGELOG.md

  • Added changelog entries for versions 4.76.1, 4.76.2, and 4.76.3
  • Fixed a typo in the documentation links

Filename: README.md

  • Fixed documentation links related to helpers
- [various helpers for your convenience](helpers.md#events)
+ [various helpers for your convenience](helpers.md#chat-events)
- [helpers and events](helpers.md#events).
+ [helpers and events](helpers.md#chat-events).
- [next.js](helpers.md#integrate-wtih-next-js)
+ [next.js](helpers.md#integrate-with-nextjs)

Filename: ecosystem-tests/cli.ts

  • Added segfault-handler for improved error handling in ecosystem tests
+ // @ts-ignore
+ var SegfaultHandler = require('segfault-handler');
+ SegfaultHandler.registerHandler('crash.log');

Filename: jsr.json

  • Updated version
- "version": "4.76.0"
+ "version": "4.76.3"

Filename: package.json

  • Updated version
  • Added segfault-handler as a dev dependency
- "version": "4.76.0"
+ "version": "4.76.3"
+ "segfault-handler": "^1.3.0",

Filename: src/core.ts

  • Removed unnecessary getRequestClient function
  • Optimized URL scheme regex
- this.getRequestClient().fetch.call(undefined, url, { signal: controller.signal as any, ...options })
+ this.fetch.call(undefined, url, { signal: controller.signal as any, ...options })

- protected getRequestClient(): RequestClient {
-   return { fetch: this.fetch };
- }

- // https://stackoverflow.com/a/19709846
- const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
+ // https://url.spec.whatwg.org/#url-scheme-string
+ const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;

Filename: src/error.ts

  • Enhanced error class types using generics

Filename: src/version.ts

  • Updated version
- export const VERSION = '4.76.0'; // x-release-please-version
+ export const VERSION = '4.76.3'; // x-release-please-version
sequenceDiagram
    participant Developer
    participant GitHub Repo
    participant SDK Library
    Developer->>GitHub Repo: Creates pull request
    GitHub Repo->>Developer: Reviews changes
    activate GitHub Repo
    GitHub Repo->>SDK Library: Updates version to 4.76.3
    GitHub Repo->>SDK Library: Updates CHANGELOG.md
    GitHub Repo->>SDK Library: Fixes documentation links
    GitHub Repo-->>Developer: Updates ecosystem tests with segfault handler
    deactivate GitHub Repo
Loading

Security Hotspots

  • ecosystem-tests/cli.ts: Adding segfault-handler introduces the possibility of creating a log file with sensitive information if a segmentation fault occurs. Ensure the log file, crash.log, is correctly secured and sanitized.

@thypon thypon merged commit 7f4c49d into main Dec 23, 2024
8 checks passed
@thypon thypon deleted the renovate/openai-4.x-lockfile branch December 23, 2024 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant