Skip to content

Commit 2df1423

Browse files
feat(api): support response format updates and local output types
Castiron-Internal-PR: openai/openai-python-internal#365 Castiron-Source-SHA: 2d22a5018f49c135bb0ee85d0b8db74f1b52f5f3 Castiron-Public-Base-SHA: 68b962c
1 parent 68b962c commit 2df1423

22 files changed

Lines changed: 748 additions & 93 deletions

‎.castiron.stats.yml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
schema_version: 1
2-
generation_id: e511c488-31b9-4833-baf5-cfb49bbba7ac
3-
openapi_spec_hash: d57efec7c76a156447c9ab739b446dc1
4-
openapi_transformed_spec_hash: b34c897c8cec867ec4ac8e22727c5975
5-
config_hash: 8da38e8d8f706786c2d8586691168746
6-
codegen_sha: e46410d5a9751f068b9afce57ecf25abda75de09
7-
codegen_hash: 33536449fa4898b45941d5fa4b5a958f88e2701a4b85fae21c372b75614198cd
2+
generation_id: 7b7feee1-6807-4c20-98e0-610aab05b2da
3+
openapi_spec_hash: 51b199ef7fd5542bc4910765f9becd60
4+
openapi_transformed_spec_hash: 73822d924c15a6ed58dcfe8f616bd4be
5+
config_hash: b707b209c892562880c415693d111ad6
6+
codegen_sha: e1054c07fb03a8025411f0ff6ee0a5ff17e09109
7+
codegen_hash: 73c66bd2bff47ee2bbd2d04a174184dec767ebe300a3bd41443938d914013ef0

