Skip to content

Commit 16312ea

Browse files
feat(api): manual updates
1 parent 0b9cb85 commit 16312ea

File tree

6 files changed

+190
-20
lines changed

6 files changed

+190
-20
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-b2a451656ca64d30d174391ebfd94806b4de3ab76dc55b92843cfb7f1a54ecb6.yml
3-
openapi_spec_hash: 27d9691b400f28c17ef063a1374048b0
4-
config_hash: e822d0c9082c8b312264403949243179
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-721e6ccaa72205ee14c71f8163129920464fb814b95d3df9567a9476bbd9b7fb.yml
3+
openapi_spec_hash: 2115413a21df8b5bf9e4552a74df4312
4+
config_hash: 9606bb315a193bfd8da0459040143242

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Response Types:
7373
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ChatCompletion">ChatCompletion</a>
7474
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ChatCompletionAudio">ChatCompletionAudio</a>
7575
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ChatCompletionChunk">ChatCompletionChunk</a>
76+
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ChatCompletionContentPartImage">ChatCompletionContentPartImage</a>
77+
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ChatCompletionContentPartText">ChatCompletionContentPartText</a>
7678
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ChatCompletionDeleted">ChatCompletionDeleted</a>
7779
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ChatCompletionMessage">ChatCompletionMessage</a>
7880
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ChatCompletionMessageToolCall">ChatCompletionMessageToolCall</a>

chatcompletion.go

Lines changed: 142 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,59 @@ func (r *ChatCompletionContentPartFileFileParam) UnmarshalJSON(data []byte) erro
964964
return apijson.UnmarshalRoot(data, r)
965965
}
966966

967+
// Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
968+
type ChatCompletionContentPartImage struct {
969+
ImageURL ChatCompletionContentPartImageImageURL `json:"image_url,required"`
970+
// The type of the content part.
971+
Type constant.ImageURL `json:"type,required"`
972+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
973+
JSON struct {
974+
ImageURL respjson.Field
975+
Type respjson.Field
976+
ExtraFields map[string]respjson.Field
977+
raw string
978+
} `json:"-"`
979+
}
980+
981+
// Returns the unmodified JSON received from the API
982+
func (r ChatCompletionContentPartImage) RawJSON() string { return r.JSON.raw }
983+
func (r *ChatCompletionContentPartImage) UnmarshalJSON(data []byte) error {
984+
return apijson.UnmarshalRoot(data, r)
985+
}
986+
987+
// ToParam converts this ChatCompletionContentPartImage to a
988+
// ChatCompletionContentPartImageParam.
989+
//
990+
// Warning: the fields of the param type will not be present. ToParam should only
991+
// be used at the last possible moment before sending a request. Test for this with
992+
// ChatCompletionContentPartImageParam.Overrides()
993+
func (r ChatCompletionContentPartImage) ToParam() ChatCompletionContentPartImageParam {
994+
return param.Override[ChatCompletionContentPartImageParam](json.RawMessage(r.RawJSON()))
995+
}
996+
997+
type ChatCompletionContentPartImageImageURL struct {
998+
// Either a URL of the image or the base64 encoded image data.
999+
URL string `json:"url,required" format:"uri"`
1000+
// Specifies the detail level of the image. Learn more in the
1001+
// [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
1002+
//
1003+
// Any of "auto", "low", "high".
1004+
Detail string `json:"detail"`
1005+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1006+
JSON struct {
1007+
URL respjson.Field
1008+
Detail respjson.Field
1009+
ExtraFields map[string]respjson.Field
1010+
raw string
1011+
} `json:"-"`
1012+
}
1013+
1014+
// Returns the unmodified JSON received from the API
1015+
func (r ChatCompletionContentPartImageImageURL) RawJSON() string { return r.JSON.raw }
1016+
func (r *ChatCompletionContentPartImageImageURL) UnmarshalJSON(data []byte) error {
1017+
return apijson.UnmarshalRoot(data, r)
1018+
}
1019+
9671020
// Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
9681021
//
9691022
// The properties ImageURL, Type are required.
@@ -1074,6 +1127,38 @@ func (r *ChatCompletionContentPartRefusalParam) UnmarshalJSON(data []byte) error
10741127
return apijson.UnmarshalRoot(data, r)
10751128
}
10761129

