From f2100e89334753e7f580f7f20f48b43eb8ba2fe3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 23 Jun 2025 18:18:04 +0000 Subject: [PATCH 1/2] feat(api): update api shapes for usage and code interpreter --- .stats.yml | 6 +- api.md | 2 +- src/resources/audio/speech.ts | 8 +- src/resources/audio/transcriptions.ts | 141 ++++++++++++++++++ src/resources/beta/realtime/realtime.ts | 12 +- src/resources/beta/realtime/sessions.ts | 17 +-- .../fine-tuning/checkpoints/checkpoints.ts | 2 - .../fine-tuning/checkpoints/index.ts | 1 - .../fine-tuning/checkpoints/permissions.ts | 88 ++++++----- src/resources/responses/responses.ts | 116 +++++++------- tests/api-resources/audio/speech.test.ts | 1 + 11 files changed, 285 insertions(+), 109 deletions(-) diff --git a/.stats.yml b/.stats.yml index f8abf5bab..1e0182cf2 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 111 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-f411a68f272b8be0ab0c266043da33228687b9b2d76896724e3cef797de9563d.yml -openapi_spec_hash: 89bf866ea95ecfb3d76c8833237047d6 -config_hash: dc5515e257676a27cb1ace1784aa92b3 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-ef4ecb19eb61e24c49d77fef769ee243e5279bc0bdbaee8d0f8dba4da8722559.yml +openapi_spec_hash: 1b8a9767c9f04e6865b06c41948cdc24 +config_hash: fd2af1d5eff0995bb7dc02ac9a34851d diff --git a/api.md b/api.md index 284ecf469..4e2de3252 100644 --- a/api.md +++ b/api.md @@ -259,7 +259,7 @@ Types: Methods: - client.fineTuning.checkpoints.permissions.create(fineTunedModelCheckpoint, { ...params }) -> PermissionCreateResponsesPage -- client.fineTuning.checkpoints.permissions.retrieve(fineTunedModelCheckpoint, { ...params }) -> PermissionRetrieveResponsesPage +- client.fineTuning.checkpoints.permissions.retrieve(fineTunedModelCheckpoint, { ...params }) -> PermissionRetrieveResponse - client.fineTuning.checkpoints.permissions.delete(permissionID, { ...params }) -> PermissionDeleteResponse ## Alpha diff --git a/src/resources/audio/speech.ts b/src/resources/audio/speech.ts index 41d890ccf..6bb092863 100644 --- a/src/resources/audio/speech.ts +++ b/src/resources/audio/speech.ts @@ -79,9 +79,15 @@ export interface SpeechCreateParams { /** * The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is - * the default. Does not work with `gpt-4o-mini-tts`. + * the default. */ speed?: number; + + /** + * The format to stream the audio in. Supported formats are `sse` and `audio`. + * `sse` is not supported for `tts-1` or `tts-1-hd`. + */ + stream_format?: 'sse' | 'audio'; } export declare namespace Speech { diff --git a/src/resources/audio/transcriptions.ts b/src/resources/audio/transcriptions.ts index 33622bb84..1a3e22af7 100644 --- a/src/resources/audio/transcriptions.ts +++ b/src/resources/audio/transcriptions.ts @@ -78,6 +78,11 @@ export interface Transcription { * to the `include` array. */ logprobs?: Array; + + /** + * Token usage statistics for the request. + */ + usage?: Transcription.Tokens | Transcription.Duration; } export namespace Transcription { @@ -97,6 +102,68 @@ export namespace Transcription { */ logprob?: number; } + + /** + * Usage statistics for models billed by token usage. + */ + export interface Tokens { + /** + * Number of input tokens billed for this request. + */ + input_tokens: number; + + /** + * Number of output tokens generated. + */ + output_tokens: number; + + /** + * Total number of tokens used (input + output). + */ + total_tokens: number; + + /** + * The type of the usage object. Always `tokens` for this variant. + */ + type: 'tokens'; + + /** + * Details about the input tokens billed for this request. + */ + input_token_details?: Tokens.InputTokenDetails; + } + + export namespace Tokens { + /** + * Details about the input tokens billed for this request. + */ + export interface InputTokenDetails { + /** + * Number of audio tokens billed for this request. + */ + audio_tokens?: number; + + /** + * Number of text tokens billed for this request. + */ + text_tokens?: number; + } + } + + /** + * Usage statistics for models billed by audio input duration. + */ + export interface Duration { + /** + * Duration of the input audio in seconds. + */ + duration: number; + + /** + * The type of the usage object. Always `duration` for this variant. + */ + type: 'duration'; + } } export type TranscriptionInclude = 'logprobs'; @@ -232,6 +299,11 @@ export interface TranscriptionTextDoneEvent { * with the `include[]` parameter set to `logprobs`. */ logprobs?: Array; + + /** + * Usage statistics for models billed by token usage. + */ + usage?: TranscriptionTextDoneEvent.Usage; } export namespace TranscriptionTextDoneEvent { @@ -251,6 +323,53 @@ export namespace TranscriptionTextDoneEvent { */ logprob?: number; } + + /** + * Usage statistics for models billed by token usage. + */ + export interface Usage { + /** + * Number of input tokens billed for this request. + */ + input_tokens: number; + + /** + * Number of output tokens generated. + */ + output_tokens: number; + + /** + * Total number of tokens used (input + output). + */ + total_tokens: number; + + /** + * The type of the usage object. Always `tokens` for this variant. + */ + type: 'tokens'; + + /** + * Details about the input tokens billed for this request. + */ + input_token_details?: Usage.InputTokenDetails; + } + + export namespace Usage { + /** + * Details about the input tokens billed for this request. + */ + export interface InputTokenDetails { + /** + * Number of audio tokens billed for this request. + */ + audio_tokens?: number; + + /** + * Number of text tokens billed for this request. + */ + text_tokens?: number; + } + } } /** @@ -278,12 +397,34 @@ export interface TranscriptionVerbose { */ segments?: Array; + /** + * Usage statistics for models billed by audio input duration. + */ + usage?: TranscriptionVerbose.Usage; + /** * Extracted words and their corresponding timestamps. */ words?: Array; } +export namespace TranscriptionVerbose { + /** + * Usage statistics for models billed by audio input duration. + */ + export interface Usage { + /** + * Duration of the input audio in seconds. + */ + duration: number; + + /** + * The type of the usage object. Always `duration` for this variant. + */ + type: 'duration'; + } +} + export interface TranscriptionWord { /** * End time of the word in seconds. diff --git a/src/resources/beta/realtime/realtime.ts b/src/resources/beta/realtime/realtime.ts index 5f38aae3a..c7e7712ec 100644 --- a/src/resources/beta/realtime/realtime.ts +++ b/src/resources/beta/realtime/realtime.ts @@ -279,9 +279,9 @@ export interface ConversationItemDeletedEvent { * the Response events. * * Realtime API models accept audio natively, and thus input transcription is a - * separate process run on a separate ASR (Automatic Speech Recognition) model, - * currently always `whisper-1`. Thus the transcript may diverge somewhat from the - * model's interpretation, and should be treated as a rough guide. + * separate process run on a separate ASR (Automatic Speech Recognition) model. The + * transcript may diverge somewhat from the model's interpretation, and should be + * treated as a rough guide. */ export interface ConversationItemInputAudioTranscriptionCompletedEvent { /** @@ -2248,19 +2248,19 @@ export namespace SessionUpdateEvent { /** * Configuration for the ephemeral token expiration. */ - expires_at?: ClientSecret.ExpiresAt; + expires_after?: ClientSecret.ExpiresAfter; } export namespace ClientSecret { /** * Configuration for the ephemeral token expiration. */ - export interface ExpiresAt { + export interface ExpiresAfter { /** * The anchor point for the ephemeral token expiration. Only `created_at` is * currently supported. */ - anchor?: 'created_at'; + anchor: 'created_at'; /** * The number of seconds from the anchor point to the expiration. Select a value diff --git a/src/resources/beta/realtime/sessions.ts b/src/resources/beta/realtime/sessions.ts index d39d2d202..b3a4eda8d 100644 --- a/src/resources/beta/realtime/sessions.ts +++ b/src/resources/beta/realtime/sessions.ts @@ -356,8 +356,8 @@ export interface SessionCreateResponse { * Configuration for input audio transcription, defaults to off and can be set to * `null` to turn off once on. Input audio transcription is not native to the * model, since the model consumes audio directly. Transcription runs - * asynchronously through Whisper and should be treated as rough guidance rather - * than the representation understood by the model. + * asynchronously and should be treated as rough guidance rather than the + * representation understood by the model. */ input_audio_transcription?: SessionCreateResponse.InputAudioTranscription; @@ -476,13 +476,12 @@ export namespace SessionCreateResponse { * Configuration for input audio transcription, defaults to off and can be set to * `null` to turn off once on. Input audio transcription is not native to the * model, since the model consumes audio directly. Transcription runs - * asynchronously through Whisper and should be treated as rough guidance rather - * than the representation understood by the model. + * asynchronously and should be treated as rough guidance rather than the + * representation understood by the model. */ export interface InputAudioTranscription { /** - * The model to use for transcription, `whisper-1` is the only currently supported - * model. + * The model to use for transcription. */ model?: string; } @@ -721,19 +720,19 @@ export namespace SessionCreateParams { /** * Configuration for the ephemeral token expiration. */ - expires_at?: ClientSecret.ExpiresAt; + expires_after?: ClientSecret.ExpiresAfter; } export namespace ClientSecret { /** * Configuration for the ephemeral token expiration. */ - export interface ExpiresAt { + export interface ExpiresAfter { /** * The anchor point for the ephemeral token expiration. Only `created_at` is * currently supported. */ - anchor?: 'created_at'; + anchor: 'created_at'; /** * The number of seconds from the anchor point to the expiration. Select a value diff --git a/src/resources/fine-tuning/checkpoints/checkpoints.ts b/src/resources/fine-tuning/checkpoints/checkpoints.ts index 124c7faaf..da055b0e4 100644 --- a/src/resources/fine-tuning/checkpoints/checkpoints.ts +++ b/src/resources/fine-tuning/checkpoints/checkpoints.ts @@ -10,7 +10,6 @@ import { PermissionDeleteResponse, PermissionRetrieveParams, PermissionRetrieveResponse, - PermissionRetrieveResponsesPage, Permissions, } from './permissions'; @@ -27,7 +26,6 @@ export declare namespace Checkpoints { type PermissionRetrieveResponse as PermissionRetrieveResponse, type PermissionDeleteResponse as PermissionDeleteResponse, type PermissionCreateResponsesPage as PermissionCreateResponsesPage, - type PermissionRetrieveResponsesPage as PermissionRetrieveResponsesPage, type PermissionCreateParams as PermissionCreateParams, type PermissionRetrieveParams as PermissionRetrieveParams, type PermissionDeleteParams as PermissionDeleteParams, diff --git a/src/resources/fine-tuning/checkpoints/index.ts b/src/resources/fine-tuning/checkpoints/index.ts index 0457329bc..7e04fc667 100644 --- a/src/resources/fine-tuning/checkpoints/index.ts +++ b/src/resources/fine-tuning/checkpoints/index.ts @@ -10,5 +10,4 @@ export { type PermissionRetrieveParams, type PermissionDeleteParams, type PermissionCreateResponsesPage, - type PermissionRetrieveResponsesPage, } from './permissions'; diff --git a/src/resources/fine-tuning/checkpoints/permissions.ts b/src/resources/fine-tuning/checkpoints/permissions.ts index 75b89090e..9217f324c 100644 --- a/src/resources/fine-tuning/checkpoints/permissions.ts +++ b/src/resources/fine-tuning/checkpoints/permissions.ts @@ -2,7 +2,7 @@ import { APIResource } from '../../../core/resource'; import { APIPromise } from '../../../core/api-promise'; -import { CursorPage, type CursorPageParams, Page, PagePromise } from '../../../core/pagination'; +import { Page, PagePromise } from '../../../core/pagination'; import { RequestOptions } from '../../../internal/request-options'; import { path } from '../../../internal/utils/path'; @@ -44,24 +44,21 @@ export class Permissions extends APIResource { * * @example * ```ts - * // Automatically fetches more pages as needed. - * for await (const permissionRetrieveResponse of client.fineTuning.checkpoints.permissions.retrieve( - * 'ft-AF1WoRqd3aJAHsqc9NY7iL8F', - * )) { - * // ... - * } + * const permission = + * await client.fineTuning.checkpoints.permissions.retrieve( + * 'ft-AF1WoRqd3aJAHsqc9NY7iL8F', + * ); * ``` */ retrieve( fineTunedModelCheckpoint: string, query: PermissionRetrieveParams | null | undefined = {}, options?: RequestOptions, - ): PagePromise { - return this._client.getAPIList( - path`/fine_tuning/checkpoints/${fineTunedModelCheckpoint}/permissions`, - CursorPage, - { query, ...options }, - ); + ): APIPromise { + return this._client.get(path`/fine_tuning/checkpoints/${fineTunedModelCheckpoint}/permissions`, { + query, + ...options, + }); } /** @@ -98,8 +95,6 @@ export class Permissions extends APIResource { // Note: no pagination actually occurs yet, this is for forwards-compatibility. export type PermissionCreateResponsesPage = Page; -export type PermissionRetrieveResponsesPage = CursorPage; - /** * The `checkpoint.permission` object represents a permission for a fine-tuned * model checkpoint. @@ -126,30 +121,44 @@ export interface PermissionCreateResponse { project_id: string; } -/** - * The `checkpoint.permission` object represents a permission for a fine-tuned - * model checkpoint. - */ export interface PermissionRetrieveResponse { - /** - * The permission identifier, which can be referenced in the API endpoints. - */ - id: string; + data: Array; - /** - * The Unix timestamp (in seconds) for when the permission was created. - */ - created_at: number; + has_more: boolean; - /** - * The object type, which is always "checkpoint.permission". - */ - object: 'checkpoint.permission'; + object: 'list'; + first_id?: string | null; + + last_id?: string | null; +} + +export namespace PermissionRetrieveResponse { /** - * The project identifier that the permission is for. + * The `checkpoint.permission` object represents a permission for a fine-tuned + * model checkpoint. */ - project_id: string; + export interface Data { + /** + * The permission identifier, which can be referenced in the API endpoints. + */ + id: string; + + /** + * The Unix timestamp (in seconds) for when the permission was created. + */ + created_at: number; + + /** + * The object type, which is always "checkpoint.permission". + */ + object: 'checkpoint.permission'; + + /** + * The project identifier that the permission is for. + */ + project_id: string; + } } export interface PermissionDeleteResponse { @@ -176,7 +185,17 @@ export interface PermissionCreateParams { project_ids: Array; } -export interface PermissionRetrieveParams extends CursorPageParams { +export interface PermissionRetrieveParams { + /** + * Identifier for the last permission ID from the previous pagination request. + */ + after?: string; + + /** + * Number of permissions to retrieve. + */ + limit?: number; + /** * The order in which to retrieve permissions. */ @@ -201,7 +220,6 @@ export declare namespace Permissions { type PermissionRetrieveResponse as PermissionRetrieveResponse, type PermissionDeleteResponse as PermissionDeleteResponse, type PermissionCreateResponsesPage as PermissionCreateResponsesPage, - type PermissionRetrieveResponsesPage as PermissionRetrieveResponsesPage, type PermissionCreateParams as PermissionCreateParams, type PermissionRetrieveParams as PermissionRetrieveParams, type PermissionDeleteParams as PermissionDeleteParams, diff --git a/src/resources/responses/responses.ts b/src/resources/responses/responses.ts index 69c5d8cbe..0044e82eb 100644 --- a/src/resources/responses/responses.ts +++ b/src/resources/responses/responses.ts @@ -623,21 +623,27 @@ export interface ResponseAudioTranscriptDoneEvent { } /** - * Emitted when a partial code snippet is added by the code interpreter. + * Emitted when a partial code snippet is streamed by the code interpreter. */ export interface ResponseCodeInterpreterCallCodeDeltaEvent { /** - * The partial code snippet added by the code interpreter. + * The partial code snippet being streamed by the code interpreter. */ delta: string; /** - * The index of the output item that the code interpreter call is in progress. + * The unique identifier of the code interpreter tool call item. + */ + item_id: string; + + /** + * The index of the output item in the response for which the code is being + * streamed. */ output_index: number; /** - * The sequence number of this event. + * The sequence number of this event, used to order streaming events. */ sequence_number: number; @@ -648,7 +654,7 @@ export interface ResponseCodeInterpreterCallCodeDeltaEvent { } /** - * Emitted when code snippet output is finalized by the code interpreter. + * Emitted when the code snippet is finalized by the code interpreter. */ export interface ResponseCodeInterpreterCallCodeDoneEvent { /** @@ -657,12 +663,17 @@ export interface ResponseCodeInterpreterCallCodeDoneEvent { code: string; /** - * The index of the output item that the code interpreter call is in progress. + * The unique identifier of the code interpreter tool call item. + */ + item_id: string; + + /** + * The index of the output item in the response for which the code is finalized. */ output_index: number; /** - * The sequence number of this event. + * The sequence number of this event, used to order streaming events. */ sequence_number: number; @@ -677,17 +688,18 @@ export interface ResponseCodeInterpreterCallCodeDoneEvent { */ export interface ResponseCodeInterpreterCallCompletedEvent { /** - * A tool call to run code. + * The unique identifier of the code interpreter tool call item. */ - code_interpreter_call: ResponseCodeInterpreterToolCall; + item_id: string; /** - * The index of the output item that the code interpreter call is in progress. + * The index of the output item in the response for which the code interpreter call + * is completed. */ output_index: number; /** - * The sequence number of this event. + * The sequence number of this event, used to order streaming events. */ sequence_number: number; @@ -702,17 +714,18 @@ export interface ResponseCodeInterpreterCallCompletedEvent { */ export interface ResponseCodeInterpreterCallInProgressEvent { /** - * A tool call to run code. + * The unique identifier of the code interpreter tool call item. */ - code_interpreter_call: ResponseCodeInterpreterToolCall; + item_id: string; /** - * The index of the output item that the code interpreter call is in progress. + * The index of the output item in the response for which the code interpreter call + * is in progress. */ output_index: number; /** - * The sequence number of this event. + * The sequence number of this event, used to order streaming events. */ sequence_number: number; @@ -727,17 +740,18 @@ export interface ResponseCodeInterpreterCallInProgressEvent { */ export interface ResponseCodeInterpreterCallInterpretingEvent { /** - * A tool call to run code. + * The unique identifier of the code interpreter tool call item. */ - code_interpreter_call: ResponseCodeInterpreterToolCall; + item_id: string; /** - * The index of the output item that the code interpreter call is in progress. + * The index of the output item in the response for which the code interpreter is + * interpreting code. */ output_index: number; /** - * The sequence number of this event. + * The sequence number of this event, used to order streaming events. */ sequence_number: number; @@ -757,71 +771,61 @@ export interface ResponseCodeInterpreterToolCall { id: string; /** - * The code to run. + * The code to run, or null if not available. */ - code: string; + code: string | null; /** - * The results of the code interpreter tool call. + * The ID of the container used to run the code. */ - results: Array; + container_id: string; /** - * The status of the code interpreter tool call. + * The outputs generated by the code interpreter, such as logs or images. Can be + * null if no outputs are available. */ - status: 'in_progress' | 'interpreting' | 'completed'; + outputs: Array | null; /** - * The type of the code interpreter tool call. Always `code_interpreter_call`. + * The status of the code interpreter tool call. */ - type: 'code_interpreter_call'; + status: 'in_progress' | 'completed' | 'incomplete' | 'interpreting' | 'failed'; /** - * The ID of the container used to run the code. + * The type of the code interpreter tool call. Always `code_interpreter_call`. */ - container_id?: string; + type: 'code_interpreter_call'; } export namespace ResponseCodeInterpreterToolCall { /** - * The output of a code interpreter tool call that is text. + * The logs output from the code interpreter. */ export interface Logs { /** - * The logs of the code interpreter tool call. + * The logs output from the code interpreter. */ logs: string; /** - * The type of the code interpreter text output. Always `logs`. + * The type of the output. Always 'logs'. */ type: 'logs'; } /** - * The output of a code interpreter tool call that is a file. + * The image output from the code interpreter. */ - export interface Files { - files: Array; - + export interface Image { /** - * The type of the code interpreter file output. Always `files`. + * The type of the output. Always 'image'. */ - type: 'files'; - } + type: 'image'; - export namespace Files { - export interface File { - /** - * The ID of the file. - */ - file_id: string; - - /** - * The MIME type of the file. - */ - mime_type: string; - } + /** + * The URL of the image output from the code interpreter. + */ + url: string; } } @@ -3327,6 +3331,11 @@ export namespace ResponseOutputText { */ file_id: string; + /** + * The filename of the file cited. + */ + filename: string; + /** * The index of the file in the list of files. */ @@ -3387,6 +3396,11 @@ export namespace ResponseOutputText { */ file_id: string; + /** + * The filename of the container file cited. + */ + filename: string; + /** * The index of the first character of the container file citation in the message. */ diff --git a/tests/api-resources/audio/speech.test.ts b/tests/api-resources/audio/speech.test.ts index 191c6a313..63d945ea4 100644 --- a/tests/api-resources/audio/speech.test.ts +++ b/tests/api-resources/audio/speech.test.ts @@ -17,6 +17,7 @@ describe('resource speech', () => { instructions: 'instructions', response_format: 'mp3', speed: 0.25, + stream_format: 'sse', }); }); }); From 9ee48aa7c783bcc58d346e122f388a836f745e54 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 23 Jun 2025 18:18:39 +0000 Subject: [PATCH 2/2] release: 5.7.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ jsr.json | 2 +- package.json | 2 +- src/version.ts | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index d49c9e283..68f9449d5 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "5.6.0" + ".": "5.7.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 69faf741c..3ec8b483e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 5.7.0 (2025-06-23) + +Full Changelog: [v5.6.0...v5.7.0](https://github.com/openai/openai-node/compare/v5.6.0...v5.7.0) + +### Features + +* **api:** update api shapes for usage and code interpreter ([f2100e8](https://github.com/openai/openai-node/commit/f2100e89334753e7f580f7f20f48b43eb8ba2fe3)) + ## 5.6.0 (2025-06-20) Full Changelog: [v5.5.1...v5.6.0](https://github.com/openai/openai-node/compare/v5.5.1...v5.6.0) diff --git a/jsr.json b/jsr.json index 9ab74ece3..83eda605f 100644 --- a/jsr.json +++ b/jsr.json @@ -1,6 +1,6 @@ { "name": "@openai/openai", - "version": "5.6.0", + "version": "5.7.0", "exports": { ".": "./index.ts", "./helpers/zod": "./helpers/zod.ts", diff --git a/package.json b/package.json index d124e6854..94babf897 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openai", - "version": "5.6.0", + "version": "5.7.0", "description": "The official TypeScript library for the OpenAI API", "author": "OpenAI ", "types": "dist/index.d.ts", diff --git a/src/version.ts b/src/version.ts index a0cba220f..3d3704645 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '5.6.0'; // x-release-please-version +export const VERSION = '5.7.0'; // x-release-please-version