Skip to content

Commit eb84f42

Browse files
feat(api): update api shapes for usage and code interpreter
1 parent 3c88b95 commit eb84f42

File tree

8 files changed

+505
-363
lines changed

8 files changed

+505
-363
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: 97
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
@@ -283,7 +283,7 @@ Response Types:
283283
Methods:
284284

285285
- <code title="post /fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions">client.FineTuning.Checkpoints.Permissions.<a href="https://pkg.go.dev/github.com/openai/openai-go#FineTuningCheckpointPermissionService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, fineTunedModelCheckpoint <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FineTuningCheckpointPermissionNewParams">FineTuningCheckpointPermissionNewParams</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/packages/pagination#Page">Page</a>[<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FineTuningCheckpointPermissionNewResponse">FineTuningCheckpointPermissionNewResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
286-
- <code title="get /fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions">client.FineTuning.Checkpoints.Permissions.<a href="https://pkg.go.dev/github.com/openai/openai-go#FineTuningCheckpointPermissionService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, fineTunedModelCheckpoint <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FineTuningCheckpointPermissionGetParams">FineTuningCheckpointPermissionGetParams</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/packages/pagination#CursorPage">CursorPage</a>[<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FineTuningCheckpointPermissionGetResponse">FineTuningCheckpointPermissionGetResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
286+
- <code title="get /fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions">client.FineTuning.Checkpoints.Permissions.<a href="https://pkg.go.dev/github.com/openai/openai-go#FineTuningCheckpointPermissionService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, fineTunedModelCheckpoint <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FineTuningCheckpointPermissionGetParams">FineTuningCheckpointPermissionGetParams</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FineTuningCheckpointPermissionGetResponse">FineTuningCheckpointPermissionGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
287287
- <code title="delete /fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions/{permission_id}">client.FineTuning.Checkpoints.Permissions.<a href="https://pkg.go.dev/github.com/openai/openai-go#FineTuningCheckpointPermissionService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, fineTunedModelCheckpoint <a href="https://pkg.go.dev/builtin#string">string</a>, permissionID <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#FineTuningCheckpointPermissionDeleteResponse">FineTuningCheckpointPermissionDeleteResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
288288

289289
## Alpha

audiospeech.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,18 @@ type AudioSpeechNewParams struct {
6363
// work with `tts-1` or `tts-1-hd`.
6464
Instructions param.Opt[string] `json:"instructions,omitzero"`
6565
// The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is
66-
// the default. Does not work with `gpt-4o-mini-tts`.
66+
// the default.
6767
Speed param.Opt[float64] `json:"speed,omitzero"`
6868
// The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`,
6969
// `wav`, and `pcm`.
7070
//
7171
// Any of "mp3", "opus", "aac", "flac", "wav", "pcm".
7272
ResponseFormat AudioSpeechNewParamsResponseFormat `json:"response_format,omitzero"`
73+
// The format to stream the audio in. Supported formats are `sse` and `audio`.
74+
// `sse` is not supported for `tts-1` or `tts-1-hd`.
75+
//
76+
// Any of "sse", "audio".
77+
StreamFormat AudioSpeechNewParamsStreamFormat `json:"stream_format,omitzero"`
7378
paramObj
7479
}
7580

@@ -113,3 +118,12 @@ const (
113118
AudioSpeechNewParamsResponseFormatWAV AudioSpeechNewParamsResponseFormat = "wav"
114119
AudioSpeechNewParamsResponseFormatPCM AudioSpeechNewParamsResponseFormat = "pcm"
115120
)
121+
122+
// The format to stream the audio in. Supported formats are `sse` and `audio`.
123+
// `sse` is not supported for `tts-1` or `tts-1-hd`.
124+
type AudioSpeechNewParamsStreamFormat string
125+
126+
const (
127+
AudioSpeechNewParamsStreamFormatSSE AudioSpeechNewParamsStreamFormat = "sse"
128+
AudioSpeechNewParamsStreamFormatAudio AudioSpeechNewParamsStreamFormat = "audio"
129+
)

