Skip to content

Commit 060d566

Browse files
feat(api): update api shapes for usage and code interpreter
1 parent e689216 commit 060d566

25 files changed

+253
-127
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 111
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-f411a68f272b8be0ab0c266043da33228687b9b2d76896724e3cef797de9563d.yml
3-
openapi_spec_hash: 89bf866ea95ecfb3d76c8833237047d6
4-
config_hash: dc5515e257676a27cb1ace1784aa92b3
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-ef4ecb19eb61e24c49d77fef769ee243e5279bc0bdbaee8d0f8dba4da8722559.yml
3+
openapi_spec_hash: 1b8a9767c9f04e6865b06c41948cdc24
4+
config_hash: fd2af1d5eff0995bb7dc02ac9a34851d

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ from openai.types.fine_tuning.checkpoints import (
293293
Methods:
294294

295295
- <code title="post /fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions">client.fine_tuning.checkpoints.permissions.<a href="./src/openai/resources/fine_tuning/checkpoints/permissions.py">create</a>(fine_tuned_model_checkpoint, \*\*<a href="src/openai/types/fine_tuning/checkpoints/permission_create_params.py">params</a>) -> <a href="./src/openai/types/fine_tuning/checkpoints/permission_create_response.py">SyncPage[PermissionCreateResponse]</a></code>
296-
- <code title="get /fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions">client.fine_tuning.checkpoints.permissions.<a href="./src/openai/resources/fine_tuning/checkpoints/permissions.py">retrieve</a>(fine_tuned_model_checkpoint, \*\*<a href="src/openai/types/fine_tuning/checkpoints/permission_retrieve_params.py">params</a>) -> <a href="./src/openai/types/fine_tuning/checkpoints/permission_retrieve_response.py">SyncCursorPage[PermissionRetrieveResponse]</a></code>
296+
- <code title="get /fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions">client.fine_tuning.checkpoints.permissions.<a href="./src/openai/resources/fine_tuning/checkpoints/permissions.py">retrieve</a>(fine_tuned_model_checkpoint, \*\*<a href="src/openai/types/fine_tuning/checkpoints/permission_retrieve_params.py">params</a>) -> <a href="./src/openai/types/fine_tuning/checkpoints/permission_retrieve_response.py">PermissionRetrieveResponse</a></code>
297297
- <code title="delete /fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions/{permission_id}">client.fine_tuning.checkpoints.permissions.<a href="./src/openai/resources/fine_tuning/checkpoints/permissions.py">delete</a>(permission_id, \*, fine_tuned_model_checkpoint) -> <a href="./src/openai/types/fine_tuning/checkpoints/permission_delete_response.py">PermissionDeleteResponse</a></code>
298298

299299
## Alpha

src/openai/resources/audio/speech.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def create(
5656
instructions: str | NotGiven = NOT_GIVEN,
5757
response_format: Literal["mp3", "opus", "aac", "flac", "wav", "pcm"] | NotGiven = NOT_GIVEN,
5858
speed: float | NotGiven = NOT_GIVEN,
59+
stream_format: Literal["sse", "audio"] | NotGiven = NOT_GIVEN,
5960
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
6061
# The extra values given here take precedence over values defined on the client or passed to this method.
6162
extra_headers: Headers | None = None,
@@ -85,7 +86,10 @@ def create(
8586
`wav`, and `pcm`.
8687
8788
speed: The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is
88-
the default. Does not work with `gpt-4o-mini-tts`.
89+
the default.
90+
91+
stream_format: The format to stream the audio in. Supported formats are `sse` and `audio`.
92+
`sse` is not supported for `tts-1` or `tts-1-hd`.
8993
9094
extra_headers: Send extra headers
9195
@@ -106,6 +110,7 @@ def create(
106110
"instructions": instructions,
107111
"response_format": response_format,
108112
"speed": speed,
113+
"stream_format": stream_format,
109114
},
110115
speech_create_params.SpeechCreateParams,
111116
),
@@ -147,6 +152,7 @@ async def create(
147152
instructions: str | NotGiven = NOT_GIVEN,
148153
response_format: Literal["mp3", "opus", "aac", "flac", "wav", "pcm"] | NotGiven = NOT_GIVEN,
149154
speed: float | NotGiven = NOT_GIVEN,
155+
stream_format: Literal["sse", "audio"] | NotGiven = NOT_GIVEN,
150156
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
151157
# The extra values given here take precedence over values defined on the client or passed to this method.
152158
extra_headers: Headers | None = None,
@@ -176,7 +182,10 @@ async def create(
176182
`wav`, and `pcm`.
177183
178184
speed: The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is
179-
the default. Does not work with `gpt-4o-mini-tts`.
185+
the default.
186+
187+
stream_format: The format to stream the audio in. Supported formats are `sse` and `audio`.
188+
`sse` is not supported for `tts-1` or `tts-1-hd`.
180189
181190
extra_headers: Send extra headers
182191
@@ -197,6 +206,7 @@ async def create(
197206
"instructions": instructions,
198207
"response_format": response_format,
199208
"speed": speed,
209+
"stream_format": stream_format,
200210
},
201211
speech_create_params.SpeechCreateParams,
202212
),

src/openai/resources/fine_tuning/checkpoints/permissions.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
from .... import _legacy_response
1111
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
12-
from ...._utils import maybe_transform
12+
from ...._utils import maybe_transform, async_maybe_transform
1313
from ...._compat import cached_property
1414
from ...._resource import SyncAPIResource, AsyncAPIResource
1515
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
16-
from ....pagination import SyncPage, AsyncPage, SyncCursorPage, AsyncCursorPage
16+
from ....pagination import SyncPage, AsyncPage
1717
from ...._base_client import AsyncPaginator, make_request_options
1818
from ....types.fine_tuning.checkpoints import permission_create_params, permission_retrieve_params
1919
from ....types.fine_tuning.checkpoints.permission_create_response import PermissionCreateResponse
@@ -101,7 +101,7 @@ def retrieve(
101101
extra_query: Query | None = None,
102102
extra_body: Body | None = None,
103103
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
104-
) -> SyncCursorPage[PermissionRetrieveResponse]:
104+
) -> PermissionRetrieveResponse:
105105
"""
106106
**NOTE:** This endpoint requires an [admin API key](../admin-api-keys).
107107
@@ -129,9 +129,8 @@ def retrieve(
129129
raise ValueError(
130130
f"Expected a non-empty value for `fine_tuned_model_checkpoint` but received {fine_tuned_model_checkpoint!r}"
131131
)
132-
return self._get_api_list(
132+
return self._get(
133133
f"/fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions",
134-
page=SyncCursorPage[PermissionRetrieveResponse],
135134
options=make_request_options(
136135
extra_headers=extra_headers,
137136
extra_query=extra_query,
@@ -147,7 +146,7 @@ def retrieve(
147146
permission_retrieve_params.PermissionRetrieveParams,
148147
),
149148
),
150-
model=PermissionRetrieveResponse,
149+
cast_to=PermissionRetrieveResponse,
151150
)
152151

153152
def delete(
@@ -256,7 +255,7 @@ def create(
256255
method="post",
257256
)
258257

259-
def retrieve(
258+
async def retrieve(
260259
self,
261260
fine_tuned_model_checkpoint: str,
262261
*,
@@ -270,7 +269,7 @@ def retrieve(
270269
extra_query: Query | None = None,
271270
extra_body: Body | None = None,
272271
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
273-
) -> AsyncPaginator[PermissionRetrieveResponse, AsyncCursorPage[PermissionRetrieveResponse]]:
272+
) -> PermissionRetrieveResponse:
274273
"""
275274
**NOTE:** This endpoint requires an [admin API key](../admin-api-keys).
276275
@@ -298,15 +297,14 @@ def retrieve(
298297
raise ValueError(
299298
f"Expected a non-empty value for `fine_tuned_model_checkpoint` but received {fine_tuned_model_checkpoint!r}"
300299
)
301-
return self._get_api_list(
300+
return await self._get(
302301
f"/fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions",
303-
page=AsyncCursorPage[PermissionRetrieveResponse],
304302
options=make_request_options(
305303
extra_headers=extra_headers,
306304
extra_query=extra_query,
307305
extra_body=extra_body,
308306
timeout=timeout,
309-
query=maybe_transform(
307+
query=await async_maybe_transform(
310308
{
311309
"after": after,
312310
"limit": limit,
@@ -316,7 +314,7 @@ def retrieve(
316314
permission_retrieve_params.PermissionRetrieveParams,
317315
),
318316
),
319-
model=PermissionRetrieveResponse,
317+
cast_to=PermissionRetrieveResponse,
320318
)
321319

322320
async def delete(

src/openai/types/audio/speech_create_params.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ class SpeechCreateParams(TypedDict, total=False):
4848
speed: float
4949
"""The speed of the generated audio.
5050
51-
Select a value from `0.25` to `4.0`. `1.0` is the default. Does not work with
52-
`gpt-4o-mini-tts`.
51+
Select a value from `0.25` to `4.0`. `1.0` is the default.
52+
"""
53+
54+
stream_format: Literal["sse", "audio"]
55+
"""The format to stream the audio in.
56+
57+
Supported formats are `sse` and `audio`. `sse` is not supported for `tts-1` or
58+
`tts-1-hd`.
5359
"""

src/openai/types/audio/transcription.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
from typing import List, Optional
3+
from typing import List, Union, Optional
4+
from typing_extensions import Literal, Annotated, TypeAlias
45

6+
from ..._utils import PropertyInfo
57
from ..._models import BaseModel
68

7-
__all__ = ["Transcription", "Logprob"]
9+
__all__ = ["Transcription", "Logprob", "Usage", "UsageTokens", "UsageTokensInputTokenDetails", "UsageDuration"]
810

911

1012
class Logprob(BaseModel):
@@ -18,6 +20,42 @@ class Logprob(BaseModel):
1820
"""The log probability of the token."""
1921

2022

23+
class UsageTokensInputTokenDetails(BaseModel):
24+
audio_tokens: Optional[int] = None
25+
"""Number of audio tokens billed for this request."""
26+
27+
text_tokens: Optional[int] = None
28+
"""Number of text tokens billed for this request."""
29+
30+
31+
class UsageTokens(BaseModel):
32+
input_tokens: int
33+
"""Number of input tokens billed for this request."""
34+
35+
output_tokens: int
36+
"""Number of output tokens generated."""
37+
38+
total_tokens: int
39+
"""Total number of tokens used (input + output)."""
40+
41+
type: Literal["tokens"]
42+
"""The type of the usage object. Always `tokens` for this variant."""
43+
44+
input_token_details: Optional[UsageTokensInputTokenDetails] = None
45+
"""Details about the input tokens billed for this request."""
46+
47+
48+
class UsageDuration(BaseModel):
49+
duration: float
50+
"""Duration of the input audio in seconds."""
51+
52+
type: Literal["duration"]
53+
"""The type of the usage object. Always `duration` for this variant."""
54+
55+
56+
Usage: TypeAlias = Annotated[Union[UsageTokens, UsageDuration], PropertyInfo(discriminator="type")]
57+
58+
2159
class Transcription(BaseModel):
2260
text: str
2361
"""The transcribed text."""
@@ -28,3 +66,6 @@ class Transcription(BaseModel):
2866
Only returned with the models `gpt-4o-transcribe` and `gpt-4o-mini-transcribe`
2967
if `logprobs` is added to the `include` array.
3068
"""
69+
70+
usage: Optional[Usage] = None
71+
"""Token usage statistics for the request."""

src/openai/types/audio/transcription_text_done_event.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from ..._models import BaseModel
77

8-
__all__ = ["TranscriptionTextDoneEvent", "Logprob"]
8+
__all__ = ["TranscriptionTextDoneEvent", "Logprob", "Usage", "UsageInputTokenDetails"]
99

1010

1111
class Logprob(BaseModel):
@@ -19,6 +19,31 @@ class Logprob(BaseModel):
1919
"""The log probability of the token."""
2020

2121

22+
class UsageInputTokenDetails(BaseModel):
23+
audio_tokens: Optional[int] = None
24+
"""Number of audio tokens billed for this request."""
25+
26+
text_tokens: Optional[int] = None
27+
"""Number of text tokens billed for this request."""
28+
29+
30+
class Usage(BaseModel):
31+
input_tokens: int
32+
"""Number of input tokens billed for this request."""
33+
34+
output_tokens: int
35+
"""Number of output tokens generated."""
36+
37+
total_tokens: int
38+
"""Total number of tokens used (input + output)."""
39+
40+
type: Literal["tokens"]
41+
"""The type of the usage object. Always `tokens` for this variant."""
42+
43+
input_token_details: Optional[UsageInputTokenDetails] = None
44+
"""Details about the input tokens billed for this request."""
45+
46+
2247
class TranscriptionTextDoneEvent(BaseModel):
2348
text: str
2449
"""The text that was transcribed."""
@@ -33,3 +58,6 @@ class TranscriptionTextDoneEvent(BaseModel):
3358
[create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)
3459
with the `include[]` parameter set to `logprobs`.
3560
"""
61+
62+
usage: Optional[Usage] = None
63+
"""Usage statistics for models billed by token usage."""

src/openai/types/audio/transcription_verbose.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
from typing import List, Optional
4+
from typing_extensions import Literal
45

56
from ..._models import BaseModel
67
from .transcription_word import TranscriptionWord
78
from .transcription_segment import TranscriptionSegment
89

9-
__all__ = ["TranscriptionVerbose"]
10+
__all__ = ["TranscriptionVerbose", "Usage"]
11+
12+
13+
class Usage(BaseModel):
14+
duration: float
15+
"""Duration of the input audio in seconds."""
16+
17+
type: Literal["duration"]
18+
"""The type of the usage object. Always `duration` for this variant."""
1019

1120

1221
class TranscriptionVerbose(BaseModel):
@@ -22,5 +31,8 @@ class TranscriptionVerbose(BaseModel):
2231
segments: Optional[List[TranscriptionSegment]] = None
2332
"""Segments of the transcribed text and their corresponding details."""
2433

34+
usage: Optional[Usage] = None
35+
"""Usage statistics for models billed by audio input duration."""
36+
2537
words: Optional[List[TranscriptionWord]] = None
2638
"""Extracted words and their corresponding timestamps."""

src/openai/types/beta/realtime/session_create_params.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from __future__ import annotations
44

55
from typing import List, Union, Iterable
6-
from typing_extensions import Literal, TypeAlias, TypedDict
6+
from typing_extensions import Literal, Required, TypeAlias, TypedDict
77

88
__all__ = [
99
"SessionCreateParams",
1010
"ClientSecret",
11-
"ClientSecretExpiresAt",
11+
"ClientSecretExpiresAfter",
1212
"InputAudioNoiseReduction",
1313
"InputAudioTranscription",
1414
"Tool",
@@ -156,8 +156,8 @@ class SessionCreateParams(TypedDict, total=False):
156156
"""
157157

158158

159-
class ClientSecretExpiresAt(TypedDict, total=False):
160-
anchor: Literal["created_at"]
159+
class ClientSecretExpiresAfter(TypedDict, total=False):
160+
anchor: Required[Literal["created_at"]]
161161
"""The anchor point for the ephemeral token expiration.
162162
163163
Only `created_at` is currently supported.
@@ -171,7 +171,7 @@ class ClientSecretExpiresAt(TypedDict, total=False):
171171

172172

173173
class ClientSecret(TypedDict, total=False):
174-
expires_at: ClientSecretExpiresAt
174+
expires_after: ClientSecretExpiresAfter
175175
"""Configuration for the ephemeral token expiration."""
176176

177177

src/openai/types/beta/realtime/session_create_response.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ class ClientSecret(BaseModel):
3333

3434
class InputAudioTranscription(BaseModel):
3535
model: Optional[str] = None
36-
"""
37-
The model to use for transcription, `whisper-1` is the only currently supported
38-
model.
39-
"""
36+
"""The model to use for transcription."""
4037

4138

4239
class Tool(BaseModel):
@@ -116,8 +113,8 @@ class SessionCreateResponse(BaseModel):
116113
Configuration for input audio transcription, defaults to off and can be set to
117114
`null` to turn off once on. Input audio transcription is not native to the
118115
model, since the model consumes audio directly. Transcription runs
119-
asynchronously through Whisper and should be treated as rough guidance rather
120-
than the representation understood by the model.
116+
asynchronously and should be treated as rough guidance rather than the
117+
representation understood by the model.
121118
"""
122119

123120
instructions: Optional[str] = None

0 commit comments

Comments
 (0)