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
"use strict";
export class UrlCitation {
    /** @param {{end_index?:number,start_index?:number,title?:string,url?:string}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {number}
     * @description The index of the last character of the URL citation in the message. */
    end_index;
    /**
     * @type {number}
     * @description The index of the first character of the URL citation in the message. */
    start_index;
    /**
     * @type {string}
     * @description The title of the web resource. */
    title;
    /**
     * @type {string}
     * @description The URL of the web resource. */
    url;
}
export class ChoiceAnnotation {
    /** @param {{type?:string,url_citation?:UrlCitation}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {string}
     * @description The type of the URL citation. Always url_citation. */
    type;
    /**
     * @type {UrlCitation}
     * @description A URL citation when using web search. */
    url_citation;
}
export class ChoiceAudio {
    /** @param {{data?:string,expires_at?:number,id?:string,transcript?:string}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {string}
     * @description Base64 encoded audio bytes generated by the model, in the format specified in the request. */
    data;
    /**
     * @type {number}
     * @description The Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations. */
    expires_at;
    /**
     * @type {string}
     * @description Unique identifier for this audio response. */
    id;
    /**
     * @type {string}
     * @description Transcript of the audio generated by the model. */
    transcript;
}
export class ToolCall {
    /** @param {{id?:string,type?:string,function?:string}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {string}
     * @description The ID of the tool call. */
    id;
    /**
     * @type {string}
     * @description The type of the tool. Currently, only `function` is supported. */
    type;
    /**
     * @type {string}
     * @description The function that the model called. */
    function;
}
export class ChoiceMessage {
    /** @param {{content?:string,refusal?:string,reasoning?:string,role?:string,annotations?:ChoiceAnnotation[],audio?:ChoiceAudio,tool_calls?:ToolCall[]}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {string}
     * @description The contents of the message. */
    content;
    /**
     * @type {?string}
     * @description The refusal message generated by the model. */
    refusal;
    /**
     * @type {?string}
     * @description The reasoning process used by the model. */
    reasoning;
    /**
     * @type {string}
     * @description The role of the author of this message. */
    role;
    /**
     * @type {?ChoiceAnnotation[]}
     * @description Annotations for the message, when applicable, as when using the web search tool. */
    annotations;
    /**
     * @type {?ChoiceAudio}
     * @description If the audio output modality is requested, this object contains data about the audio response from the model. */
    audio;
    /**
     * @type {?ToolCall[]}
     * @description The tool calls generated by the model, such as function calls. */
    tool_calls;
}
export class Choice {
    /** @param {{finish_reason?:string,index?:number,message?:ChoiceMessage}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {string}
     * @description 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 */
    finish_reason;
    /**
     * @type {number}
     * @description The index of the choice in the list of choices. */
    index;
    /**
     * @type {ChoiceMessage}
     * @description A chat completion message generated by the model. */
    message;
}
export class AiCompletionUsage {
    /** @param {{accepted_prediction_tokens?:number,audio_tokens?:number,reasoning_tokens?:number,rejected_prediction_tokens?:number}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {number}
     * @description When using Predicted Outputs, the number of tokens in the prediction that appeared in the completion.

 */
    accepted_prediction_tokens;
    /**
     * @type {number}
     * @description Audio input tokens generated by the model. */
    audio_tokens;
    /**
     * @type {number}
     * @description Tokens generated by the model for reasoning. */
    reasoning_tokens;
    /**
     * @type {number}
     * @description When using Predicted Outputs, the number of tokens in the prediction that did not appear in the completion. */
    rejected_prediction_tokens;
}
export class AiPromptUsage {
    /** @param {{accepted_prediction_tokens?:number,audio_tokens?:number,cached_tokens?:number}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {number}
     * @description When using Predicted Outputs, the number of tokens in the prediction that appeared in the completion.

 */
    accepted_prediction_tokens;
    /**
     * @type {number}
     * @description Audio input tokens present in the prompt. */
    audio_tokens;
    /**
     * @type {number}
     * @description Cached tokens present in the prompt. */
    cached_tokens;
}
export class AiUsage {
    /** @param {{completion_tokens?:number,prompt_tokens?:number,total_tokens?:number,completion_tokens_details?:AiCompletionUsage,prompt_tokens_details?:AiPromptUsage}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {number}
     * @description Number of tokens in the generated completion. */
    completion_tokens;
    /**
     * @type {number}
     * @description Number of tokens in the prompt. */
    prompt_tokens;
    /**
     * @type {number}
     * @description Total number of tokens used in the request (prompt + completion). */
    total_tokens;
    /**
     * @type {?AiCompletionUsage}
     * @description Breakdown of tokens used in a completion. */
    completion_tokens_details;
    /**
     * @type {?AiPromptUsage}
     * @description Breakdown of tokens used in the prompt. */
    prompt_tokens_details;
}
export class ChatResponse {
    /** @param {{id?:string,choices?:Choice[],created?:number,model?:string,system_fingerprint?:string,object?:string,service_tier?:string,usage?:AiUsage,provider?:string,metadata?:{ [index:string]: string; },responseStatus?:ResponseStatus}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {string}
     * @description A unique identifier for the chat completion. */
    id;
    /**
     * @type {Choice[]}
     * @description A list of chat completion choices. Can be more than one if n is greater than 1. */
    choices = [];
    /**
     * @type {number}
     * @description The Unix timestamp (in seconds) of when the chat completion was created. */
    created;
    /**
     * @type {string}
     * @description The model used for the chat completion. */
    model;
    /**
     * @type {?string}
     * @description This fingerprint represents the backend configuration that the model runs with. */
    system_fingerprint;
    /**
     * @type {string}
     * @description The object type, which is always chat.completion. */
    object;
    /**
     * @type {?string}
     * @description Specifies the processing type used for serving the request. */
    service_tier;
    /**
     * @type {AiUsage}
     * @description Usage statistics for the completion request. */
    usage;
    /**
     * @type {?string}
     * @description The provider used for the chat completion. */
    provider;
    /**
     * @type {?{ [index:string]: string; }}
     * @description 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. */
    metadata;
    /** @type {?ResponseStatus} */
    responseStatus;
}
export class AiContent {
    /** @param {{type?:string}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {string}
     * @description The type of the content part. */
    type;
}
export class AiMessage {
    /** @param {{content?:AiContent[],role?:string,name?:string,tool_calls?:ToolCall[],tool_call_id?:string}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {?AiContent[]}
     * @description The contents of the message. */
    content;
    /**
     * @type {string}
     * @description The role of the author of this message. Valid values are `system`, `user`, `assistant` and `tool`. */
    role;
    /**
     * @type {?string}
     * @description An optional name for the participant. Provides the model information to differentiate between participants of the same role. */
    name;
    /**
     * @type {?ToolCall[]}
     * @description The tool calls generated by the model, such as function calls. */
    tool_calls;
    /**
     * @type {?string}
     * @description Tool call that this message is responding to. */
    tool_call_id;
}
export class AiChatAudio {
    /** @param {{format?:string,voice?:string}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {string}
     * @description Specifies the output audio format. Must be one of wav, mp3, flac, opus, or pcm16. */
    format;
    /**
     * @type {string}
     * @description The voice the model uses to respond. Supported voices are alloy, ash, ballad, coral, echo, fable, nova, onyx, sage, and shimmer. */
    voice;
}
/** @typedef {'text'|'json_object'} */
export var ResponseFormat;
(function (ResponseFormat) {
    ResponseFormat["Text"] = "text"
    ResponseFormat["JsonObject"] = "json_object"
})(ResponseFormat || (ResponseFormat = {}));
export class AiResponseFormat {
    /** @param {{response_format?:ResponseFormat}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {ResponseFormat}
     * @description 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. */
    response_format;
}
/** @typedef {'function'} */
export var ToolType;
(function (ToolType) {
    ToolType["Function"] = "function"
})(ToolType || (ToolType = {}));
export class Tool {
    /** @param {{type?:ToolType}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {ToolType}
     * @description The type of the tool. Currently, only function is supported. */
    type;
}
export class ChatCompletion {
    /** @param {{messages?:AiMessage[],model?:string,audio?:AiChatAudio,logit_bias?:{ [index:number]: number; },metadata?:{ [index:string]: string; },reasoning_effort?:string,response_format?:AiResponseFormat,service_tier?:string,safety_identifier?:string,stop?:string[],modalities?:string[],prompt_cache_key?:string,tools?:Tool[],verbosity?:string,temperature?:number,max_completion_tokens?:number,top_logprobs?:number,top_p?:number,frequency_penalty?:number,presence_penalty?:number,seed?:number,n?:number,store?:boolean,logprobs?:boolean,parallel_tool_calls?:boolean,enable_thinking?:boolean,stream?:boolean}} [init] */
    constructor(init) { Object.assign(this, init) }
    /**
     * @type {AiMessage[]}
     * @description The messages to generate chat completions for. */
    messages = [];
    /**
     * @type {string}
     * @description ID of the model to use. See the model endpoint compatibility table for details on which models work with the Chat API */
    model;
    /**
     * @type {?AiChatAudio}
     * @description Parameters for audio output. Required when audio output is requested with modalities: [audio] */
    audio;
    /**
     * @type {?{ [index:number]: number; }}
     * @description Modify the likelihood of specified tokens appearing in the completion. */
    logit_bias;
    /**
     * @type {?{ [index:string]: string; }}
     * @description 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. */
    metadata;
    /**
     * @type {?string}
     * @description 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. */
    reasoning_effort;
    /**
     * @type {?AiResponseFormat}
     * @description 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. */
    response_format;
    /**
     * @type {?string}
     * @description Specifies the processing type used for serving the request. */
    service_tier;
    /**
     * @type {?string}
     * @description 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. */
    safety_identifier;
    /**
     * @type {?string[]}
     * @description Up to 4 sequences where the API will stop generating further tokens. */
    stop;
    /**
     * @type {?string[]}
     * @description Output types that you would like the model to generate. Most models are capable of generating text, which is the default: */
    modalities;
    /**
     * @type {?string}
     * @description Used by OpenAI to cache responses for similar requests to optimize your cache hit rates. */
    prompt_cache_key;
    /**
     * @type {?Tool[]}
     * @description 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. */
    tools;
    /**
     * @type {?string}
     * @description 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. */
    verbosity;
    /**
     * @type {?number}
     * @description 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. */
    temperature;
    /**
     * @type {?number}
     * @description An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens. */
    max_completion_tokens;
    /**
     * @type {?number}
     * @description 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. */
    top_logprobs;
    /**
     * @type {?number}
     * @description 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. */
    top_p;
    /**
     * @type {?number}
     * @description 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. */
    frequency_penalty;
    /**
     * @type {?number}
     * @description 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. */
    presence_penalty;
    /**
     * @type {?number}
     * @description 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. */
    seed;
    /**
     * @type {?number}
     * @description 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. */
    n;
    /**
     * @type {?boolean}
     * @description Whether or not to store the output of this chat completion request for use in our model distillation or evals products. */
    store;
    /**
     * @type {?boolean}
     * @description 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. */
    logprobs;
    /**
     * @type {?boolean}
     * @description Whether to enable parallel function calling during tool use. */
    parallel_tool_calls;
    /**
     * @type {?boolean}
     * @description Whether to enable thinking mode for some Qwen models and providers. */
    enable_thinking;
    /**
     * @type {?boolean}
     * @description 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. */
    stream;
}

JavaScript ChatCompletion DTOs

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":"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: application/json
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"}}}