cli/resources/completions/methods/create/index.md +0 −280 deleted
File Deleted View Diff
1## Create completion
2
3`$ openai completions create`
4
5**post** `/completions`
6
7Creates a completion for the provided prompt and parameters.
8
9Returns a completion object, or a sequence of completion objects if the request is streamed.
10
11### Parameters
12
13- `--model: string or "gpt-3.5-turbo-instruct" or "davinci-002" or "babbage-002"`
14
15 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.
16
17- `--prompt: string or array of string or array of number or array of array of number`
18
19 The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays.
20
21 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.
22
23- `--best-of: optional number`
24
25 Generates `best_of` completions server-side and returns the "best" (the one with the highest log probability per token). Results cannot be streamed.
26
27 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`.
28
29 **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`.
30
31- `--echo: optional boolean`
32
33 Echo back the prompt in addition to the completion
34
35- `--frequency-penalty: optional number`
36
37 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.
38
39 [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/text-generation)
40
41- `--logit-bias: optional map[number]`
42
43 Modify the likelihood of specified tokens appearing in the completion.
44
45 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.
46
47 As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being generated.
48
49- `--logprobs: optional number`
50
51 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.
52
53 The maximum value for `logprobs` is 5.
54
55- `--max-tokens: optional number`
56
57 The maximum number of [tokens](/tokenizer) that can be generated in the completion.
58
59 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.
60
61- `--n: optional number`
62
63 How many completions to generate for each prompt.
64
65 **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`.
66
67- `--presence-penalty: optional number`
68
69 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.
70
71 [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/text-generation)
72
73- `--seed: optional number`
74
75 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.
76
77 Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
78
79- `--stop: optional string or array of string`
80
81 Not supported with latest reasoning models `o3` and `o4-mini`.
82
83 Up to 4 sequences where the API will stop generating further tokens. The
84 returned text will not contain the stop sequence.
85
86- `--stream-options: optional object { include_obfuscation, include_usage }`
87
88 Options for streaming response. Only set this when you set `stream: true`.
89
90- `--suffix: optional string`
91
92 The suffix that comes after a completion of inserted text.
93
94 This parameter is only supported for `gpt-3.5-turbo-instruct`.
95
96- `--temperature: optional number`
97
98 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.
99
100 We generally recommend altering this or `top_p` but not both.
101
102- `--top-p: optional number`
103
104 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.
105
106 We generally recommend altering this or `temperature` but not both.
107
108- `--user: optional string`
109
110 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).
111
112### Returns
113
114- `completion: object { id, choices, created, 4 more }`
115
116 Represents a completion response from the API. Note: both the streamed and non-streamed response objects share the same shape (unlike the chat endpoint).
117
118 - `id: string`
119
120 A unique identifier for the completion.
121
122 - `choices: array of CompletionChoice`
123
124 The list of completion choices the model generated for the input prompt.
125
126 - `finish_reason: "stop" or "length" or "content_filter"`
127
128 The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,
129 `length` if the maximum number of tokens specified in the request was reached,
130 or `content_filter` if content was omitted due to a flag from our content filters.
131
132 - `"stop"`
133
134 - `"length"`
135
136 - `"content_filter"`
137
138 - `index: number`
139
140 - `logprobs: object { text_offset, token_logprobs, tokens, top_logprobs }`
141
142 - `text_offset: optional array of number`
143
144 - `token_logprobs: optional array of number`
145
146 - `tokens: optional array of string`
147
148 - `top_logprobs: optional array of map[number]`
149
150 - `text: string`
151
152 - `created: number`
153
154 The Unix timestamp (in seconds) of when the completion was created.
155
156 - `model: string`
157
158 The model used for completion.
159
160 - `object: "text_completion"`
161
162 The object type, which is always "text_completion"
163
164 - `system_fingerprint: optional string`
165
166 This fingerprint represents the backend configuration that the model runs with.
167
168 Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.
169
170 - `usage: optional object { completion_tokens, prompt_tokens, total_tokens, 2 more }`
171
172 Usage statistics for the completion request.
173
174 - `completion_tokens: number`
175
176 Number of tokens in the generated completion.
177
178 - `prompt_tokens: number`
179
180 Number of tokens in the prompt.
181
182 - `total_tokens: number`
183
184 Total number of tokens used in the request (prompt + completion).
185
186 - `completion_tokens_details: optional object { accepted_prediction_tokens, audio_tokens, reasoning_tokens, rejected_prediction_tokens }`
187
188 Breakdown of tokens used in a completion.
189
190 - `accepted_prediction_tokens: optional number`
191
192 When using Predicted Outputs, the number of tokens in the
193 prediction that appeared in the completion.
194
195 - `audio_tokens: optional number`
196
197 Audio input tokens generated by the model.
198
199 - `reasoning_tokens: optional number`
200
201 Tokens generated by the model for reasoning.
202
203 - `rejected_prediction_tokens: optional number`
204
205 When using Predicted Outputs, the number of tokens in the
206 prediction that did not appear in the completion. However, like
207 reasoning tokens, these tokens are still counted in the total
208 completion tokens for purposes of billing, output, and context window
209 limits.
210
211 - `prompt_tokens_details: optional object { audio_tokens, cached_tokens }`
212
213 Breakdown of tokens used in the prompt.
214
215 - `audio_tokens: optional number`
216
217 Audio input tokens present in the prompt.
218
219 - `cached_tokens: optional number`
220
221 Cached tokens present in the prompt.
222
223### Example
224
225```cli
226openai completions create \
227 --api-key 'My API Key' \
228 --model gpt-3.5-turbo-instruct \
229 --prompt 'This is a test.'
230```
231
232#### Response
233
234```json
235{
236 "id": "id",
237 "choices": [
238 {
239 "finish_reason": "stop",
240 "index": 0,
241 "logprobs": {
242 "text_offset": [
243 0
244 ],
245 "token_logprobs": [
246 0
247 ],
248 "tokens": [
249 "string"
250 ],
251 "top_logprobs": [
252 {
253 "foo": 0
254 }
255 ]
256 },
257 "text": "text"
258 }
259 ],
260 "created": 0,
261 "model": "model",
262 "object": "text_completion",
263 "system_fingerprint": "system_fingerprint",
264 "usage": {
265 "completion_tokens": 0,
266 "prompt_tokens": 0,
267 "total_tokens": 0,
268 "completion_tokens_details": {
269 "accepted_prediction_tokens": 0,
270 "audio_tokens": 0,
271 "reasoning_tokens": 0,
272 "rejected_prediction_tokens": 0
273 },
274 "prompt_tokens_details": {
275 "audio_tokens": 0,
276 "cached_tokens": 0
277 }
278 }
279}
280```