1130+
// Learn about
1131+
// [text inputs](https://platform.openai.com/docs/guides/text-generation).
1132+
type ChatCompletionContentPartText struct {
1133+
// The text content.
1134+
Text string `json:"text,required"`
1135+
// The type of the content part.
1136+
Type constant.Text `json:"type,required"`
1137+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1138+
JSON struct {
1139+
Text respjson.Field
1140+
Type respjson.Field
1141+
ExtraFields map[string]respjson.Field
1142+
raw string
1143+
} `json:"-"`
1144+
}
1145+
1146+
// Returns the unmodified JSON received from the API
1147+
func (r ChatCompletionContentPartText) RawJSON() string { return r.JSON.raw }
1148+
func (r *ChatCompletionContentPartText) UnmarshalJSON(data []byte) error {
1149+
return apijson.UnmarshalRoot(data, r)
1150+
}
1151+
1152+
// ToParam converts this ChatCompletionContentPartText to a
1153+
// ChatCompletionContentPartTextParam.
1154+
//
1155+
// Warning: the fields of the param type will not be present. ToParam should only
1156+
// be used at the last possible moment before sending a request. Test for this with
1157+
// ChatCompletionContentPartTextParam.Overrides()
1158+
func (r ChatCompletionContentPartText) ToParam() ChatCompletionContentPartTextParam {
1159+
return param.Override[ChatCompletionContentPartTextParam](json.RawMessage(r.RawJSON()))
1160+
}
1161+
10771162
// Learn about
10781163
// [text inputs](https://platform.openai.com/docs/guides/text-generation).
10791164
//
@@ -1795,11 +1880,15 @@ func (u *ChatCompletionPredictionContentContentUnionParam) asAny() any {
17951880
type ChatCompletionStoreMessage struct {
17961881
// The identifier of the chat message.
17971882
ID string `json:"id,required"`
1883+
// If a content parts array was provided, this is an array of `text` and
1884+
// `image_url` parts. Otherwise, null.
1885+
ContentParts []ChatCompletionStoreMessageContentPartUnion `json:"content_parts,nullable"`
17981886
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
17991887
JSON struct {
1800-
ID respjson.Field
1801-
ExtraFields map[string]respjson.Field
1802-
raw string
1888+
ID respjson.Field
1889+
ContentParts respjson.Field
1890+
ExtraFields map[string]respjson.Field
1891+
raw string
18031892
} `json:"-"`
18041893
ChatCompletionMessage
18051894
}
@@ -1810,6 +1899,41 @@ func (r *ChatCompletionStoreMessage) UnmarshalJSON(data []byte) error {
18101899
return apijson.UnmarshalRoot(data, r)
18111900
}
18121901

1902+
// ChatCompletionStoreMessageContentPartUnion contains all possible properties and
1903+
// values from [ChatCompletionContentPartText], [ChatCompletionContentPartImage].
1904+
//
1905+
// Use the methods beginning with 'As' to cast the union to one of its variants.
1906+
type ChatCompletionStoreMessageContentPartUnion struct {
1907+
// This field is from variant [ChatCompletionContentPartText].
1908+
Text string `json:"text"`
1909+
Type string `json:"type"`
1910+
// This field is from variant [ChatCompletionContentPartImage].
1911+
ImageURL ChatCompletionContentPartImageImageURL `json:"image_url"`
1912+
JSON struct {
1913+
Text respjson.Field
1914+
Type respjson.Field
1915+
ImageURL respjson.Field
1916+
raw string
1917+
} `json:"-"`
1918+
}
1919+
1920+
func (u ChatCompletionStoreMessageContentPartUnion) AsTextContentPart() (v ChatCompletionContentPartText) {
1921+
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1922+
return
1923+
}
1924+
1925+
func (u ChatCompletionStoreMessageContentPartUnion) AsImageContentPart() (v ChatCompletionContentPartImage) {
1926+
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1927+
return
1928+
}
1929+
1930+
// Returns the unmodified JSON received from the API
1931+
func (u ChatCompletionStoreMessageContentPartUnion) RawJSON() string { return u.JSON.raw }
1932+
1933+
func (r *ChatCompletionStoreMessageContentPartUnion) UnmarshalJSON(data []byte) error {
1934+
return apijson.UnmarshalRoot(data, r)
1935+
}
1936+
18131937
// Options for streaming response. Only set this when you set `stream: true`.
18141938
type ChatCompletionStreamOptionsParam struct {
18151939
// If set, an additional chunk will be streamed before the `data: [DONE]` message.
@@ -2173,9 +2297,21 @@ type ChatCompletionNewParams struct {
21732297
// [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
21742298
// during tool use.
21752299
ParallelToolCalls param.Opt[bool] `json:"parallel_tool_calls,omitzero"`
2176-
// A stable identifier for your end-users. Used to boost cache hit rates by better
2177-
// bucketing similar requests and to help OpenAI detect and prevent abuse.
2178-
// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
2300+
// Used by OpenAI to cache responses for similar requests to optimize your cache
2301+
// hit rates. Replaces the `user` field.
2302+
// [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
2303+
PromptCacheKey param.Opt[string] `json:"prompt_cache_key,omitzero"`
2304+
// A stable identifier used to help detect users of your application that may be
2305+
// violating OpenAI's usage policies. The IDs should be a string that uniquely
2306+
// identifies each user. We recommend hashing their username or email address, in
2307+
// order to avoid sending us any identifying information.
2308+
// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
2309+
SafetyIdentifier param.Opt[string] `json:"safety_identifier,omitzero"`
2310+
// This field is being replaced by `safety_identifier` and `prompt_cache_key`. Use
2311+
// `prompt_cache_key` instead to maintain caching optimizations. A stable
2312+
// identifier for your end-users. Used to boost cache hit rates by better bucketing
2313+
// similar requests and to help OpenAI detect and prevent abuse.
2314+
// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
21792315
User param.Opt[string] `json:"user,omitzero"`
21802316
// Parameters for audio output. Required when audio output is requested with
21812317
// `modalities: ["audio"]`.

chatcompletion_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ func TestChatCompletionNewWithOptionalParams(t *testing.T) {
6969
},
7070
},
7171
PresencePenalty: openai.Float(-2),
72+
PromptCacheKey: openai.String("prompt-cache-key-1234"),
7273
ReasoningEffort: shared.ReasoningEffortLow,
7374
ResponseFormat: openai.ChatCompletionNewParamsResponseFormatUnion{
7475
OfText: &shared.ResponseFormatTextParam{},
7576
},
76-
Seed: openai.Int(-9007199254740991),
77-
ServiceTier: openai.ChatCompletionNewParamsServiceTierAuto,
77+
SafetyIdentifier: openai.String("safety-identifier-1234"),
78+
Seed: openai.Int(-9007199254740991),
79+
ServiceTier: openai.ChatCompletionNewParamsServiceTierAuto,
7880
Stop: openai.ChatCompletionNewParamsStopUnion{
7981
OfString: openai.String("\n"),
8082
},

responses/response.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -756,11 +756,21 @@ type Response struct {
756756
// Reference to a prompt template and its variables.
757757
// [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
758758
Prompt ResponsePrompt `json:"prompt,nullable"`
759+
// Used by OpenAI to cache responses for similar requests to optimize your cache
760+
// hit rates. Replaces the `user` field.
761+
// [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
762+
PromptCacheKey string `json:"prompt_cache_key"`
759763
// **o-series models only**
760764
//
761765
// Configuration options for
762766
// [reasoning models](https://platform.openai.com/docs/guides/reasoning).
763767
Reasoning shared.Reasoning `json:"reasoning,nullable"`
768+
// A stable identifier used to help detect users of your application that may be
769+
// violating OpenAI's usage policies. The IDs should be a string that uniquely
770+
// identifies each user. We recommend hashing their username or email address, in
771+
// order to avoid sending us any identifying information.
772+
// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
773+
SafetyIdentifier string `json:"safety_identifier"`
764774
// Specifies the processing type used for serving the request.
765775
//
766776
// - If set to 'auto', then the request will be processed with the service tier
@@ -809,9 +819,13 @@ type Response struct {
809819
// Represents token usage details including input tokens, output tokens, a
810820
// breakdown of output tokens, and the total tokens used.
811821
Usage ResponseUsage `json:"usage"`
812-
// A stable identifier for your end-users. Used to boost cache hit rates by better
813-
// bucketing similar requests and to help OpenAI detect and prevent abuse.
814-
// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
822+
// This field is being replaced by `safety_identifier` and `prompt_cache_key`. Use
823+
// `prompt_cache_key` instead to maintain caching optimizations. A stable
824+
// identifier for your end-users. Used to boost cache hit rates by better bucketing
825+
// similar requests and to help OpenAI detect and prevent abuse.
826+
// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
827+
//
828+
// Deprecated: deprecated
815829
User string `json:"user"`
816830
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
817831
JSON struct {
@@ -834,7 +848,9 @@ type Response struct {
834848
MaxToolCalls respjson.Field
835849
PreviousResponseID respjson.Field
836850
Prompt respjson.Field
851+
PromptCacheKey respjson.Field
837852
Reasoning respjson.Field
853+
SafetyIdentifier respjson.Field
838854
ServiceTier respjson.Field
839855
Status respjson.Field
840856
Text respjson.Field
@@ -12754,9 +12770,21 @@ type ResponseNewParams struct {
1275412770
//
1275512771
// We generally recommend altering this or `temperature` but not both.
1275612772
TopP param.Opt[float64] `json:"top_p,omitzero"`
12757-
// A stable identifier for your end-users. Used to boost cache hit rates by better
12758-
// bucketing similar requests and to help OpenAI detect and prevent abuse.
12759-
// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
12773+
// Used by OpenAI to cache responses for similar requests to optimize your cache
12774+
// hit rates. Replaces the `user` field.
12775+
// [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
12776+
PromptCacheKey param.Opt[string] `json:"prompt_cache_key,omitzero"`
12777+
// A stable identifier used to help detect users of your application that may be
12778+
// violating OpenAI's usage policies. The IDs should be a string that uniquely
12779+
// identifies each user. We recommend hashing their username or email address, in
12780+
// order to avoid sending us any identifying information.
12781+
// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
12782+
SafetyIdentifier param.Opt[string] `json:"safety_identifier,omitzero"`
12783+
// This field is being replaced by `safety_identifier` and `prompt_cache_key`. Use
12784+
// `prompt_cache_key` instead to maintain caching optimizations. A stable
12785+
// identifier for your end-users. Used to boost cache hit rates by better bucketing
12786+
// similar requests and to help OpenAI detect and prevent abuse.
12787+
// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
1276012788
User param.Opt[string] `json:"user,omitzero"`
1276112789
// Specify additional output data to include in the model response. Currently
1276212790
// supported values are:

responses/response_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ func TestResponseNewWithOptionalParams(t *testing.T) {
5151
},
5252
Version: openai.String("version"),
5353
},
54+
PromptCacheKey: openai.String("prompt-cache-key-1234"),
5455
Reasoning: shared.ReasoningParam{
5556
Effort: shared.ReasoningEffortLow,
5657
GenerateSummary: shared.ReasoningGenerateSummaryAuto,
5758
Summary: shared.ReasoningSummaryAuto,
5859
},
59-
ServiceTier: responses.ResponseNewParamsServiceTierAuto,
60-
Store: openai.Bool(true),
61-
Temperature: openai.Float(1),
60+
SafetyIdentifier: openai.String("safety-identifier-1234"),
61+
ServiceTier: responses.ResponseNewParamsServiceTierAuto,
62+
Store: openai.Bool(true),
63+
Temperature: openai.Float(1),
6264
Text: responses.ResponseTextConfigParam{
6365
Format: responses.ResponseFormatTextConfigUnionParam{
6466
OfText: &shared.ResponseFormatTextParam{},

0 commit comments

Comments
 (0)