Skip to content

release: 5.8.3 #1561

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
timeout-minutes: 10
name: lint
runs-on: ${{ github.repository == 'stainless-sdks/openai-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v4

Expand All @@ -35,6 +36,7 @@ jobs:
timeout-minutes: 5
name: build
runs-on: ${{ github.repository == 'stainless-sdks/openai-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
permissions:
contents: read
id-token: write
Expand Down Expand Up @@ -70,6 +72,7 @@ jobs:
timeout-minutes: 10
name: test
runs-on: ${{ github.repository == 'stainless-sdks/openai-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "5.8.2"
".": "5.8.3"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 111
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-a473967d1766dc155994d932fbc4a5bcbd1c140a37c20d0a4065e1bf0640536d.yml
openapi_spec_hash: 67cdc62b0d6c8b1de29b7dc54b265749
config_hash: e74d6791681e3af1b548748ff47a22c2
config_hash: 7b53f96f897ca1b3407a5341a6f820db
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 5.8.3 (2025-07-07)

Full Changelog: [v5.8.2...v5.8.3](https://github.com/openai/openai-node/compare/v5.8.2...v5.8.3)

### Bug Fixes

* avoid console usage ([aec57c5](https://github.com/openai/openai-node/commit/aec57c5902b47d2d643f48d98a6014e0e77ba6cc))


### Chores

* add docs to RequestOptions type ([3735172](https://github.com/openai/openai-node/commit/37351723bc5a24c06a96c95e11104cda42a1bec3))
* **ci:** only run for pushes and fork pull requests ([e200bc4](https://github.com/openai/openai-node/commit/e200bc4db18a09d4148fff0056801140411bfa53))
* **client:** improve path param validation ([b5a043b](https://github.com/openai/openai-node/commit/b5a043bc96b6b6bfe8cca05e103a6e4d6fea962b))

## 5.8.2 (2025-06-27)

Full Changelog: [v5.8.1...v5.8.2](https://github.com/openai/openai-node/compare/v5.8.1...v5.8.2)
Expand Down
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openai/openai",
"version": "5.8.2",
"version": "5.8.3",
"exports": {
".": "./index.ts",
"./helpers/zod": "./helpers/zod.ts",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openai",
"version": "5.8.2",
"version": "5.8.3",
"description": "The official TypeScript library for the OpenAI API",
"author": "OpenAI <[email protected]>",
"types": "dist/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ export interface ClientOptions {
*
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
* much longer than this timeout before the promise succeeds or fails.
*
* @unit milliseconds
*/
timeout?: number | undefined;
/**
Expand Down
30 changes: 22 additions & 8 deletions src/core/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { findDoubleNewlineIndex, LineDecoder } from '../internal/decoders/line';
import { ReadableStreamToAsyncIterable } from '../internal/shims';
import { isAbortError } from '../internal/errors';
import { encodeUTF8 } from '../internal/utils/bytes';
import { loggerFor } from '../internal/utils/log';
import type { OpenAI } from '../client';

import { APIError } from './error';

Expand All @@ -18,16 +20,24 @@ export type ServerSentEvent = {

export class Stream<Item> implements AsyncIterable<Item> {
controller: AbortController;
#client: OpenAI | undefined;

constructor(
private iterator: () => AsyncIterator<Item>,
controller: AbortController,
client?: OpenAI,
) {
this.controller = controller;
this.#client = client;
}

static fromSSEResponse<Item>(response: Response, controller: AbortController): Stream<Item> {
static fromSSEResponse<Item>(
response: Response,
controller: AbortController,
client?: OpenAI,
): Stream<Item> {
let consumed = false;
const logger = client ? loggerFor(client) : console;

async function* iterator(): AsyncIterator<Item, any, undefined> {
if (consumed) {
Expand All @@ -54,8 +64,8 @@ export class Stream<Item> implements AsyncIterable<Item> {
try {
data = JSON.parse(sse.data);
} catch (e) {
console.error(`Could not parse message into JSON:`, sse.data);
console.error(`From chunk:`, sse.raw);
logger.error(`Could not parse message into JSON:`, sse.data);
logger.error(`From chunk:`, sse.raw);
throw e;
}

Expand Down Expand Up @@ -91,14 +101,18 @@ export class Stream<Item> implements AsyncIterable<Item> {
}
}

return new Stream(iterator, controller);
return new Stream(iterator, controller, client);
}

/**
* Generates a Stream from a newline-separated ReadableStream
* where each item is a JSON value.
*/
static fromReadableStream<Item>(readableStream: ReadableStream, controller: AbortController): Stream<Item> {
static fromReadableStream<Item>(
readableStream: ReadableStream,
controller: AbortController,
client?: OpenAI,
): Stream<Item> {
let consumed = false;

async function* iterLines(): AsyncGenerator<string, void, unknown> {
Expand Down Expand Up @@ -138,7 +152,7 @@ export class Stream<Item> implements AsyncIterable<Item> {
}
}

return new Stream(iterator, controller);
return new Stream(iterator, controller, client);
}

[Symbol.asyncIterator](): AsyncIterator<Item> {
Expand Down Expand Up @@ -168,8 +182,8 @@ export class Stream<Item> implements AsyncIterable<Item> {
};

return [
new Stream(() => teeIterator(left), this.controller),
new Stream(() => teeIterator(right), this.controller),
new Stream(() => teeIterator(left), this.controller, this.#client),
new Stream(() => teeIterator(right), this.controller, this.#client),
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/internal/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export async function defaultParseResponse<T>(
// that if you set `stream: true` the response type must also be `Stream<T>`

if (props.options.__streamClass) {
return props.options.__streamClass.fromSSEResponse(response, props.controller) as any;
return props.options.__streamClass.fromSSEResponse(response, props.controller, client) as any;
}

return Stream.fromSSEResponse(response, props.controller) as any;
return Stream.fromSSEResponse(response, props.controller, client) as any;
}

// fetch refuses to read the body when the status code is 204.
Expand Down
53 changes: 53 additions & 0 deletions src/internal/request-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,70 @@ import { type HeadersLike } from './headers';
export type FinalRequestOptions = RequestOptions & { method: HTTPMethod; path: string };

export type RequestOptions = {
/**
* The HTTP method for the request (e.g., 'get', 'post', 'put', 'delete').
*/
method?: HTTPMethod;

/**
* The URL path for the request.
*
* @example "/v1/foo"
*/
path?: string;

/**
* Query parameters to include in the request URL.
*/
query?: object | undefined | null;

/**
* The request body. Can be a string, JSON object, FormData, or other supported types.
*/
body?: unknown;

/**
* HTTP headers to include with the request. Can be a Headers object, plain object, or array of tuples.
*/
headers?: HeadersLike;

/**
* The maximum number of times that the client will retry a request in case of a
* temporary failure, like a network error or a 5XX error from the server.
*
* @default 2
*/
maxRetries?: number;

stream?: boolean | undefined;

/**
* The maximum amount of time (in milliseconds) that the client should wait for a response
* from the server before timing out a single request.
*
* @unit milliseconds
*/
timeout?: number;

/**
* Additional `RequestInit` options to be passed to the underlying `fetch` call.
* These options will be merged with the client's default fetch options.
*/
fetchOptions?: MergedRequestInit;

/**
* An AbortSignal that can be used to cancel the request.
*/
signal?: AbortSignal | undefined | null;

/**
* A unique key for this request to enable idempotency.
*/
idempotencyKey?: string;

/**
* Override the default base URL for this specific request.
*/
defaultBaseURL?: string | undefined;

__metadata?: Record<string, unknown>;
Expand Down
2 changes: 1 addition & 1 deletion src/internal/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const multipartFormRequestOptions = async (
return { ...opts, body: await createForm(opts.body, fetch) };
};

const supportsFormDataMap = /** @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();

/**
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
Expand Down
2 changes: 1 addition & 1 deletion src/internal/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const noopLogger = {
debug: noop,
};

let cachedLoggers = /** @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();

export function loggerFor(client: OpenAI): Logger {
const logger = client.logger;
Expand Down
39 changes: 32 additions & 7 deletions src/internal/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,43 @@ export function encodeURIPath(str: string) {
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
}

const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));

export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
function path(statics: readonly string[], ...params: readonly unknown[]): string {
// If there are no params, no processing is needed.
if (statics.length === 1) return statics[0]!;

let postPath = false;
const invalidSegments = [];
const path = statics.reduce((previousValue, currentValue, index) => {
if (/[?#]/.test(currentValue)) {
postPath = true;
}
return (
previousValue +
currentValue +
(index === params.length ? '' : (postPath ? encodeURIComponent : pathEncoder)(String(params[index])))
);
const value = params[index];
let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
if (
index !== params.length &&
(value == null ||
(typeof value === 'object' &&
// handle values from other realms
value.toString ===
Object.getPrototypeOf(Object.getPrototypeOf((value as any).hasOwnProperty ?? EMPTY) ?? EMPTY)
?.toString))
) {
encoded = value + '';
invalidSegments.push({
start: previousValue.length + currentValue.length,
length: encoded.length,
error: `Value of type ${Object.prototype.toString
.call(value)
.slice(8, -1)} is not a valid path parameter`,
});
}
return previousValue + currentValue + (index === params.length ? '' : encoded);
}, '');

const pathOnly = path.split(/[?#]/, 1)[0]!;
const invalidSegments = [];
const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
let match;

Expand All @@ -39,9 +57,12 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
invalidSegments.push({
start: match.index,
length: match[0].length,
error: `Value "${match[0]}" can\'t be safely passed as a path parameter`,
});
}

invalidSegments.sort((a, b) => a.start - b.start);

if (invalidSegments.length > 0) {
let lastEnd = 0;
const underline = invalidSegments.reduce((acc, segment) => {
Expand All @@ -51,7 +72,11 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
return acc + spaces + arrows;
}, '');

throw new OpenAIError(`Path parameters result in path with invalid segments:\n${path}\n${underline}`);
throw new OpenAIError(
`Path parameters result in path with invalid segments:\n${invalidSegments
.map((e) => e.error)
.join('\n')}\n${path}\n${underline}`,
);
}

return path;
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '5.8.2'; // x-release-please-version
export const VERSION = '5.8.3'; // x-release-please-version
Loading
Loading