Skip to content

Commit f63f14b

Browse files
authored
fix(api): clarify when to omit completion choice count (#4298)
## Summary Clarifies the choice-count guidance for Chat Completions and Completions. ## Changes - In Chat Completions, explain that newer models reject an explicit n, including n=1. - In legacy Completions, document that omitting n generates one completion per prompt. Co-authored-by: dpiet-oai <326640584+dpiet-oai@users.noreply.github.com>
1 parent bb2d8c5 commit f63f14b

7 files changed

Lines changed: 52 additions & 37 deletions

File tree

‎.castiron.stats.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
schema_version: 1
2-
generation_id: 73dd77b3-1459-4cd6-96e8-5235eb850ba1
3-
openapi_spec_hash: 514afcfaf218a8ffd8dca49cd1a6513c
4-
openapi_transformed_spec_hash: ce06ef5cea644a2bdd14844436b5851b
2+
generation_id: 84cadef0-3ff5-45fb-be96-81e72f1f1c23
3+
openapi_spec_hash: 2b8a518f116ba253bf51f42979adab09
4+
openapi_transformed_spec_hash: b738fc05e7d9b281857dc656fe33aa42
55
config_hash: 94ef47b9aa904df37859861d724c30d6
6-
codegen_sha: acab32176d557b86eeced9b47013eea496b3e1a4
7-
codegen_hash: d2751b8d36ab5865a721402045c025f377df63f7c2cd1b073bf99dd27004d61e
6+
codegen_sha: 55baaeaebaa4dfebc414857f2332911902284f7e
7+
codegen_hash: ac598006ba02ff7d7f12e87ed2ef4be76041545648262fc95def80b1d8deb3f9

‎api_reference/openapi.transformed.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43264,7 +43264,7 @@ components:
4326443264
maximum: 128
4326543265
default: 1
4326643266
example: 1
43267-
description: How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs.
43267+
description: How many chat completion choices to generate for each input message. Omit `n` to generate one choice. Newer models reject an explicit `n`, even `n=1`. When requesting multiple choices, you are billed for generated tokens across all choices.
4326843268
prediction:
4326943269
description: |
4327043270
Configuration for a [Predicted Output](https://developers.openai.com/api/docs/guides/predicted-outputs),
@@ -43745,7 +43745,7 @@ components:
4374543745
default: 1
4374643746
example: 1
4374743747
description: |
43748-
How many completions to generate for each prompt.
43748+
How many completions to generate for each prompt. Omit `n` to generate one completion per prompt.
4374943749

4375043750
**Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`.
4375143751
presence_penalty:

‎scripts/castiron/generated-files.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,15 @@
435435
},
436436
"src/openai/resources/chat/completions/completions.py": {
437437
"mode": "100644",
438-
"sha256": "2dbef784c86b1082cdb969f8a6fc3ba860bf805f8247afc6ca2edf52eb230710"
438+
"sha256": "f5d33a1f78b39bdb0d6080a6ccbd0e8b6d9d3abc94906401c3273ea3078ba3a2"
439439
},
440440
"src/openai/resources/chat/completions/messages.py": {
441441
"mode": "100644",
442442
"sha256": "25bd83719085da7f6dbbef53718229a9dfa0571c20db94986fa7a57b99cadd35"
443443
},
444444
"src/openai/resources/completions.py": {
445445
"mode": "100644",
446-
"sha256": "291814bfdc1a2bc561e46b553d5a9e237cb00762e41cd22baf3dd33545dfd52f"
446+
"sha256": "8ac45e637006268bbc0005041169abaacf55ca28f5c0ad1b2df414ecc85d1aa5"
447447
},
448448
"src/openai/resources/containers/__init__.py": {
449449
"mode": "100644",
@@ -4015,7 +4015,7 @@
40154015
},
40164016
"src/openai/types/chat/completion_create_params.py": {
40174017
"mode": "100644",
4018-
"sha256": "a27e422737a8998c1a35b3d0e004828281839e5449fcdbf3d1eb66f8821b8023"
4018+
"sha256": "ab7ee3efb068b45dbc71d5393191747a168052b6a22f89375f6154c0f39de706"
40194019
},
40204020
"src/openai/types/chat/completion_list_params.py": {
40214021
"mode": "100644",
@@ -4051,7 +4051,7 @@
40514051
},
40524052
"src/openai/types/completion_create_params.py": {
40534053
"mode": "100644",
4054-
"sha256": "9c2f91eb36cb3df67d6fe4a4e9160ece6291b5fca52fdc0c8c1dc0208145c33d"
4054+
"sha256": "9069215ed2e70bc0af6356ea912fd22f580a1925d509b36577270b3f77fdd17c"
40554055
},
40564056
"src/openai/types/completion_usage.py": {
40574057
"mode": "100644",

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,10 @@ def create(
554554
555555
moderation: Configuration for running moderation on the request input and generated output.
556556
557-
n: How many chat completion choices to generate for each input message. Note that
558-
you will be charged based on the number of generated tokens across all of the
559-
choices. Keep `n` as `1` to minimize costs.
557+
n: How many chat completion choices to generate for each input message. Omit `n` to
558+
generate one choice. Newer models reject an explicit `n`, even `n=1`. When
559+
requesting multiple choices, you are billed for generated tokens across all
560+
choices.
560561
561562
parallel_tool_calls: Whether to enable
562563
[parallel function calling](https://developers.openai.com/api/docs/guides/function-calling#parallel-function-calling)
@@ -974,9 +975,10 @@ def create(
974975
975976
moderation: Configuration for running moderation on the request input and generated output.
976977
977-
n: How many chat completion choices to generate for each input message. Note that
978-
you will be charged based on the number of generated tokens across all of the
979-
choices. Keep `n` as `1` to minimize costs.
978+
n: How many chat completion choices to generate for each input message. Omit `n` to
979+
generate one choice. Newer models reject an explicit `n`, even `n=1`. When
980+
requesting multiple choices, you are billed for generated tokens across all
981+
choices.
980982
981983
parallel_tool_calls: Whether to enable
982984
[parallel function calling](https://developers.openai.com/api/docs/guides/function-calling#parallel-function-calling)
@@ -1385,9 +1387,10 @@ def create(
13851387
13861388
moderation: Configuration for running moderation on the request input and generated output.
13871389
1388-
n: How many chat completion choices to generate for each input message. Note that
1389-
you will be charged based on the number of generated tokens across all of the
1390-
choices. Keep `n` as `1` to minimize costs.
1390+
n: How many chat completion choices to generate for each input message. Omit `n` to
1391+
generate one choice. Newer models reject an explicit `n`, even `n=1`. When
1392+
requesting multiple choices, you are billed for generated tokens across all
1393+
choices.
13911394
13921395
parallel_tool_calls: Whether to enable
13931396
[parallel function calling](https://developers.openai.com/api/docs/guides/function-calling#parallel-function-calling)
@@ -2357,9 +2360,10 @@ async def create(
23572360
23582361
moderation: Configuration for running moderation on the request input and generated output.
23592362
2360-
n: How many chat completion choices to generate for each input message. Note that
2361-
you will be charged based on the number of generated tokens across all of the
2362-
choices. Keep `n` as `1` to minimize costs.
2363+
n: How many chat completion choices to generate for each input message. Omit `n` to
2364+
generate one choice. Newer models reject an explicit `n`, even `n=1`. When
2365+
requesting multiple choices, you are billed for generated tokens across all
2366+
choices.
23632367
23642368
parallel_tool_calls: Whether to enable
23652369
[parallel function calling](https://developers.openai.com/api/docs/guides/function-calling#parallel-function-calling)
@@ -2777,9 +2781,10 @@ async def create(
27772781
27782782
moderation: Configuration for running moderation on the request input and generated output.
27792783
2780-
n: How many chat completion choices to generate for each input message. Note that
2781-
you will be charged based on the number of generated tokens across all of the
2782-
choices. Keep `n` as `1` to minimize costs.
2784+
n: How many chat completion choices to generate for each input message. Omit `n` to
2785+
generate one choice. Newer models reject an explicit `n`, even `n=1`. When
2786+
requesting multiple choices, you are billed for generated tokens across all
2787+
choices.
27832788
27842789
parallel_tool_calls: Whether to enable
27852790
[parallel function calling](https://developers.openai.com/api/docs/guides/function-calling#parallel-function-calling)
@@ -3188,9 +3193,10 @@ async def create(
31883193
31893194
moderation: Configuration for running moderation on the request input and generated output.
31903195
3191-
n: How many chat completion choices to generate for each input message. Note that
3192-
you will be charged based on the number of generated tokens across all of the
3193-
choices. Keep `n` as `1` to minimize costs.
3196+
n: How many chat completion choices to generate for each input message. Omit `n` to
3197+
generate one choice. Newer models reject an explicit `n`, even `n=1`. When
3198+
requesting multiple choices, you are billed for generated tokens across all
3199+
choices.
31943200
31953201
parallel_tool_calls: Whether to enable
31963202
[parallel function calling](https://developers.openai.com/api/docs/guides/function-calling#parallel-function-calling)

‎src/openai/resources/completions.py‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def create(
142142
[Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)
143143
for counting tokens.
144144
145-
n: How many completions to generate for each prompt.
145+
n: How many completions to generate for each prompt. Omit `n` to generate one
146+
completion per prompt.
146147
147148
**Note:** Because this parameter generates many completions, it can quickly
148149
consume your token quota. Use carefully and ensure that you have reasonable
@@ -308,7 +309,8 @@ def create(
308309
[Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)
309310
for counting tokens.
310311
311-
n: How many completions to generate for each prompt.
312+
n: How many completions to generate for each prompt. Omit `n` to generate one
313+
completion per prompt.
312314
313315
**Note:** Because this parameter generates many completions, it can quickly
314316
consume your token quota. Use carefully and ensure that you have reasonable
@@ -467,7 +469,8 @@ def create(
467469
[Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)
468470
for counting tokens.
469471
470-
n: How many completions to generate for each prompt.
472+
n: How many completions to generate for each prompt. Omit `n` to generate one
473+
completion per prompt.
471474
472475
**Note:** Because this parameter generates many completions, it can quickly
473476
consume your token quota. Use carefully and ensure that you have reasonable
@@ -712,7 +715,8 @@ async def create(
712715
[Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)
713716
for counting tokens.
714717
715-
n: How many completions to generate for each prompt.
718+
n: How many completions to generate for each prompt. Omit `n` to generate one
719+
completion per prompt.
716720
717721
**Note:** Because this parameter generates many completions, it can quickly
718722
consume your token quota. Use carefully and ensure that you have reasonable
@@ -878,7 +882,8 @@ async def create(
878882
[Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)
879883
for counting tokens.
880884
881-
n: How many completions to generate for each prompt.
885+
n: How many completions to generate for each prompt. Omit `n` to generate one
886+
completion per prompt.
882887
883888
**Note:** Because this parameter generates many completions, it can quickly
884889
consume your token quota. Use carefully and ensure that you have reasonable
@@ -1037,7 +1042,8 @@ async def create(
10371042
[Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)
10381043
for counting tokens.
10391044
1040-
n: How many completions to generate for each prompt.
1045+
n: How many completions to generate for each prompt. Omit `n` to generate one
1046+
completion per prompt.
10411047
10421048
**Note:** Because this parameter generates many completions, it can quickly
10431049
consume your token quota. Use carefully and ensure that you have reasonable

‎src/openai/types/chat/completion_create_params.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,9 @@ class CompletionCreateParamsBase(TypedDict, total=False):
234234
n: Optional[int]
235235
"""How many chat completion choices to generate for each input message.
236236
237-
Note that you will be charged based on the number of generated tokens across all
238-
of the choices. Keep `n` as `1` to minimize costs.
237+
Omit `n` to generate one choice. Newer models reject an explicit `n`, even
238+
`n=1`. When requesting multiple choices, you are billed for generated tokens
239+
across all choices.
239240
"""
240241

241242
parallel_tool_calls: bool

‎src/openai/types/completion_create_params.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class CompletionCreateParamsBase(TypedDict, total=False):
9797
n: Optional[int]
9898
"""How many completions to generate for each prompt.
9999
100+
Omit `n` to generate one completion per prompt.
101+
100102
**Note:** Because this parameter generates many completions, it can quickly
101103
consume your token quota. Use carefully and ensure that you have reasonable
102104
settings for `max_tokens` and `stop`.

0 commit comments

Comments
 (0)