audiospeech_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestAudioSpeechNewWithOptionalParams(t *testing.T) {
3333
Instructions: openai.String("instructions"),
3434
ResponseFormat: openai.AudioSpeechNewParamsResponseFormatMP3,
3535
Speed: openai.Float(0.25),
36+
StreamFormat: openai.AudioSpeechNewParamsStreamFormatSSE,
3637
})
3738
if err != nil {
3839
var apierr *openai.Error

audiotranscription.go

Lines changed: 208 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,13 @@ type Transcription struct {
7171
// models `gpt-4o-transcribe` and `gpt-4o-mini-transcribe` if `logprobs` is added
7272
// to the `include` array.
7373
Logprobs []TranscriptionLogprob `json:"logprobs"`
74+
// Token usage statistics for the request.
75+
Usage TranscriptionUsageUnion `json:"usage"`
7476
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
7577
JSON struct {
7678
Text respjson.Field
7779
Logprobs respjson.Field
80+
Usage respjson.Field
7881
ExtraFields map[string]respjson.Field
7982
raw string
8083
} `json:"-"`
@@ -109,6 +112,153 @@ func (r *TranscriptionLogprob) UnmarshalJSON(data []byte) error {
109112
return apijson.UnmarshalRoot(data, r)
110113
}
111114

115+
// TranscriptionUsageUnion contains all possible properties and values from
116+
// [TranscriptionUsageTokens], [TranscriptionUsageDuration].
117+
//
118+
// Use the [TranscriptionUsageUnion.AsAny] method to switch on the variant.
119+
//
120+
// Use the methods beginning with 'As' to cast the union to one of its variants.
121+
type TranscriptionUsageUnion struct {
122+
// This field is from variant [TranscriptionUsageTokens].
123+
InputTokens int64 `json:"input_tokens"`
124+
// This field is from variant [TranscriptionUsageTokens].
125+
OutputTokens int64 `json:"output_tokens"`
126+
// This field is from variant [TranscriptionUsageTokens].
127+
TotalTokens int64 `json:"total_tokens"`
128+
// Any of "tokens", "duration".
129+
Type string `json:"type"`
130+
// This field is from variant [TranscriptionUsageTokens].
131+
InputTokenDetails TranscriptionUsageTokensInputTokenDetails `json:"input_token_details"`
132+
// This field is from variant [TranscriptionUsageDuration].
133+
Duration float64 `json:"duration"`
134+
JSON struct {
135+
InputTokens respjson.Field
136+
OutputTokens respjson.Field
137+
TotalTokens respjson.Field
138+
Type respjson.Field
139+
InputTokenDetails respjson.Field
140+
Duration respjson.Field
141+
raw string
142+
} `json:"-"`
143+
}
144+
145+
// anyTranscriptionUsage is implemented by each variant of
146+
// [TranscriptionUsageUnion] to add type safety for the return type of
147+
// [TranscriptionUsageUnion.AsAny]
148+
type anyTranscriptionUsage interface {
149+
implTranscriptionUsageUnion()
150+
}
151+
152+
func (TranscriptionUsageTokens) implTranscriptionUsageUnion() {}
153+
func (TranscriptionUsageDuration) implTranscriptionUsageUnion() {}
154+
155+
// Use the following switch statement to find the correct variant
156+
//
157+
// switch variant := TranscriptionUsageUnion.AsAny().(type) {
158+
// case openai.TranscriptionUsageTokens:
159+
// case openai.TranscriptionUsageDuration:
160+
// default:
161+
// fmt.Errorf("no variant present")
162+
// }
163+
func (u TranscriptionUsageUnion) AsAny() anyTranscriptionUsage {
164+
switch u.Type {
165+
case "tokens":
166+
return u.AsTokens()
167+
case "duration":
168+
return u.AsDuration()
169+
}
170+
return nil
171+
}
172+
173+
func (u TranscriptionUsageUnion) AsTokens() (v TranscriptionUsageTokens) {
174+
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
175+
return
176+
}
177+
178+
func (u TranscriptionUsageUnion) AsDuration() (v TranscriptionUsageDuration) {
179+
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
180+
return
181+
}
182+
183+
// Returns the unmodified JSON received from the API
184+
func (u TranscriptionUsageUnion) RawJSON() string { return u.JSON.raw }
185+
186+
func (r *TranscriptionUsageUnion) UnmarshalJSON(data []byte) error {
187+
return apijson.UnmarshalRoot(data, r)
188+
}
189+
190+
// Usage statistics for models billed by token usage.
191+
type TranscriptionUsageTokens struct {
192+
// Number of input tokens billed for this request.
193+
InputTokens int64 `json:"input_tokens,required"`
194+
// Number of output tokens generated.
195+
OutputTokens int64 `json:"output_tokens,required"`
196+
// Total number of tokens used (input + output).
197+
TotalTokens int64 `json:"total_tokens,required"`
198+
// The type of the usage object. Always `tokens` for this variant.
199+
Type constant.Tokens `json:"type,required"`
200+
// Details about the input tokens billed for this request.
201+
InputTokenDetails TranscriptionUsageTokensInputTokenDetails `json:"input_token_details"`
202+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
203+
JSON struct {
204+
InputTokens respjson.Field
205+
OutputTokens respjson.Field
206+
TotalTokens respjson.Field
207+
Type respjson.Field
208+
InputTokenDetails respjson.Field
209+
ExtraFields map[string]respjson.Field
210+
raw string
211+
} `json:"-"`
212+
}
213+
214+
// Returns the unmodified JSON received from the API
215+
func (r TranscriptionUsageTokens) RawJSON() string { return r.JSON.raw }
216+
func (r *TranscriptionUsageTokens) UnmarshalJSON(data []byte) error {
217+
return apijson.UnmarshalRoot(data, r)
218+
}
219+
220+
// Details about the input tokens billed for this request.
221+
type TranscriptionUsageTokensInputTokenDetails struct {
222+
// Number of audio tokens billed for this request.
223+
AudioTokens int64 `json:"audio_tokens"`
224+
// Number of text tokens billed for this request.
225+
TextTokens int64 `json:"text_tokens"`
226+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
227+
JSON struct {
228+
AudioTokens respjson.Field
229+
TextTokens respjson.Field
230+
ExtraFields map[string]respjson.Field
231+
raw string
232+
} `json:"-"`
233+
}
234+
235+
// Returns the unmodified JSON received from the API
236+
func (r TranscriptionUsageTokensInputTokenDetails) RawJSON() string { return r.JSON.raw }
237+
func (r *TranscriptionUsageTokensInputTokenDetails) UnmarshalJSON(data []byte) error {
238+
return apijson.UnmarshalRoot(data, r)
239+
}
240+
241+
// Usage statistics for models billed by audio input duration.
242+
type TranscriptionUsageDuration struct {
243+
// Duration of the input audio in seconds.
244+
Duration float64 `json:"duration,required"`
245+
// The type of the usage object. Always `duration` for this variant.
246+
Type constant.Duration `json:"type,required"`
247+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
248+
JSON struct {
249+
Duration respjson.Field
250+
Type respjson.Field
251+
ExtraFields map[string]respjson.Field
252+
raw string
253+
} `json:"-"`
254+
}
255+
256+
// Returns the unmodified JSON received from the API
257+
func (r TranscriptionUsageDuration) RawJSON() string { return r.JSON.raw }
258+
func (r *TranscriptionUsageDuration) UnmarshalJSON(data []byte) error {
259+
return apijson.UnmarshalRoot(data, r)
260+
}
261+
112262
type TranscriptionInclude string
113263

114264
const (
@@ -131,11 +281,14 @@ type TranscriptionStreamEventUnion struct {
131281
Logprobs TranscriptionStreamEventUnionLogprobs `json:"logprobs"`
132282
// This field is from variant [TranscriptionTextDoneEvent].
133283
Text string `json:"text"`
134-
JSON struct {
284+
// This field is from variant [TranscriptionTextDoneEvent].
285+
Usage TranscriptionTextDoneEventUsage `json:"usage"`
286+
JSON struct {
135287
Delta respjson.Field
136288
Type respjson.Field
137289
Logprobs respjson.Field
138290
Text respjson.Field
291+
Usage respjson.Field
139292
raw string
140293
} `json:"-"`
141294
}
@@ -279,11 +432,14 @@ type TranscriptionTextDoneEvent struct {
279432
// [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)
280433
// with the `include[]` parameter set to `logprobs`.
281434
Logprobs []TranscriptionTextDoneEventLogprob `json:"logprobs"`
435+
// Usage statistics for models billed by token usage.
436+
Usage TranscriptionTextDoneEventUsage `json:"usage"`
282437
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
283438
JSON struct {
284439
Text respjson.Field
285440
Type respjson.Field
286441
Logprobs respjson.Field
442+
Usage respjson.Field
287443
ExtraFields map[string]respjson.Field
288444
raw string
289445
} `json:"-"`
@@ -318,6 +474,57 @@ func (r *TranscriptionTextDoneEventLogprob) UnmarshalJSON(data []byte) error {
318474
return apijson.UnmarshalRoot(data, r)
319475
}
320476

477+
// Usage statistics for models billed by token usage.
478+
type TranscriptionTextDoneEventUsage struct {
479+
// Number of input tokens billed for this request.
480+
InputTokens int64 `json:"input_tokens,required"`
481+
// Number of output tokens generated.
482+
OutputTokens int64 `json:"output_tokens,required"`
483+
// Total number of tokens used (input + output).
484+
TotalTokens int64 `json:"total_tokens,required"`
485+
// The type of the usage object. Always `tokens` for this variant.
486+
Type constant.Tokens `json:"type,required"`
487+
// Details about the input tokens billed for this request.
488+
InputTokenDetails TranscriptionTextDoneEventUsageInputTokenDetails `json:"input_token_details"`
489+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
490+
JSON struct {
491+
InputTokens respjson.Field
492+
OutputTokens respjson.Field
493+
TotalTokens respjson.Field
494+
Type respjson.Field
495+
InputTokenDetails respjson.Field
496+
ExtraFields map[string]respjson.Field
497+
raw string
498+
} `json:"-"`
499+
}
500+
501+
// Returns the unmodified JSON received from the API
502+
func (r TranscriptionTextDoneEventUsage) RawJSON() string { return r.JSON.raw }
503+
func (r *TranscriptionTextDoneEventUsage) UnmarshalJSON(data []byte) error {
504+
return apijson.UnmarshalRoot(data, r)
505+
}
506+
507+
// Details about the input tokens billed for this request.
508+
type TranscriptionTextDoneEventUsageInputTokenDetails struct {
509+
// Number of audio tokens billed for this request.
510+
AudioTokens int64 `json:"audio_tokens"`
511+
// Number of text tokens billed for this request.
512+
TextTokens int64 `json:"text_tokens"`
513+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
514+
JSON struct {
515+
AudioTokens respjson.Field
516+
TextTokens respjson.Field
517+
ExtraFields map[string]respjson.Field
518+
raw string
519+
} `json:"-"`
520+
}
521+
522+
// Returns the unmodified JSON received from the API
523+
func (r TranscriptionTextDoneEventUsageInputTokenDetails) RawJSON() string { return r.JSON.raw }
524+
func (r *TranscriptionTextDoneEventUsageInputTokenDetails) UnmarshalJSON(data []byte) error {
525+
return apijson.UnmarshalRoot(data, r)
526+
}
527+
321528
type AudioTranscriptionNewParams struct {
322529
// The audio file object (not file name) to transcribe, in one of these formats:
323530
// flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.

0 commit comments

Comments
 (0)