MyApp

<back to all web services

ChatCompletion

AI

Chat Completions API (OpenAI-Compatible)

The following routes are available for this service:
POST/v1/chat/completions
ChatCompletion Parameters:
NameParameterData TypeRequiredDescription
MessagesbodyList<AiMessage>YesThe messages to generate chat completions for.
ModelbodystringYesID of the model to use. See the model endpoint compatibility table for details on which models work with the Chat API
AudiobodyAiChatAudioNoParameters for audio output. Required when audio output is requested with modalities: [audio]
LogitBiasbodyDictionary<int, int>NoModify the likelihood of specified tokens appearing in the completion.
MetadatabodyDictionary<string, string>NoSet of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format.
ReasoningEffortbodystringNoConstrains effort on reasoning for reasoning models. Currently supported values are minimal, low, medium, and high (none, default). Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.

Allowable Values

  • low
  • medium
  • high
  • none
  • default
ResponseFormatbodyAiResponseFormatNoAn object specifying the format that the model must output. Compatible with GPT-4 Turbo and all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`. Setting Type to ResponseFormat.JsonObject enables JSON mode, which guarantees the message the model generates is valid JSON.
ServiceTierbodystringNoSpecifies the processing type used for serving the request.

Allowable Values

  • auto
  • default
SafetyIdentifierbodystringNoA stable identifier used to help detect users of your application that may be violating OpenAI's usage policies. The IDs should be a string that uniquely identifies each user.
StopbodyList<string>NoUp to 4 sequences where the API will stop generating further tokens.
ModalitiesbodyList<string>NoOutput types that you would like the model to generate. Most models are capable of generating text, which is the default:
PromptCacheKeybodystringNoUsed by OpenAI to cache responses for similar requests to optimize your cache hit rates.
ToolsbodyList<Tool>NoA list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.
VerbositybodystringNoConstrains the verbosity of the model's response. Lower values will result in more concise responses, while higher values will result in more verbose responses. Currently supported values are low, medium, and high.

Allowable Values

  • low
  • medium
  • high
Temperaturebodydouble?NoWhat 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.

Valid Range: 0 - 2

MaxCompletionTokensbodyint?NoAn upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.

Valid Range: 1 -

TopLogprobsbodyint?NoAn integer between 0 and 20 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.

Valid Range: 0 - 20

TopPbodydouble?NoAn 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.

Valid Range: 0 - 1

FrequencyPenaltybodydouble?NoNumber 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.

Valid Range: 0 - 2

PresencePenaltybodydouble?NoNumber 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.

Valid Range: 0 - 2

Seedbodyint?NoThis feature is in Beta. 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. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.
Nbodyint?NoHow 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.
Storebodybool?NoWhether or not to store the output of this chat completion request for use in our model distillation or evals products.
Logprobsbodybool?NoWhether 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.
ParallelToolCallsbodybool?NoWhether to enable parallel function calling during tool use.
EnableThinkingbodybool?NoWhether to enable thinking mode for some Qwen models and providers.
Streambodybool?NoIf 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]` message.
AiMessage Parameters:
NameParameterData TypeRequiredDescription
ContentformList<AiContent>NoThe contents of the message.
RoleformstringYesThe role of the author of this message. Valid values are `system`, `user`, `assistant` and `tool`.
NameformstringNoAn optional name for the participant. Provides the model information to differentiate between participants of the same role.
ToolCallsformList<ToolCall>NoThe tool calls generated by the model, such as function calls.
ToolCallIdformstringNoTool call that this message is responding to.
ReasoningformstringNoThe reasoning an assistant message was generated with, normalized per provider when replayed as history.
ReasoningContentformstringNoThe reasoning an assistant message was generated with, as emitted by Gemini and most OpenAI-compatible providers.
Timestampformlong?NoUnix timestamp (in milliseconds) the message was generated.
ImagesformList<AiContent>NoImages attached to the message. Folded into `content` parts before sending to a provider.
AiContent Parameters:
NameParameterData TypeRequiredDescription
TypeformstringYesThe type of the content part.
ToolCall Parameters:
NameParameterData TypeRequiredDescription
IdformstringYesThe ID of the tool call.
TypeformstringYesThe type of the tool. Currently, only `function` is supported.
FunctionformToolFunctionYesThe function that the model called.
ToolFunction Parameters:
NameParameterData TypeRequiredDescription
NameformstringYesThe name of the function to call.
ArgumentsformstringYesThe arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
AiChatAudio Parameters:
NameParameterData TypeRequiredDescription
FormatformstringYesSpecifies the output audio format. Must be one of wav, mp3, flac, opus, or pcm16.
VoiceformstringYesThe voice the model uses to respond. Supported voices are alloy, ash, ballad, coral, echo, fable, nova, onyx, sage, and shimmer.
AiResponseFormat Parameters:
NameParameterData TypeRequiredDescription
TypeformResponseFormatNoAn object specifying the format that the model must output. Compatible with GPT-4 Turbo and all GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106.
ResponseFormat Enum:
NameValue
Texttext
JsonObjectjson_object
Tool Parameters:
NameParameterData TypeRequiredDescription
TypeformToolTypeNoThe type of the tool. Currently, only function is supported.
FunctionformAiToolFunctionNoThe function definition the model may call.
ToolType Enum:
NameValue
Functionfunction
AiToolFunction Parameters:
NameParameterData TypeRequiredDescription
NameformstringNoThe name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
DescriptionformstringNoA description of what the function does, used by the model to choose when and how to call the function.
ParametersformDictionary<string, Object>NoThe parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format.
ChatResponse Parameters:
NameParameterData TypeRequiredDescription
IdformstringYesA unique identifier for the chat completion.
ChoicesformList<Choice>YesA list of chat completion choices. Can be more than one if n is greater than 1.
CreatedformlongNoThe Unix timestamp (in seconds) of when the chat completion was created.
ModelformstringYesThe model used for the chat completion.
SystemFingerprintformstringNoThis fingerprint represents the backend configuration that the model runs with.
ObjectformstringYesThe object type, which is always chat.completion.
ServiceTierformstringNoSpecifies the processing type used for serving the request.
UsageformAiUsageYesUsage statistics for the completion request.
ProviderformstringNoThe provider used for the chat completion.
Costformdouble?NoTotal cost of the completion in USD, accumulated across every request in the tool loop.
ToolHistoryformList<ChoiceMessage>NoThe assistant and tool messages exchanged during the tool-execution loop, in order.
MetadataformDictionary<string, string>NoSet of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format.
ResponseStatusformResponseStatusNo
Choice Parameters:
NameParameterData TypeRequiredDescription
FinishReasonformstringYesThe reason the model stopped generating tokens. This will be stop if the model hit a natural stop point or a provided stop sequence, length if the maximum number of tokens specified in the request was reached, content_filter if content was omitted due to a flag from our content filters, tool_calls if the model called a tool
IndexformintNoThe index of the choice in the list of choices.
MessageformChoiceMessageYesA chat completion message generated by the model.
LogprobsformLogprobsNoLog probability information for the choice.
ChoiceMessage Parameters:
NameParameterData TypeRequiredDescription
ContentformstringYesThe contents of the message.
RefusalformstringNoThe refusal message generated by the model.
ReasoningformstringNoThe reasoning process used by the model.
ReasoningContentformstringNoThe reasoning process used by the model, as emitted by Gemini and most OpenAI-compatible providers.
ThinkingformstringNoThe reasoning process used by the model, as emitted by Anthropic.
RoleformstringYesThe role of the author of this message.
Timestampformlong?NoUnix timestamp (in milliseconds) the message was generated.
ToolCallIdformstringNoThe tool call this message is responding to, set on `tool` role messages in tool_history.
ImagesformList<AiContent>NoImages generated by the model or produced by a tool call.
AudiosformList<AiContent>NoAudio generated by the model or produced by a tool call.
FilesformList<AiContent>NoFiles produced by a tool call.
AnnotationsformList<ChoiceAnnotation>NoAnnotations for the message, when applicable, as when using the web search tool.
AudioformChoiceAudioNoIf the audio output modality is requested, this object contains data about the audio response from the model.
ToolCallsformList<ToolCall>NoThe tool calls generated by the model, such as function calls.
ChoiceAnnotation Parameters:
NameParameterData TypeRequiredDescription
TypeformstringYesThe type of the URL citation. Always url_citation.
UrlCitationformUrlCitationYesA URL citation when using web search.
UrlCitation Parameters:
NameParameterData TypeRequiredDescription
EndIndexformintNoThe index of the last character of the URL citation in the message.
StartIndexformintNoThe index of the first character of the URL citation in the message.
TitleformstringYesThe title of the web resource.
UrlformstringYesThe URL of the web resource.
ChoiceAudio Parameters:
NameParameterData TypeRequiredDescription
DataformstringYesBase64 encoded audio bytes generated by the model, in the format specified in the request.
ExpiresAtformlongNoThe Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.
IdformstringYesUnique identifier for this audio response.
TranscriptformstringYesTranscript of the audio generated by the model.
Logprobs Parameters:
NameParameterData TypeRequiredDescription
ContentformList<LogprobItem>YesA list of message content tokens with log probability information.
LogprobItem Parameters:
NameParameterData TypeRequiredDescription
TokenformstringYesThe token.
LogprobformdoubleNoThe log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value `-9999`.0 is used to signify that the token is very unlikely.
Bytesformbyte[]YesA list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be `null` if there is no bytes representation for the token.
TopLogprobsformList<LogprobItem>YesList of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested `top_logprobs` returned.
AiUsage Parameters:
NameParameterData TypeRequiredDescription
CompletionTokensformlongNoNumber of tokens in the generated completion.
PromptTokensformlongNoNumber of tokens in the prompt.
TotalTokensformlongNoTotal number of tokens used in the request (prompt + completion).
CompletionTokensDetailsformAiCompletionUsageNoBreakdown of tokens used in a completion.
PromptTokensDetailsformAiPromptUsageNoBreakdown of tokens used in the prompt.
Durationformlong?NoSeconds spent servicing the completion, including every request in the tool loop.
AiCompletionUsage Parameters:
NameParameterData TypeRequiredDescription
AcceptedPredictionTokensformlongNoWhen using Predicted Outputs, the number of tokens in the prediction that appeared in the completion.
AudioTokensformlongNoAudio input tokens generated by the model.
ReasoningTokensformlongNoTokens generated by the model for reasoning.
RejectedPredictionTokensformlongNoWhen using Predicted Outputs, the number of tokens in the prediction that did not appear in the completion.
AiPromptUsage Parameters:
NameParameterData TypeRequiredDescription
AcceptedPredictionTokensformlongNoWhen using Predicted Outputs, the number of tokens in the prediction that appeared in the completion.
AudioTokensformlongNoAudio input tokens present in the prompt.
CachedTokensformlongNoCached tokens present in the prompt.

