Skip to navigation

OpenAI-compatible chat endpoint

View as Markdown

Request

This endpoint expects an object.
messageslist of objectsRequired
A list of messages comprising the conversation so far.
modelstringRequired
The model to use.
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.

logprobsboolean or nullOptionalDefaults to false

Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message.

top_logprobsinteger or nullOptional1-20

An integer specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used.

max_tokensinteger or nullOptional>=1
The maximum number of tokens that can be generated.
max_completion_tokensinteger or nullOptional>=1

Alternative to max_tokens. If set, will be used as max_tokens.

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.

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.

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
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.

toolslist of objects or nullOptional
tool_choiceenum or object or nullOptionalDefaults to none

Controls which (if any) tool is called by the model.

parallel_tool_callsboolean or nullOptionalDefaults to false
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 false

If true, special tokens (e.g. BOS) will be added to the prompt on top of what is added by the chat template. For most models, the chat template takes care of adding the special tokens so this should be set to false (as is the default).

documentslist of maps from strings to strings or nullOptional

A list of dicts representing documents that will be accessible to the model if it is performing RAG (retrieval-augmented generation). If the template does not support RAG, this argument will have no effect. We recommend that each document should be a dict containing “title” and “text” keys.

chat_templatestring or nullOptional
A Jinja template to use for this conversion. As of transformers v4.44, default chat template is no longer allowed, so you must provide a chat template if the tokenizer does not define one.
chat_template_kwargsobject or nullOptional
Additional kwargs to pass to the template renderer. Will be accessible by the chat template.
mm_processor_kwargsobject or nullOptional
Additional kwargs to pass to the HF processor.
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.
request_idstringOptional

The request_id related to this request. If the caller does not set it, a random_uuid will be generated. This id is used through out the inference process and return in response.

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
ChatCompletionResponseobject
OR
ChatCompletionStreamResponseobject

Errors

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