‎api_reference/openapi.transformed.yml‎

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65425,8 +65425,8 @@ components:
6542565425
ResponseConfigurationUpdate:
6542665426
type: object
6542765427
description: |
65428-
A configuration update that applies to subsequent responses until it is
65429-
replaced by another configuration update.
65428+
A configuration update for subsequent responses. Each setting stays in effect
65429+
until a later update replaces that setting.
6543065430
properties:
6543165431
id:
6543265432
type: string
@@ -65448,15 +65448,27 @@ components:
6544865448
description: |
6544965449
The reasoning effort used for subsequent responses until another
6545065450
configuration update replaces it.
65451+
text:
65452+
type: object
65453+
description: The text output configuration for subsequent responses.
65454+
properties:
65455+
format:
65456+
description: Use a JSON schema for structured output or text to return to plain text.
65457+
discriminator:
65458+
propertyName: type
65459+
anyOf:
65460+
- $ref: '#/components/schemas/ResponseFormatText'
65461+
- $ref: '#/components/schemas/TextResponseFormatJsonSchema'
65462+
required:
65463+
- format
6545165464
required:
6545265465
- id
6545365466
- type
6545465467
ResponseConfigurationUpdateItemParam:
6545565468
type: object
6545665469
description: |
65457-
An update to the conversation's response configuration. The configuration
65458-
remains in effect for subsequent responses until it is replaced by another
65459-
configuration update.
65470+
An update to the conversation's response configuration. Supply reasoning,
65471+
text, or both. Each setting stays in effect until a later update replaces it.
6546065472
properties:
6546165473
id:
6546265474
anyOf:
@@ -65480,6 +65492,19 @@ components:
6548065492
description: |
6548165493
The reasoning effort to use for subsequent responses until another
6548265494
configuration update replaces it.
65495+
text:
65496+
type: object
65497+
description: The text output configuration for subsequent responses.
65498+
properties:
65499+
format:
65500+
description: Use a JSON schema for structured output or text to return to plain text.
65501+
discriminator:
65502+
propertyName: type
65503+
anyOf:
65504+
- $ref: '#/components/schemas/ResponseFormatText'
65505+
- $ref: '#/components/schemas/TextResponseFormatJsonSchema'
65506+
required:
65507+
- format
6548365508
required:
6548465509
- type
6548565510
ResponseContentPartAddedEvent:
@@ -71066,13 +71091,13 @@ components:
7106671091
Setting to `{ "type": "json_object" }` enables the older JSON mode, which
7106771092
ensures the message the model generates is valid JSON. Using `json_schema`
7106871093
is preferred for models that support it.
71094+
discriminator:
71095+
propertyName: type
7106971096
anyOf:
7107071097
- $ref: '#/components/schemas/ResponseFormatText'
7107171098
- $ref: '#/components/schemas/TextResponseFormatJsonSchema'
7107271099
x-openai-ruby-json-schema-input: true
7107371100
- $ref: '#/components/schemas/ResponseFormatJsonObject'
71074-
discriminator:
71075-
propertyName: type
7107671101
TextResponseFormatJsonSchema:
7107771102
x-openai-structured-output: json_schema_default_strict
7107871103
type: object
@@ -99478,12 +99503,12 @@ components:
9947899503
Setting to `{ "type": "json_object" }` enables the older JSON mode, which
9947999504
ensures the message the model generates is valid JSON. Using `json_schema`
9948099505
is preferred for models that support it.
99506+
discriminator:
99507+
propertyName: type
9948199508
anyOf:
9948299509
- $ref: '#/components/schemas/BetaResponseFormatText'
9948399510
- $ref: '#/components/schemas/BetaTextResponseFormatJsonSchema'
9948499511
- $ref: '#/components/schemas/BetaResponseFormatJsonObject'
99485-
discriminator:
99486-
propertyName: type
9948799512
BetaResponseFormatJsonObject:
9948899513
type: object
9948999514
title: JSON object
@@ -102546,9 +102571,8 @@ components:
102546102571
BetaResponseConfigurationUpdateItemParam:
102547102572
type: object
102548102573
description: |
102549-
An update to the conversation's response configuration. The configuration
102550-
remains in effect for subsequent responses until it is replaced by another
102551-
configuration update.
102574+
An update to the conversation's response configuration. Supply reasoning,
102575+
text, or both. Each setting stays in effect until a later update replaces it.
102552102576
properties:
102553102577
agent:
102554102578
anyOf:
@@ -102577,6 +102601,19 @@ components:
102577102601
description: |
102578102602
The reasoning effort to use for subsequent responses until another
102579102603
configuration update replaces it.
102604+
text:
102605+
type: object
102606+
description: The text output configuration for subsequent responses.
102607+
properties:
102608+
format:
102609+
description: Use a JSON schema for structured output or text to return to plain text.
102610+
discriminator:
102611+
propertyName: type
102612+
anyOf:
102613+
- $ref: '#/components/schemas/BetaResponseFormatText'
102614+
- $ref: '#/components/schemas/BetaTextResponseFormatJsonSchema'
102615+
required:
102616+
- format
102580102617
required:
102581102618
- type
102582102619
BetaAdditionalToolsItemParam:
@@ -105303,8 +105340,8 @@ components:
105303105340
BetaResponseConfigurationUpdate:
105304105341
type: object
105305105342
description: |
105306-
A configuration update that applies to subsequent responses until it is
105307-
replaced by another configuration update.
105343+
A configuration update for subsequent responses. Each setting stays in effect
105344+
until a later update replaces that setting.
105308105345
properties:
105309105346
agent:
105310105347
$ref: '#/components/schemas/BetaAgentTag'
@@ -105329,6 +105366,19 @@ components:
105329105366
description: |
105330105367
The reasoning effort used for subsequent responses until another
105331105368
configuration update replaces it.
105369+
text:
105370+
type: object
105371+
description: The text output configuration for subsequent responses.
105372+
properties:
105373+
format:
105374+
description: Use a JSON schema for structured output or text to return to plain text.
105375+
discriminator:
105376+
propertyName: type
105377+
anyOf:
105378+
- $ref: '#/components/schemas/BetaResponseFormatText'
105379+
- $ref: '#/components/schemas/BetaTextResponseFormatJsonSchema'
105380+
required:
105381+
- format
105332105382
required:
105333105383
- id
105334105384
- type

‎helpers.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,41 @@ output into a Pydantic model. The same parsing rules apply to
6363
Use `output_parsed` for the structured result and retain `output` when replaying
6464
messages so their phases are preserved.
6565