To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json

To embed the response in a jsonp callback, append ?callback=myCallback

HTTP + JSON

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /v1/chat/completions HTTP/1.1 
Host: blazor-vue.web-templates.io 
Accept: application/json
Content-Type: application/json
Content-Length: length

{"messages":[{"content":[{}],"role":"String","name":"String","tool_calls":[{"id":"String","type":"String","function":{"name":"String","arguments":"String"}}],"tool_call_id":"String","reasoning":"String","reasoning_content":"String","timestamp":0,"images":[{}]}],"model":"String","audio":{"format":"String","voice":"String"},"logit_bias":{"0":0},"metadata":{"String":"String"},"reasoning_effort":"String","response_format":{"type":"text"},"service_tier":"String","safety_identifier":"String","stop":["String"],"modalities":["String"],"prompt_cache_key":"String","tools":[{"type":"function","function":{"name":"String","description":"String","parameters":{"String":{}}}}],"verbosity":"String","temperature":0,"max_completion_tokens":0,"top_logprobs":0,"top_p":0,"frequency_penalty":0,"presence_penalty":0,"seed":0,"n":0,"store":false,"logprobs":false,"parallel_tool_calls":false,"enable_thinking":false,"stream":false}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

{"id":"String","choices":[{"finish_reason":"String","index":0,"message":{"content":"String","refusal":"String","reasoning":"String","reasoning_content":"String","thinking":"String","role":"String","timestamp":0,"tool_call_id":"String","images":[{}],"audios":[{}],"files":[{}],"annotations":[{"type":"String","url_citation":{"end_index":0,"start_index":0,"title":"String","url":"String"}}],"audio":{"data":"String","expires_at":0,"id":"String","transcript":"String"},"tool_calls":[{"id":"String","type":"String","function":{"name":"String","arguments":"String"}}]},"logprobs":{"content":[{"token":"String","logprob":0,"bytes":"AA==","top_logprobs":[{"token":"String","logprob":0,"bytes":"AA==","top_logprobs":[{"token":"String","logprob":0,"bytes":"AA=="}]}]}]}}],"created":0,"model":"String","system_fingerprint":"String","object":"String","service_tier":"String","usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0},"prompt_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"cached_tokens":0},"duration":0},"provider":"String","cost":0,"tool_history":[{"content":"String","refusal":"String","reasoning":"String","reasoning_content":"String","thinking":"String","role":"String","timestamp":0,"tool_call_id":"String","images":[{}],"audios":[{}],"files":[{}],"annotations":[{"type":"String","url_citation":{"end_index":0,"start_index":0,"title":"String","url":"String"}}],"audio":{"data":"String","expires_at":0,"id":"String","transcript":"String"},"tool_calls":[{"id":"String","type":"String","function":{"name":"String","arguments":"String"}}]}],"metadata":{"String":"String"},"responseStatus":{"errorCode":"String","message":"String","stackTrace":"String","errors":[{"errorCode":"String","fieldName":"String","message":"String","meta":{"String":"String"}}],"meta":{"String":"String"}}}