Skip to navigation

OpenAI-compatible completions endpoint

View as Markdown

Request

This endpoint expects an object.
modelstringRequired
The model to use.
promptlist of integers or list of lists of integers or string or list of stringsRequired
best_ofinteger or nullOptional1-128

Supported for completion only. Generates best_of completions server-side and returns top n ‘best’ (with the highest cumulative log probability). Results cannot be streamed. 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. When best_of != n, best_of is returned by the backend API and n-slicing is done at request output.

echoboolean or nullOptionalDefaults to false
If true, echo back the prompt in addition to the completion. 'echo' and 'stream' fields cannot be true simultaneously.
frequency_penaltydouble or nullOptional-2-2Defaults to 0

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.

logit_biasmap from strings to doubles or nullOptional

Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. 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.

logprobsinteger or nullOptional0-5

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.

max_tokensinteger or nullOptional>=1Defaults to 16
The maximum number of tokens that can be generated.
ninteger or nullOptional1-128Defaults to 1
How many completions to generate for each prompt.
presence_penaltydouble or nullOptional-2-2Defaults to 0

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.

seedinteger or nullOptional-9223372036854776000-9223372036854776000
Changing the seed will produce a different response with similar characteristics. Fixing the seed will reproduce the same results if all other parameters are also kept constant.
stopstring or list of strings or nullOptional
Sequences where the API will stop generating further tokens.
streamboolean or nullOptionalDefaults to false

If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE]

stream_optionsobject or nullOptional
suffixstring or nullOptional
The suffix that comes after a completion of inserted text.
temperaturedouble or nullOptional0-2Defaults to 1
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.
top_pdouble or nullOptional<=1Defaults to 1

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. We generally recommend altering this or temperature but not both.

userstring or nullOptional>=1 character

A unique identifier representing your end-user.

top_kinteger or nullOptional>=-1Defaults to -1

How many of the top tokens to sample from. Must be -1 or greater than or equal to 1.

min_pdouble or nullOptional
repetition_penaltydouble or nullOptionalDefaults to 1
How much to penalize tokens based on how frequently they occur in the text. A value of 1 means no penalty, while values larger than 1 discourage and values smaller encourage.
include_stop_str_in_outputboolean or nullOptionalDefaults to false

Whether to include the stop string in the output. This is only applied when the stop or stop_token_ids is set. Can be a boolean or null.

ignore_eosboolean or nullOptionalDefaults to false

Whether to ignore End of Sequence (EOS) tokens. It is advised to set max_tokens when this is set to avoid overly long response times.

min_tokensinteger or nullOptionalDefaults to 0
Min Tokens, can be an integer or null.
prompt_logprobsinteger or nullOptional
add_special_tokensbooleanOptionalDefaults to true

If true (the default), special tokens (e.g. BOS) will be added to the prompt.

response_formatobject or nullOptional

An object specifying the format that the model must output. Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.

guided_jsonstring or map from strings to any or object or nullOptional
If specified, the output will follow the JSON schema. Can be a string, an object, a reference to a BaseModel, or null.
guided_regexstring or nullOptional
If specified, the output will follow the regex pattern. Can be a string or null.
guided_choicelist of strings or nullOptional
If specified, the output will be exactly one of the choices.
guided_grammarstring or nullOptional

If specified, the output will follow the context-free grammar. Can be a string or null.

guided_decoding_backendstring or nullOptional

If specified, will override the default guided decoding backend of the server for this specific request. If set, must be one of ‘outlines’ / ‘lm-format-enforcer’ / name of a custom decoding backend

guided_whitespace_patternstring or nullOptional

If specified, will override the default whitespace pattern for guided json decoding. Must be used with guided_json. Supported in ‘outlines’ backend.

return_tokens_as_token_idsboolean or nullOptional

If specified with ‘logprobs’, tokens are represented as strings of the form ‘token_id:{token_id}’ so that tokens that are not JSON-encodable can be identified.

nvextobject or nullOptional
Extension dictionary for NIM API.

Response

Successful Response
CompletionResponseobject
OR
CompletionStreamResponseobject

Errors

400
Bad Request Error
404
Not Found Error
415
Unsupported Media Type Error
422
Unprocessable Entity Error
500
Internal Server Error