66+
When the output schema changes during a conversation, pass `parse_as` to
67+
`client.responses.parse()` to select the local output type. For example, if a
68+
previous turn switched to `DetailedAnswer`, continue with this call.
69+
70+
```py
71+
response = client.responses.parse(
72+
model=model,
73+
previous_response_id=previous.id,
74+
input="Explain the evidence.",
75+
parse_as=DetailedAnswer,
76+
)
77+
```
78+
79+
The SDK parses the answer as `DetailedAnswer`. The request inherits its output
80+
format from the previous turn. If you also pass `text_format=ShortAnswer`,
81+
the request sends that class's schema as the top-level format. Pass
82+
`parse_as=None` to read unparsed text when the previous turn reset the format.
83+
You can also pass a format update directly in `input`. For example, given a
84+
JSON schema format named `detailed_format`:
85+
86+
```py
87+
response = client.responses.parse(
88+
model=model,
89+
input=[
90+
{"type": "configuration_update", "text": {"format": detailed_format}},
91+
{"role": "user", "content": "Explain the evidence."},
92+
],
93+
parse_as=DetailedAnswer,
94+
)
95+
```
96+
97+
To switch back to plain text, send `{"type": "text"}` as the update's format.
98+
A reasoning-only update keeps the active format. Retrieved configuration items
99+
include `item.text.format` when the input supplied it.
100+
66101
## Auto-parsing function tool calls
67102

68103
The `.parse()` method will also automatically parse `function` tool calls if:

‎scripts/castiron/generated-files.json‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@
379379
},
380380
"src/openai/resources/beta/responses/responses.py": {
381381
"mode": "100644",
382-
"sha256": "043ff25a6a7f078bb0b11f6368ee136d7f3bb371c65360c8eb608afaf86de023"
382+
"sha256": "effa8db6d9a676f1f264f0b6acb3252d8dcd5f75db251bfd8b5d45ea49f0f533"
383383
},
384384
"src/openai/resources/beta/threads/__init__.py": {
385385
"mode": "100644",
@@ -559,19 +559,19 @@
559559
},
560560
"src/openai/resources/live/forks.py": {
561561
"mode": "100644",
562-
"sha256": "eda42fc4ed92675d23eb62905f154a5b115567c158dd4b0fe5cf3d0824e2bd9d"
562+
"sha256": "7fe78c144680df54628773683f9dd5b06c5241d0218b4f4c745890ddae225c92"
563563
},
564564
"src/openai/resources/live/live.py": {
565565
"mode": "100644",
566-
"sha256": "a42b9133f64a4421eafbb1d0d10a9cddcefdc872270518f7bdf61ce192265985"
566+
"sha256": "86be3e074d011a750fa52a4d216a7e87ee5c8e82f6ccec00102c03a539199882"
567567
},
568568
"src/openai/resources/live/sessions.py": {
569569
"mode": "100644",
570570
"sha256": "9ba2d59d9c7498c96ac2e7e48660c91468e0eeb5df881e77f123ee37985c3dfd"
571571
},
572572
"src/openai/resources/live/sideband.py": {
573573
"mode": "100644",
574-
"sha256": "7ed377e577ce3b229692bd112059914700741cbff042a7a92cc2a581ec2ac1f8"
574+
"sha256": "d19149c042afcd8c8efca3d7794092acc1c2f76a4bcb4f6f620547314a78e59b"
575575
},
576576
"src/openai/resources/models.py": {
577577
"mode": "100644",
@@ -599,7 +599,7 @@
599599
},
600600
"src/openai/resources/realtime/realtime.py": {
601601
"mode": "100644",
602-
"sha256": "563d955afa8c0b023f4fcb353565db0b4348394f36e6a02659db6c2885286149"
602+
"sha256": "d45ef5f2d1e25e6f8761592a9fb5739d7a344c6e64a4e7a4006418c16f05a540"
603603
},
604604
"src/openai/resources/realtime/translations/__init__.py": {
605605
"mode": "100644",
@@ -611,15 +611,15 @@
611611
},
612612
"src/openai/resources/realtime/translations/translations.py": {
613613
"mode": "100644",
614-
"sha256": "8f45807c74c477a1d13df9979c6274a089c380004b943fcb6d9342b1a7ac3ef1"
614+
"sha256": "4a6f072cea78d5afab3fe1c995b939ff8c79f449665346c729abb5c516c53f21"
615615
},
616616
"src/openai/resources/responses/__init__.py": {
617617
"mode": "100644",
618618
"sha256": "70034ef169af2cd1991aaaed26fb565d2a2d5a5b6b14309a72ab1f483f0aba15"
619619
},
620620
"src/openai/resources/responses/api.md": {
621621
"mode": "100644",
622-
"sha256": "e7815b1278aa2780bb885ac5a249fe00859dff67d3899b708d25d2968e734785"
622+
"sha256": "b635f37005fb7126cc69a7b69e3f14a9df135d9523271cc4407b1ffcb9bd5c8c"
623623
},
624624
"src/openai/resources/responses/input_items.py": {
625625
"mode": "100644",
@@ -631,7 +631,7 @@
631631
},
632632
"src/openai/resources/responses/responses.py": {
633633
"mode": "100644",
634-
"sha256": "6e536e48d77d9ed583bd0c86a4f189b664e8636ae46a52a1c80fac28ffc3b4ec"
634+
"sha256": "f844db6ec37b49de883ab2c507570b94c29e8c2609ee93cf45c0aec19fd671d3"
635635
},
636636
"src/openai/resources/safety/__init__.py": {
637637
"mode": "100644",
@@ -2523,15 +2523,15 @@
25232523
},
25242524
"src/openai/types/beta/beta_response_configuration_update_item.py": {
25252525
"mode": "100644",
2526-
"sha256": "4bd97e32e710edbd688bf8c6eac0dd8f24d1d0a64da60efda522ffefa0790046"
2526+
"sha256": "eebab46ab26a7650a94cf353d3b98c86fc12378284a9431cd4379808515ba6b0"
25272527
},
25282528
"src/openai/types/beta/beta_response_configuration_update_item_param.py": {
25292529
"mode": "100644",
2530-
"sha256": "eb06f107b27ef1fa3a9266bfaf8921b68384faf7c0dd0d300e554767bb7aed30"
2530+
"sha256": "c10511a06c2bd67530ce2f6ab2e94b63e49602e4e29df8cfb64e4bb73359e3a9"
25312531
},
25322532
"src/openai/types/beta/beta_response_configuration_update_item_param_param.py": {
25332533
"mode": "100644",
2534-
"sha256": "3c9bcd2d7e730b102b0674424e56cbd35e6bed0664a58acc1830466eea28d2be"
2534+
"sha256": "269015eac1b4dd3a8bfbd1053218e64c9a2fd3cac4b50db961089f3813c6bbd0"
25352535
},
25362536
"src/openai/types/beta/beta_response_container_reference.py": {
25372537
"mode": "100644",
@@ -6167,15 +6167,15 @@
61676167
},
61686168
"src/openai/types/responses/response_configuration_update_item.py": {
61696169
"mode": "100644",
6170-
"sha256": "4d07aca0f5dbb6f87f1db31fc16dbba2e4a49d0670edbd46256907066605a703"
6170+
"sha256": "89a39d84322be94f3805145e1ca70bae0c2b0500f89102ea93918700ecc65a02"
61716171
},
61726172
"src/openai/types/responses/response_configuration_update_item_param.py": {
61736173
"mode": "100644",
6174-
"sha256": "c8eb1b18f489c4d820bc17c10e505e97a4da8059592e903882aae5ed3ca919ad"
6174+
"sha256": "fb7a2cb3b72d2a5dd73fc78ad6194bce51eb4e1b805d9ccc85c2725e3c0bab3f"
61756175
},
61766176
"src/openai/types/responses/response_configuration_update_item_param_param.py": {
61776177
"mode": "100644",
6178-
"sha256": "8e177dbfa309934a8aedbc5bd278b48bddfa3365a42cfb661ead8677aa924a9b"
6178+
"sha256": "d7e43648f155a90a35d2f57d31e8f8481c463ada28805dd810d17db00304ce23"
61796179
},
61806180
"src/openai/types/responses/response_container_reference.py": {
61816181
"mode": "100644",

0 commit comments

Comments
 (0)