| POST | /v1/chat/completions |
|---|
Imports System
Imports System.IO
Imports System.Collections
Imports System.Collections.Generic
Imports System.Runtime.Serialization
Imports ServiceStack
Imports ServiceStack.DataAnnotations
Imports ServiceStack.AI
Namespace Global
Namespace ServiceStack.AI
'''<Summary>
'''Parameters for audio output. Required when audio output is requested with modalities: [audio]
'''</Summary>
<DataContract>
Public Partial Class AiChatAudio
'''<Summary>
'''Specifies the output audio format. Must be one of wav, mp3, flac, opus, or pcm16.
'''</Summary>
<DataMember(Name:="format")>
Public Overridable Property Format As String
'''<Summary>
'''The voice the model uses to respond. Supported voices are alloy, ash, ballad, coral, echo, fable, nova, onyx, sage, and shimmer.
'''</Summary>
<DataMember(Name:="voice")>
Public Overridable Property Voice As String
End Class
'''<Summary>
'''Usage statistics for the completion request.
'''</Summary>
<DataContract>
Public Partial Class AiCompletionUsage
'''<Summary>
'''When using Predicted Outputs, the number of tokens in the prediction that appeared in the completion.
'''</Summary>
<DataMember(Name:="accepted_prediction_tokens")>
Public Overridable Property AcceptedPredictionTokens As Integer
'''<Summary>
'''Audio input tokens generated by the model.
'''</Summary>
<DataMember(Name:="audio_tokens")>
Public Overridable Property AudioTokens As Integer
'''<Summary>
'''Tokens generated by the model for reasoning.
'''</Summary>
<DataMember(Name:="reasoning_tokens")>
Public Overridable Property ReasoningTokens As Integer
'''<Summary>
'''When using Predicted Outputs, the number of tokens in the prediction that did not appear in the completion.
'''</Summary>
<DataMember(Name:="rejected_prediction_tokens")>
Public Overridable Property RejectedPredictionTokens As Integer
End Class
<DataContract>
Public Partial Class AiContent
'''<Summary>
'''The type of the content part.
'''</Summary>
<DataMember(Name:="type")>
Public Overridable Property Type As String
End Class
'''<Summary>
'''A list of messages comprising the conversation so far.
'''</Summary>
<DataContract>
Public Partial Class AiMessage
'''<Summary>
'''The contents of the message.
'''</Summary>
<DataMember(Name:="content")>
Public Overridable Property Content As List(Of AiContent)
'''<Summary>
'''The role of the author of this message. Valid values are `system`, `user`, `assistant` and `tool`.
'''</Summary>
<DataMember(Name:="role")>
Public Overridable Property Role As String
'''<Summary>
'''An optional name for the participant. Provides the model information to differentiate between participants of the same role.
'''</Summary>
<DataMember(Name:="name")>
Public Overridable Property Name As String
'''<Summary>
'''The tool calls generated by the model, such as function calls.
'''</Summary>
<DataMember(Name:="tool_calls")>
Public Overridable Property ToolCalls As List(Of ToolCall)
'''<Summary>
'''Tool call that this message is responding to.
'''</Summary>
<DataMember(Name:="tool_call_id")>
Public Overridable Property ToolCallId As String
End Class
'''<Summary>
'''Breakdown of tokens used in the prompt.
'''</Summary>
<DataContract>
Public Partial Class AiPromptUsage
'''<Summary>
'''When using Predicted Outputs, the number of tokens in the prediction that appeared in the completion.
'''</Summary>
<DataMember(Name:="accepted_prediction_tokens")>
Public Overridable Property AcceptedPredictionTokens As Integer
'''<Summary>
'''Audio input tokens present in the prompt.
'''</Summary>
<DataMember(Name:="audio_tokens")>
Public Overridable Property AudioTokens As Integer
'''<Summary>
'''Cached tokens present in the prompt.
'''</Summary>
<DataMember(Name:="cached_tokens")>
Public Overridable Property CachedTokens As Integer
End Class
<DataContract>
Public Partial Class AiResponseFormat
'''<Summary>
'''An 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.
'''</Summary>
<DataMember(Name:="response_format")>
Public Overridable Property Type As ResponseFormat
End Class
'''<Summary>
'''Usage statistics for the completion request.
'''</Summary>
<DataContract>
Public Partial Class AiUsage
'''<Summary>
'''Number of tokens in the generated completion.
'''</Summary>
<DataMember(Name:="completion_tokens")>
Public Overridable Property CompletionTokens As Integer
'''<Summary>
'''Number of tokens in the prompt.
'''</Summary>
<DataMember(Name:="prompt_tokens")>
Public Overridable Property PromptTokens As Integer
'''<Summary>
'''Total number of tokens used in the request (prompt + completion).
'''</Summary>
<DataMember(Name:="total_tokens")>
Public Overridable Property TotalTokens As Integer
'''<Summary>
'''Breakdown of tokens used in a completion.
'''</Summary>
<DataMember(Name:="completion_tokens_details")>
Public Overridable Property CompletionTokensDetails As AiCompletionUsage
'''<Summary>
'''Breakdown of tokens used in the prompt.
'''</Summary>
<DataMember(Name:="prompt_tokens_details")>
Public Overridable Property PromptTokensDetails As AiPromptUsage
End Class
'''<Summary>
'''Chat Completions API (OpenAI-Compatible)
'''</Summary>
<DataContract>
Public Partial Class ChatCompletion
Implements IPost
'''<Summary>
'''The messages to generate chat completions for.
'''</Summary>
<DataMember(Name:="messages")>
Public Overridable Property Messages As List(Of AiMessage) = New List(Of AiMessage)
'''<Summary>
'''ID of the model to use. See the model endpoint compatibility table for details on which models work with the Chat API
'''</Summary>
<DataMember(Name:="model")>
Public Overridable Property Model As String
'''<Summary>
'''Parameters for audio output. Required when audio output is requested with modalities: [audio]
'''</Summary>
<DataMember(Name:="audio")>
Public Overridable Property Audio As AiChatAudio
'''<Summary>
'''Modify the likelihood of specified tokens appearing in the completion.
'''</Summary>
<DataMember(Name:="logit_bias")>
Public Overridable Property LogitBias As Dictionary(Of Integer, Integer)
'''<Summary>
'''Set 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.
'''</Summary>
<DataMember(Name:="metadata")>
Public Overridable Property Metadata As Dictionary(Of String, String)
'''<Summary>
'''Constrains 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.
'''</Summary>
<DataMember(Name:="reasoning_effort")>
Public Overridable Property ReasoningEffort As String
'''<Summary>
'''An 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.
'''</Summary>
<DataMember(Name:="response_format")>
Public Overridable Property ResponseFormat As AiResponseFormat
'''<Summary>
'''Specifies the processing type used for serving the request.
'''</Summary>
<DataMember(Name:="service_tier")>
Public Overridable Property ServiceTier As String
'''<Summary>
'''A 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.
'''</Summary>
<DataMember(Name:="safety_identifier")>
Public Overridable Property SafetyIdentifier As String
'''<Summary>
'''Up to 4 sequences where the API will stop generating further tokens.
'''</Summary>
<DataMember(Name:="stop")>
Public Overridable Property [Stop] As List(Of String)
'''<Summary>
'''Output types that you would like the model to generate. Most models are capable of generating text, which is the default:
'''</Summary>
<DataMember(Name:="modalities")>
Public Overridable Property Modalities As List(Of String)
'''<Summary>
'''Used by OpenAI to cache responses for similar requests to optimize your cache hit rates.
'''</Summary>
<DataMember(Name:="prompt_cache_key")>
Public Overridable Property PromptCacheKey As String
'''<Summary>
'''A 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.
'''</Summary>
<DataMember(Name:="tools")>
Public Overridable Property Tools As List(Of Tool)
'''<Summary>
'''Constrains 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.
'''</Summary>
<DataMember(Name:="verbosity")>
Public Overridable Property Verbosity As String
'''<Summary>
'''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.
'''</Summary>
<DataMember(Name:="temperature")>
Public Overridable Property Temperature As Double?
'''<Summary>
'''An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
'''</Summary>
<DataMember(Name:="max_completion_tokens")>
Public Overridable Property MaxCompletionTokens As Integer?
'''<Summary>
'''An 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.
'''</Summary>
<DataMember(Name:="top_logprobs")>
Public Overridable Property TopLogprobs As Integer?
'''<Summary>
'''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.
'''</Summary>
<DataMember(Name:="top_p")>
Public Overridable Property TopP As Double?
'''<Summary>
'''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.
'''</Summary>
<DataMember(Name:="frequency_penalty")>
Public Overridable Property FrequencyPenalty As Double?
'''<Summary>
'''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.
'''</Summary>
<DataMember(Name:="presence_penalty")>
Public Overridable Property PresencePenalty As Double?
'''<Summary>
'''This 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.
'''</Summary>
<DataMember(Name:="seed")>
Public Overridable Property Seed As Integer?
'''<Summary>
'''How 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.
'''</Summary>
<DataMember(Name:="n")>
Public Overridable Property N As Integer?
'''<Summary>
'''Whether or not to store the output of this chat completion request for use in our model distillation or evals products.
'''</Summary>
<DataMember(Name:="store")>
Public Overridable Property Store As Boolean?
'''<Summary>
'''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.
'''</Summary>
<DataMember(Name:="logprobs")>
Public Overridable Property Logprobs As Boolean?
'''<Summary>
'''Whether to enable parallel function calling during tool use.
'''</Summary>
<DataMember(Name:="parallel_tool_calls")>
Public Overridable Property ParallelToolCalls As Boolean?
'''<Summary>
'''Whether to enable thinking mode for some Qwen models and providers.
'''</Summary>
<DataMember(Name:="enable_thinking")>
Public Overridable Property EnableThinking As Boolean?
'''<Summary>
'''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]` message.
'''</Summary>
<DataMember(Name:="stream")>
Public Overridable Property Stream As Boolean?
End Class
<DataContract>
Public Partial Class ChatResponse
'''<Summary>
'''A unique identifier for the chat completion.
'''</Summary>
<DataMember(Name:="id")>
Public Overridable Property Id As String
'''<Summary>
'''A list of chat completion choices. Can be more than one if n is greater than 1.
'''</Summary>
<DataMember(Name:="choices")>
Public Overridable Property Choices As List(Of Choice) = New List(Of Choice)
'''<Summary>
'''The Unix timestamp (in seconds) of when the chat completion was created.
'''</Summary>
<DataMember(Name:="created")>
Public Overridable Property Created As Long
'''<Summary>
'''The model used for the chat completion.
'''</Summary>
<DataMember(Name:="model")>
Public Overridable Property Model As String
'''<Summary>
'''This fingerprint represents the backend configuration that the model runs with.
'''</Summary>
<DataMember(Name:="system_fingerprint")>
Public Overridable Property SystemFingerprint As String
'''<Summary>
'''The object type, which is always chat.completion.
'''</Summary>
<DataMember(Name:="object")>
Public Overridable Property [Object] As String
'''<Summary>
'''Specifies the processing type used for serving the request.
'''</Summary>
<DataMember(Name:="service_tier")>
Public Overridable Property ServiceTier As String
'''<Summary>
'''Usage statistics for the completion request.
'''</Summary>
<DataMember(Name:="usage")>
Public Overridable Property Usage As AiUsage
'''<Summary>
'''The provider used for the chat completion.
'''</Summary>
<DataMember(Name:="provider")>
Public Overridable Property Provider As String
'''<Summary>
'''Set 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.
'''</Summary>
<DataMember(Name:="metadata")>
Public Overridable Property Metadata As Dictionary(Of String, String)
<DataMember(Name:="responseStatus")>
Public Overridable Property ResponseStatus As ResponseStatus
End Class
<DataContract>
Public Partial Class Choice
'''<Summary>
'''The 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
'''</Summary>
<DataMember(Name:="finish_reason")>
Public Overridable Property FinishReason As String
'''<Summary>
'''The index of the choice in the list of choices.
'''</Summary>
<DataMember(Name:="index")>
Public Overridable Property Index As Integer
'''<Summary>
'''A chat completion message generated by the model.
'''</Summary>
<DataMember(Name:="message")>
Public Overridable Property Message As ChoiceMessage
End Class
'''<Summary>
'''Annotations for the message, when applicable, as when using the web search tool.
'''</Summary>
<DataContract>
Public Partial Class ChoiceAnnotation
'''<Summary>
'''The type of the URL citation. Always url_citation.
'''</Summary>
<DataMember(Name:="type")>
Public Overridable Property Type As String
'''<Summary>
'''A URL citation when using web search.
'''</Summary>
<DataMember(Name:="url_citation")>
Public Overridable Property UrlCitation As UrlCitation
End Class
'''<Summary>
'''If the audio output modality is requested, this object contains data about the audio response from the model.
'''</Summary>
<DataContract>
Public Partial Class ChoiceAudio
'''<Summary>
'''Base64 encoded audio bytes generated by the model, in the format specified in the request.
'''</Summary>
<DataMember(Name:="data")>
Public Overridable Property Data As String
'''<Summary>
'''The Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.
'''</Summary>
<DataMember(Name:="expires_at")>
Public Overridable Property ExpiresAt As Integer
'''<Summary>
'''Unique identifier for this audio response.
'''</Summary>
<DataMember(Name:="id")>
Public Overridable Property Id As String
'''<Summary>
'''Transcript of the audio generated by the model.
'''</Summary>
<DataMember(Name:="transcript")>
Public Overridable Property Transcript As String
End Class
<DataContract>
Public Partial Class ChoiceMessage
'''<Summary>
'''The contents of the message.
'''</Summary>
<DataMember(Name:="content")>
Public Overridable Property Content As String
'''<Summary>
'''The refusal message generated by the model.
'''</Summary>
<DataMember(Name:="refusal")>
Public Overridable Property Refusal As String
'''<Summary>
'''The reasoning process used by the model.
'''</Summary>
<DataMember(Name:="reasoning")>
Public Overridable Property Reasoning As String
'''<Summary>
'''The role of the author of this message.
'''</Summary>
<DataMember(Name:="role")>
Public Overridable Property Role As String
'''<Summary>
'''Annotations for the message, when applicable, as when using the web search tool.
'''</Summary>
<DataMember(Name:="annotations")>
Public Overridable Property Annotations As List(Of ChoiceAnnotation)
'''<Summary>
'''If the audio output modality is requested, this object contains data about the audio response from the model.
'''</Summary>
<DataMember(Name:="audio")>
Public Overridable Property Audio As ChoiceAudio
'''<Summary>
'''The tool calls generated by the model, such as function calls.
'''</Summary>
<DataMember(Name:="tool_calls")>
Public Overridable Property ToolCalls As List(Of ToolCall)
End Class
Public Enum ResponseFormat
<EnumMember(Value:="text")>
Text
<EnumMember(Value:="json_object")>
JsonObject
End Enum
<DataContract>
Public Partial Class Tool
'''<Summary>
'''The type of the tool. Currently, only function is supported.
'''</Summary>
<DataMember(Name:="type")>
Public Overridable Property Type As ToolType
End Class
'''<Summary>
'''The tool calls generated by the model, such as function calls.
'''</Summary>
<DataContract>
Public Partial Class ToolCall
'''<Summary>
'''The ID of the tool call.
'''</Summary>
<DataMember(Name:="id")>
Public Overridable Property Id As String
'''<Summary>
'''The type of the tool. Currently, only `function` is supported.
'''</Summary>
<DataMember(Name:="type")>
Public Overridable Property Type As String
'''<Summary>
'''The function that the model called.
'''</Summary>
<DataMember(Name:="function")>
Public Overridable Property [Function] As String
End Class
Public Enum ToolType
<EnumMember(Value:="function")>
[Function]
End Enum
'''<Summary>
'''Annotations for the message, when applicable, as when using the web search tool.
'''</Summary>
<DataContract>
Public Partial Class UrlCitation
'''<Summary>
'''The index of the last character of the URL citation in the message.
'''</Summary>
<DataMember(Name:="end_index")>
Public Overridable Property EndIndex As Integer
'''<Summary>
'''The index of the first character of the URL citation in the message.
'''</Summary>
<DataMember(Name:="start_index")>
Public Overridable Property StartIndex As Integer
'''<Summary>
'''The title of the web resource.
'''</Summary>
<DataMember(Name:="title")>
Public Overridable Property Title As String
'''<Summary>
'''The URL of the web resource.
'''</Summary>
<DataMember(Name:="url")>
Public Overridable Property Url As String
End Class
End Namespace
End Namespace
To override the Content-type in your clients, use the HTTP Accept Header, append the .csv suffix or ?format=csv
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: text/csv
Content-Type: text/csv
Content-Length: length
{"messages":[{"content":[{}],"role":"String","name":"String","tool_calls":[{"id":"String","type":"String","function":"String"}],"tool_call_id":"String"}],"model":"String","audio":{"format":"String","voice":"String"},"logit_bias":{"0":0},"metadata":{"String":"String"},"reasoning_effort":"String","response_format":{"response_format":"text"},"service_tier":"String","safety_identifier":"String","stop":["String"],"modalities":["String"],"prompt_cache_key":"String","tools":[{"type":"function"}],"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: text/csv
Content-Length: length
{"id":"String","choices":[{"finish_reason":"String","index":0,"message":{"content":"String","refusal":"String","reasoning":"String","role":"String","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":"String"}]}}],"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}},"provider":"String","metadata":{"String":"String"},"responseStatus":{"errorCode":"String","message":"String","stackTrace":"String","errors":[{"errorCode":"String","fieldName":"String","message":"String","meta":{"String":"String"}}],"meta":{"String":"String"}}}