cli/resources/completions/index.md +0 −480 deleted
File Deleted View Diff
1# Completions
2
3## Create completion
4
5`$ openai completions create`
6
7**post** `/completions`
8
9Creates a completion for the provided prompt and parameters.
10
11Returns a completion object, or a sequence of completion objects if the request is streamed.
12
13### Parameters
14
15- `--model: string or "gpt-3.5-turbo-instruct" or "davinci-002" or "babbage-002"`
16
17 ID of the model to use. You can use the [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](https://platform.openai.com/docs/models) for descriptions of them.
18
19- `--prompt: string or array of string or array of number or array of array of number`
20
21 The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays.
22
23 Note that <|endoftext|> is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document.
24
25- `--best-of: optional number`
26
27 Generates `best_of` completions server-side and returns the "best" (the one with the highest log probability per token). Results cannot be streamed.
28
29 When used with `n`, `best_of` controls the number of candidate completions and `n` specifies how many to return – `best_of` must be greater than `n`.
30
31 **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`.
32
33- `--echo: optional boolean`
34
35 Echo back the prompt in addition to the completion
36
37- `--frequency-penalty: optional number`
38
39 Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
40
41 [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/text-generation)
42
43- `--logit-bias: optional map[number]`
44
45 Modify the likelihood of specified tokens appearing in the completion.
46
47 Accepts a JSON object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this [tokenizer tool](/tokenizer?view=bpe) to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
48
49 As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being generated.
50
51- `--logprobs: optional number`
52
53 Include the log probabilities on the `logprobs` most likely output tokens, as well the chosen tokens. For example, if `logprobs` is 5, the API will return a list of the 5 most likely tokens. The API will always return the `logprob` of the sampled token, so there may be up to `logprobs+1` elements in the response.
54
55 The maximum value for `logprobs` is 5.
56
57- `--max-tokens: optional number`
58
59 The maximum number of [tokens](/tokenizer) that can be generated in the completion.
60
61 The token count of your prompt plus `max_tokens` cannot exceed the model's context length. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens.
62
63- `--n: optional number`
64
65 How many completions to generate for each prompt.
66
67 **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`.
68
69- `--presence-penalty: optional number`
70
71 Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
72
73 [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/text-generation)
74
75- `--seed: optional number`
76
77 If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.
78
79 Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
80
81- `--stop: optional string or array of string`
82
83 Not supported with latest reasoning models `o3` and `o4-mini`.
84
85 Up to 4 sequences where the API will stop generating further tokens. The
86 returned text will not contain the stop sequence.
87
88- `--stream-options: optional object { include_obfuscation, include_usage }`
89
90 Options for streaming response. Only set this when you set `stream: true`.
91
92- `--suffix: optional string`
93
94 The suffix that comes after a completion of inserted text.
95
96 This parameter is only supported for `gpt-3.5-turbo-instruct`.
97
98- `--temperature: optional number`
99
100 What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
101
102 We generally recommend altering this or `top_p` but not both.
103
104- `--top-p: optional number`
105
106 An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
107
108 We generally recommend altering this or `temperature` but not both.
109
110- `--user: optional string`
111
112 A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
113
114### Returns
115
116- `completion: object { id, choices, created, 4 more }`
117
118 Represents a completion response from the API. Note: both the streamed and non-streamed response objects share the same shape (unlike the chat endpoint).
119
120 - `id: string`
121
122 A unique identifier for the completion.
123
124 - `choices: array of CompletionChoice`
125
126 The list of completion choices the model generated for the input prompt.
127
128 - `finish_reason: "stop" or "length" or "content_filter"`
129
130 The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,
131 `length` if the maximum number of tokens specified in the request was reached,
132 or `content_filter` if content was omitted due to a flag from our content filters.
133
134 - `"stop"`
135
136 - `"length"`
137
138 - `"content_filter"`
139
140 - `index: number`
141
142 - `logprobs: object { text_offset, token_logprobs, tokens, top_logprobs }`
143
144 - `text_offset: optional array of number`
145
146 - `token_logprobs: optional array of number`
147
148 - `tokens: optional array of string`
149
150 - `top_logprobs: optional array of map[number]`
151
152 - `text: string`
153
154 - `created: number`
155
156 The Unix timestamp (in seconds) of when the completion was created.
157
158 - `model: string`
159
160 The model used for completion.
161
162 - `object: "text_completion"`
163
164 The object type, which is always "text_completion"
165
166 - `system_fingerprint: optional string`
167
168 This fingerprint represents the backend configuration that the model runs with.
169
170 Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.
171
172 - `usage: optional object { completion_tokens, prompt_tokens, total_tokens, 2 more }`
173
174 Usage statistics for the completion request.
175
176 - `completion_tokens: number`
177
178 Number of tokens in the generated completion.
179
180 - `prompt_tokens: number`
181
182 Number of tokens in the prompt.
183
184 - `total_tokens: number`
185
186 Total number of tokens used in the request (prompt + completion).
187
188 - `completion_tokens_details: optional object { accepted_prediction_tokens, audio_tokens, reasoning_tokens, rejected_prediction_tokens }`
189
190 Breakdown of tokens used in a completion.
191
192 - `accepted_prediction_tokens: optional number`
193
194 When using Predicted Outputs, the number of tokens in the
195 prediction that appeared in the completion.
196
197 - `audio_tokens: optional number`
198
199 Audio input tokens generated by the model.
200
201 - `reasoning_tokens: optional number`
202
203 Tokens generated by the model for reasoning.
204
205 - `rejected_prediction_tokens: optional number`
206
207 When using Predicted Outputs, the number of tokens in the
208 prediction that did not appear in the completion. However, like
209 reasoning tokens, these tokens are still counted in the total
210 completion tokens for purposes of billing, output, and context window
211 limits.
212
213 - `prompt_tokens_details: optional object { audio_tokens, cached_tokens }`
214
215 Breakdown of tokens used in the prompt.
216
217 - `audio_tokens: optional number`
218
219 Audio input tokens present in the prompt.
220
221 - `cached_tokens: optional number`
222
223 Cached tokens present in the prompt.
224
225### Example
226
227```cli
228openai completions create \
229 --api-key 'My API Key' \
230 --model gpt-3.5-turbo-instruct \
231 --prompt 'This is a test.'
232```
233
234#### Response
235
236```json
237{
238 "id": "id",
239 "choices": [
240 {
241 "finish_reason": "stop",
242 "index": 0,
243 "logprobs": {
244 "text_offset": [
245 0
246 ],
247 "token_logprobs": [
248 0
249 ],
250 "tokens": [
251 "string"
252 ],
253 "top_logprobs": [
254 {
255 "foo": 0
256 }
257 ]
258 },
259 "text": "text"
260 }
261 ],
262 "created": 0,
263 "model": "model",
264 "object": "text_completion",
265 "system_fingerprint": "system_fingerprint",
266 "usage": {
267 "completion_tokens": 0,
268 "prompt_tokens": 0,
269 "total_tokens": 0,
270 "completion_tokens_details": {
271 "accepted_prediction_tokens": 0,
272 "audio_tokens": 0,
273 "reasoning_tokens": 0,
274 "rejected_prediction_tokens": 0
275 },
276 "prompt_tokens_details": {
277 "audio_tokens": 0,
278 "cached_tokens": 0
279 }
280 }
281}
282```
283
284## Domain Types
285
286### Completion
287
288- `completion: object { id, choices, created, 4 more }`
289
290 Represents a completion response from the API. Note: both the streamed and non-streamed response objects share the same shape (unlike the chat endpoint).
291
292 - `id: string`
293
294 A unique identifier for the completion.
295
296 - `choices: array of CompletionChoice`
297
298 The list of completion choices the model generated for the input prompt.
299
300 - `finish_reason: "stop" or "length" or "content_filter"`
301
302 The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,
303 `length` if the maximum number of tokens specified in the request was reached,
304 or `content_filter` if content was omitted due to a flag from our content filters.
305
306 - `"stop"`
307
308 - `"length"`
309
310 - `"content_filter"`
311
312 - `index: number`
313
314 - `logprobs: object { text_offset, token_logprobs, tokens, top_logprobs }`
315
316 - `text_offset: optional array of number`
317
318 - `token_logprobs: optional array of number`
319
320 - `tokens: optional array of string`
321
322 - `top_logprobs: optional array of map[number]`
323
324 - `text: string`
325
326 - `created: number`
327
328 The Unix timestamp (in seconds) of when the completion was created.
329
330 - `model: string`
331
332 The model used for completion.
333
334 - `object: "text_completion"`
335
336 The object type, which is always "text_completion"
337
338 - `system_fingerprint: optional string`
339
340 This fingerprint represents the backend configuration that the model runs with.
341
342 Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.
343
344 - `usage: optional object { completion_tokens, prompt_tokens, total_tokens, 2 more }`
345
346 Usage statistics for the completion request.
347
348 - `completion_tokens: number`
349
350 Number of tokens in the generated completion.
351
352 - `prompt_tokens: number`
353
354 Number of tokens in the prompt.
355
356 - `total_tokens: number`
357
358 Total number of tokens used in the request (prompt + completion).
359
360 - `completion_tokens_details: optional object { accepted_prediction_tokens, audio_tokens, reasoning_tokens, rejected_prediction_tokens }`
361
362 Breakdown of tokens used in a completion.
363
364 - `accepted_prediction_tokens: optional number`
365
366 When using Predicted Outputs, the number of tokens in the
367 prediction that appeared in the completion.
368
369 - `audio_tokens: optional number`
370
371 Audio input tokens generated by the model.
372
373 - `reasoning_tokens: optional number`
374
375 Tokens generated by the model for reasoning.
376
377 - `rejected_prediction_tokens: optional number`
378
379 When using Predicted Outputs, the number of tokens in the
380 prediction that did not appear in the completion. However, like
381 reasoning tokens, these tokens are still counted in the total
382 completion tokens for purposes of billing, output, and context window
383 limits.
384
385 - `prompt_tokens_details: optional object { audio_tokens, cached_tokens }`
386
387 Breakdown of tokens used in the prompt.
388
389 - `audio_tokens: optional number`
390
391 Audio input tokens present in the prompt.
392
393 - `cached_tokens: optional number`
394
395 Cached tokens present in the prompt.
396
397### Completion Choice
398
399- `completion_choice: object { finish_reason, index, logprobs, text }`
400
401 - `finish_reason: "stop" or "length" or "content_filter"`
402
403 The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,
404 `length` if the maximum number of tokens specified in the request was reached,
405 or `content_filter` if content was omitted due to a flag from our content filters.
406
407 - `"stop"`
408
409 - `"length"`
410
411 - `"content_filter"`
412
413 - `index: number`
414
415 - `logprobs: object { text_offset, token_logprobs, tokens, top_logprobs }`
416
417 - `text_offset: optional array of number`
418
419 - `token_logprobs: optional array of number`
420
421 - `tokens: optional array of string`
422
423 - `top_logprobs: optional array of map[number]`
424
425 - `text: string`
426
427### Completion Usage
428
429- `completion_usage: object { completion_tokens, prompt_tokens, total_tokens, 2 more }`
430
431 Usage statistics for the completion request.
432
433 - `completion_tokens: number`
434
435 Number of tokens in the generated completion.
436
437 - `prompt_tokens: number`
438
439 Number of tokens in the prompt.
440
441 - `total_tokens: number`
442
443 Total number of tokens used in the request (prompt + completion).
444
445 - `completion_tokens_details: optional object { accepted_prediction_tokens, audio_tokens, reasoning_tokens, rejected_prediction_tokens }`
446
447 Breakdown of tokens used in a completion.
448
449 - `accepted_prediction_tokens: optional number`
450
451 When using Predicted Outputs, the number of tokens in the
452 prediction that appeared in the completion.
453
454 - `audio_tokens: optional number`
455
456 Audio input tokens generated by the model.
457
458 - `reasoning_tokens: optional number`
459
460 Tokens generated by the model for reasoning.
461
462 - `rejected_prediction_tokens: optional number`
463
464 When using Predicted Outputs, the number of tokens in the
465 prediction that did not appear in the completion. However, like
466 reasoning tokens, these tokens are still counted in the total
467 completion tokens for purposes of billing, output, and context window
468 limits.
469
470 - `prompt_tokens_details: optional object { audio_tokens, cached_tokens }`
471
472 Breakdown of tokens used in the prompt.
473
474 - `audio_tokens: optional number`
475
476 Audio input tokens present in the prompt.
477
478 - `cached_tokens: optional number`
479
480 Cached tokens present in the prompt.