Skip to content

Commit ffcc4c4

Browse files
fix(api): prioritize Python request routing fields (#4014)
## Summary Prioritizes `model`, `stream`, and `service_tier` in Python JSON request bodies, placing them before potentially large `input` or `messages` fields. ## Changes - Applies only to methods with one unambiguous `application/json` request body. - Preserves the relative order and values of all other request-body fields. - Leaves public method signatures and omitted-field behavior unchanged. - Leaves multipart, form-encoded, and mixed-media requests unchanged. - Shortens the `SessionTurnError` error-category description. Co-authored-by: jbeckwith-oai <269036200+jbeckwith-oai@users.noreply.github.com>
1 parent 93bd2aa commit ffcc4c4

19 files changed

Lines changed: 65 additions & 98 deletions

File tree

‎.castiron.stats.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
schema_version: 1
2-
generation_id: 862285b0-bba7-4d7b-934b-63759482d34f
2+
generation_id: d2b5e56a-7b5c-4539-98d6-a5459de003da
33
openapi_spec_hash: c829925be8009e5eaedbc7e25a75bbb4
44
openapi_transformed_spec_hash: 06558c212f804512d9bbd22d9162355c
55
config_hash: 75548929fa5c67ad9d1d94b5a30a56e9
6-
codegen_sha: cad107aa3bd1d80294233ba5cad18f0db8151a23
7-
codegen_hash: 256f429bb05c452738ab7d660f8cf6c2ed641e0b5e9d7e9a9f21c6c1a24bf818
8-
public_codegen_sha: 8fdc56a6031ebe1660d2a10292b8db826b2b02b0
6+
codegen_sha: ae58f4187453cdc87fc2f95eab1d8007bd39a698
7+
codegen_hash: e4805e8a2047f6dcf32bd17947a6dc02178b7cd91f238eba5f3a1584754f621a
8+
public_codegen_sha: 5c5451216a28165dc1efb8f37aae9d3a7d05e4ae

‎src/openai/resources/audio/speech.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def create(
109109
"/audio/speech",
110110
body=maybe_transform(
111111
{
112-
"input": input,
113112
"model": model,
113+
"input": input,
114114
"voice": voice,
115115
"instructions": instructions,
116116
"response_format": response_format,
@@ -214,8 +214,8 @@ async def create(
214214
"/audio/speech",
215215
body=await async_maybe_transform(
216216
{
217-
"input": input,
218217
"model": model,
218+
"input": input,
219219
"voice": voice,
220220
"instructions": instructions,
221221
"response_format": response_format,

‎src/openai/resources/beta/agents/agents.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ def create(
150150
body=maybe_transform(
151151
{
152152
"model": model,
153+
"service_tier": service_tier,
153154
"instructions": instructions,
154155
"metadata": metadata,
155156
"multi_agent": multi_agent,
156157
"name": name,
157158
"reasoning": reasoning,
158-
"service_tier": service_tier,
159159
"text": text,
160160
"tools": tools,
161161
},
@@ -281,13 +281,13 @@ def update(
281281
path_template("/agents/{agent_id}", agent_id=agent_id),
282282
body=maybe_transform(
283283
{
284+
"model": model,
285+
"service_tier": service_tier,
284286
"instructions": instructions,
285287
"metadata": metadata,
286-
"model": model,
287288
"multi_agent": multi_agent,
288289
"name": name,
289290
"reasoning": reasoning,
290-
"service_tier": service_tier,
291291
"text": text,
292292
"tools": tools,
293293
},
@@ -502,12 +502,12 @@ async def create(
502502
body=await async_maybe_transform(
503503
{
504504
"model": model,
505+
"service_tier": service_tier,
505506
"instructions": instructions,
506507
"metadata": metadata,
507508
"multi_agent": multi_agent,
508509
"name": name,
509510
"reasoning": reasoning,
510-
"service_tier": service_tier,
511511
"text": text,
512512
"tools": tools,
513513
},
@@ -633,13 +633,13 @@ async def update(
633633
path_template("/agents/{agent_id}", agent_id=agent_id),
634634
body=await async_maybe_transform(
635635
{
636+
"model": model,
637+
"service_tier": service_tier,
636638
"instructions": instructions,
637639
"metadata": metadata,
638-
"model": model,
639640
"multi_agent": multi_agent,
640641
"name": name,
641642
"reasoning": reasoning,
642-
"service_tier": service_tier,
643643
"text": text,
644644
"tools": tools,
645645
},

‎src/openai/resources/beta/agents/sessions/sessions.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,12 @@ def create(
338338
"/agents/sessions",
339339
body=maybe_transform(
340340
{
341+
"stream": stream,
341342
"environment": environment,
342343
"agent": agent,
343344
"agent_id": agent_id,
344345
"input": input,
345346
"metadata": metadata,
346-
"stream": stream,
347347
"vault_ids": vault_ids,
348348
},
349349
session_create_params.SessionCreateParamsStreaming
@@ -828,12 +828,12 @@ async def create(
828828
"/agents/sessions",
829829
body=await async_maybe_transform(
830830
{
831+
"stream": stream,
831832
"environment": environment,
832833
"agent": agent,
833834
"agent_id": agent_id,
834835
"input": input,
835836
"metadata": metadata,
836-
"stream": stream,
837837
"vault_ids": vault_ids,
838838
},
839839
session_create_params.SessionCreateParamsStreaming

‎src/openai/resources/beta/assistants.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,10 @@ def update(
380380
path_template("/assistants/{assistant_id}", assistant_id=assistant_id),
381381
body=maybe_transform(
382382
{
383+
"model": model,
383384
"description": description,
384385
"instructions": instructions,
385386
"metadata": metadata,
386-
"model": model,
387387
"name": name,
388388
"reasoning_effort": reasoning_effort,
389389
"response_format": response_format,
@@ -859,10 +859,10 @@ async def update(
859859
path_template("/assistants/{assistant_id}", assistant_id=assistant_id),
860860
body=await async_maybe_transform(
861861
{
862+
"model": model,
862863
"description": description,
863864
"instructions": instructions,
864865
"metadata": metadata,
865-
"model": model,
866866
"name": name,
867867
"reasoning_effort": reasoning_effort,
868868
"response_format": response_format,

‎src/openai/resources/beta/responses/input_tokens.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ def count(
139139
"/responses/input_tokens?beta=true",
140140
body=maybe_transform(
141141
{
142+
"model": model,
142143
"conversation": conversation,
143144
"input": input,
144145
"instructions": instructions,
145-
"model": model,
146146
"parallel_tool_calls": parallel_tool_calls,
147147
"personality": personality,
148148
"previous_response_id": previous_response_id,
@@ -282,10 +282,10 @@ async def count(
282282
"/responses/input_tokens?beta=true",
283283
body=await async_maybe_transform(
284284
{
285+
"model": model,
285286
"conversation": conversation,
286287
"input": input,
287288
"instructions": instructions,
288-
"model": model,
289289
"parallel_tool_calls": parallel_tool_calls,
290290
"personality": personality,
291291
"previous_response_id": previous_response_id,

‎src/openai/resources/beta/responses/responses.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,9 @@ def create(
15041504
"/responses?beta=true",
15051505
body=maybe_transform(
15061506
{
1507+
"model": model,
1508+
"stream": stream,
1509+
"service_tier": service_tier,
15071510
"access_programs": access_programs,
15081511
"background": background,
15091512
"context_management": context_management,
@@ -1514,7 +1517,6 @@ def create(
15141517
"max_output_tokens": max_output_tokens,
15151518
"max_tool_calls": max_tool_calls,
15161519
"metadata": metadata,
1517-
"model": model,
15181520
"moderation": moderation,
15191521
"multi_agent": multi_agent,
15201522
"parallel_tool_calls": parallel_tool_calls,
@@ -1525,9 +1527,7 @@ def create(
15251527
"prompt_cache_retention": prompt_cache_retention,
15261528
"reasoning": reasoning,
15271529
"safety_identifier": safety_identifier,
1528-
"service_tier": service_tier,
15291530
"store": store,
1530-
"stream": stream,
15311531
"stream_options": stream_options,
15321532
"temperature": temperature,
15331533
"text": text,
@@ -2046,13 +2046,13 @@ def compact(
20462046
body=maybe_transform(
20472047
{
20482048
"model": model,
2049+
"service_tier": service_tier,
20492050
"input": input,
20502051
"instructions": instructions,
20512052
"previous_response_id": previous_response_id,
20522053
"prompt_cache_key": prompt_cache_key,
20532054
"prompt_cache_options": prompt_cache_options,
20542055
"prompt_cache_retention": prompt_cache_retention,
2055-
"service_tier": service_tier,
20562056
},
20572057
response_compact_params.ResponseCompactParams,
20582058
),
@@ -3522,6 +3522,9 @@ async def create(
35223522
"/responses?beta=true",
35233523
body=await async_maybe_transform(
35243524
{
3525+
"model": model,
3526+
"stream": stream,
3527+
"service_tier": service_tier,
35253528
"access_programs": access_programs,
35263529
"background": background,
35273530
"context_management": context_management,
@@ -3532,7 +3535,6 @@ async def create(
35323535
"max_output_tokens": max_output_tokens,
35333536
"max_tool_calls": max_tool_calls,
35343537
"metadata": metadata,
3535-
"model": model,
35363538
"moderation": moderation,
35373539
"multi_agent": multi_agent,
35383540
"parallel_tool_calls": parallel_tool_calls,
@@ -3543,9 +3545,7 @@ async def create(
35433545
"prompt_cache_retention": prompt_cache_retention,
35443546
"reasoning": reasoning,
35453547
"safety_identifier": safety_identifier,
3546-
"service_tier": service_tier,
35473548
"store": store,
3548-
"stream": stream,
35493549
"stream_options": stream_options,
35503550
"temperature": temperature,
35513551
"text": text,
@@ -4064,13 +4064,13 @@ async def compact(
40644064
body=await async_maybe_transform(
40654065
{
40664066
"model": model,
4067+
"service_tier": service_tier,
40674068
"input": input,
40684069
"instructions": instructions,
40694070
"previous_response_id": previous_response_id,
40704071
"prompt_cache_key": prompt_cache_key,
40714072
"prompt_cache_options": prompt_cache_options,
40724073
"prompt_cache_retention": prompt_cache_retention,
4073-
"service_tier": service_tier,
40744074
},
40754075
response_compact_params.ResponseCompactParams,
40764076
),

‎src/openai/resources/beta/threads/runs/runs.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,18 +580,18 @@ def create(
580580
path_template("/threads/{thread_id}/runs", thread_id=thread_id),
581581
body=maybe_transform(
582582
{
583+
"model": model,
584+
"stream": stream,
583585
"assistant_id": assistant_id,
584586
"additional_instructions": additional_instructions,
585587
"additional_messages": additional_messages,
586588
"instructions": instructions,
587589
"max_completion_tokens": max_completion_tokens,
588590
"max_prompt_tokens": max_prompt_tokens,
589591
"metadata": metadata,
590-
"model": model,
591592
"parallel_tool_calls": parallel_tool_calls,
592593
"reasoning_effort": reasoning_effort,
593594
"response_format": response_format,
594-
"stream": stream,
595595
"temperature": temperature,
596596
"tool_choice": tool_choice,
597597
"tools": tools,
@@ -1366,8 +1366,8 @@ def submit_tool_outputs(
13661366
path_template("/threads/{thread_id}/runs/{run_id}/submit_tool_outputs", thread_id=thread_id, run_id=run_id),
13671367
body=maybe_transform(
13681368
{
1369-
"tool_outputs": tool_outputs,
13701369
"stream": stream,
1370+
"tool_outputs": tool_outputs,
13711371
},
13721372
run_submit_tool_outputs_params.RunSubmitToolOutputsParamsStreaming
13731373
if stream
@@ -2049,18 +2049,18 @@ async def create(
20492049
path_template("/threads/{thread_id}/runs", thread_id=thread_id),
20502050
body=await async_maybe_transform(
20512051
{
2052+
"model": model,
2053+
"stream": stream,
20522054
"assistant_id": assistant_id,
20532055
"additional_instructions": additional_instructions,
20542056
"additional_messages": additional_messages,
20552057
"instructions": instructions,
20562058
"max_completion_tokens": max_completion_tokens,
20572059
"max_prompt_tokens": max_prompt_tokens,
20582060
"metadata": metadata,
2059-
"model": model,
20602061
"parallel_tool_calls": parallel_tool_calls,
20612062
"reasoning_effort": reasoning_effort,
20622063
"response_format": response_format,
2063-
"stream": stream,
20642064
"temperature": temperature,
20652065
"tool_choice": tool_choice,
20662066
"tools": tools,
@@ -2834,8 +2834,8 @@ async def submit_tool_outputs(
28342834
path_template("/threads/{thread_id}/runs/{run_id}/submit_tool_outputs", thread_id=thread_id, run_id=run_id),
28352835
body=await async_maybe_transform(
28362836
{
2837-
"tool_outputs": tool_outputs,
28382837
"stream": stream,
2838+
"tool_outputs": tool_outputs,
28392839
},
28402840
run_submit_tool_outputs_params.RunSubmitToolOutputsParamsStreaming
28412841
if stream

‎src/openai/resources/beta/threads/threads.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -731,15 +731,15 @@ def create_and_run(
731731
"/threads/runs",
732732
body=maybe_transform(
733733
{
734+
"model": model,
735+
"stream": stream,
734736
"assistant_id": assistant_id,
735737
"instructions": instructions,
736738
"max_completion_tokens": max_completion_tokens,
737739
"max_prompt_tokens": max_prompt_tokens,
738740
"metadata": metadata,
739-
"model": model,
740741
"parallel_tool_calls": parallel_tool_calls,
741742
"response_format": response_format,
742-
"stream": stream,
743743
"temperature": temperature,
744744
"thread": thread,
745745
"tool_choice": tool_choice,
@@ -1622,15 +1622,15 @@ async def create_and_run(
16221622
"/threads/runs",
16231623
body=await async_maybe_transform(
16241624
{
1625+
"model": model,
1626+
"stream": stream,
16251627
"assistant_id": assistant_id,
16261628
"instructions": instructions,
16271629
"max_completion_tokens": max_completion_tokens,
16281630
"max_prompt_tokens": max_prompt_tokens,
16291631
"metadata": metadata,
1630-
"model": model,
16311632
"parallel_tool_calls": parallel_tool_calls,
16321633
"response_format": response_format,
1633-
"stream": stream,
16341634
"temperature": temperature,
16351635
"thread": thread,
16361636
"tool_choice": tool_choice,

‎src/openai/resources/chat/completions/completions.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,8 +1319,10 @@ def create(
13191319
"/chat/completions",
13201320
body=maybe_transform(
13211321
{
1322-
"messages": messages,
13231322
"model": model,
1323+
"stream": stream,
1324+
"service_tier": service_tier,
1325+
"messages": messages,
13241326
"audio": audio,
13251327
"frequency_penalty": frequency_penalty,
13261328
"function_call": function_call,
@@ -1343,10 +1345,8 @@ def create(
13431345
"response_format": response_format,
13441346
"safety_identifier": safety_identifier,
13451347
"seed": seed,
1346-
"service_tier": service_tier,
13471348
"stop": stop,
13481349
"store": store,
1349-
"stream": stream,
13501350
"stream_options": stream_options,
13511351
"temperature": temperature,
13521352
"tool_choice": tool_choice,
@@ -2953,8 +2953,10 @@ async def create(
29532953
"/chat/completions",
29542954
body=await async_maybe_transform(
29552955
{
2956-
"messages": messages,
29572956
"model": model,
2957+
"stream": stream,
2958+
"service_tier": service_tier,
2959+
"messages": messages,
29582960
"audio": audio,
29592961
"frequency_penalty": frequency_penalty,
29602962
"function_call": function_call,
@@ -2977,10 +2979,8 @@ async def create(
29772979
"response_format": response_format,
29782980
"safety_identifier": safety_identifier,
29792981
"seed": seed,
2980-
"service_tier": service_tier,
29812982
"stop": stop,
29822983
"store": store,
2983-
"stream": stream,
29842984
"stream_options": stream_options,
29852985
"temperature": temperature,
29862986
"tool_choice": tool_choice,

0 commit comments

Comments
 (0)