Using OpenAI Chat Completion
Request
URL: https://ai.purlabs.xyz/openai/chat/completions
Request Method: POST
TS Request Interface
⚠️
One of the model and personality fields must be set!
interface Request {
model?: string;
personality?: string;
disableErrorSummarization?: true;
primaryProvider?: string;
messages: {
role: 'system' | 'user' | 'assistant' | 'function';
content: string;
name?: string;
function_call?: object;
}[];
functions?: {
name: string;
description?: string;
parameters: {
type: 'object';
properties: {
[name: string]: {
type: string;
description: string;
};
};
required?: string[];
};
}[];
function_call?: 'none' | 'auto' | {
name: string;
};
temperature?: number;
top_p?: number;
n?: number;
stream?: boolean;
stop?: string | any[] | null;
max_tokens?: number;
presence_penalty?: number;
frequency_penalty?: number;
logit_bias?: object | null;
user?: string;
};Request API Reference
⚠️
Refer to OpenAI's docs (opens in a new tab) to learn more about all the paramters, and functions!
| Parameter | Type (check TS Interface) | Required | Description |
|---|---|---|---|
model | string | Required if no personality | The model you would like to use. Refer to the Getting Available Models page for more information. |
personality | string | Required if no model | Specifies the personality for the conversation. Refer to the Getting Personalities page for more details. |
disableErrorSummarization | boolean | Optional | AI-powered error summarizer: most error messages will be summarized according to the error records (if all providers errored). |
primaryProvider | 'ChimeraGPT' | 'FoxGPT' | ... | Optional | The primary provider to use for generating responses. The API will try this provider first. If it returns with any error(s), the API will try other providers! |
messages | array | Required | A list of messages comprising the conversation so far. |
messages.role | 'system' | 'user' | 'assistant' | 'function' | Required | The role of the message's author. One of system, user, assistant, or function. |
messages.content | string | null | Required | The contents of the message. content is required for all messages, and may be null for assistant messages with function calls. |
messages.name | string | Optional | The name of the author of this message. name is required if role is function, and it should be the name of the function whose response is in the content. May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters. |
messages.function_call | object | Optional | The name and arguments of a function that should be called, as generated by the model. |
messages.function_call.name | string | Required | The name of the function to call. |
messages.function_call.arguments | string | Required | The 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. |
functions | array | Optional | A list of functions the model may generate JSON inputs for. |
functions.name | string | Required | The 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. |
functions.description | string | Optional | A description of what the function does, used by the model to choose when and how to call the function. |
functions.parameters | object | Required | The parameters the functions accept, described as a JSON Schema object. See the OpenAI guide (opens in a new tab). |
function_call | string | object | Optional | Controls how the model responds to function calls. "none" means the model does not call a function, and responds to the end-user. "auto" means the model can pick between an end-user or calling a function. Specifying a particular function via {"name":"my_function"} forces the model to call that function. "none" is the default when no functions are present. "auto" is the default if functions are present. |
temperature | number | null | Optional | Defaults 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. We generally recommend altering this or top_p but not both. |
top_p | number | null | Optional | Defaults 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. |
n | integer | null | Optional | Defaults to 1. How many chat completion choices to generate for each input message. |
stream | boolean | null | Optional | Defaults 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] message. |
stop | string | array | null | Optional | Defaults to null. Up to 4 sequences where the API will stop generating further tokens. |
max_tokens | integer | Optional | Defaults to inf. The maximum number of tokens to generate in the chat completion. |
presence_penalty | number | null | Optional | Defaults 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. |
frequency_penalty | number | null | Optional | Defaults 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_bias | map | Optional | Defaults to null. 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 the likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. |
user | string | Optional | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more (opens in a new tab). |
Example JSON Request Body
{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "Hello! How are you?"
}
]
}Response
TS Response Interface
interface Response {
id: string;
object: 'chat.completion';
created: number;
model: string;
choices: {
index: number;
message: {
role: 'assistant';
content: string;
};
finish_reason: any;
}[];
usage: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
};
overwritten: boolean;
provider: string;
cache?: {
status: 500,
error: {
message: 'Some of our providers returned with errors. Errors are automatically reported to our developers.';
records: {
provider: string;
response: {
status: number;
data?: any;
};
}[];
};
};
calledFunctions: [
{
name: string;
arguments: string;
},
{
role: 'function';
name: string;
content: string;
}
][];
} | {
status: 500,
message: string;
records: {
provider: string;
response: {
status: number;
data?: any;
};
}[];
};Response API Reference
| Property | Type | Description |
|---|---|---|
id | string | The ID of the chat completion response. |
object | 'chat.completion' | The object type of the response. |
created | number | Timestamp of when the response was created. |
model | string | The model used for generating the response. |
choices | array (of objects) | An array of choices containing generated message, index, and finish reason. |
choices.index | number | Index of the choice in the array. |
choices.message | object | The generated message by the assistant. |
choices.message.role | 'assistant' | The role of the generated message (always 'assistant'). |
choices.message.content | string | The content of the generated message. |
choices.finish_reason | any | The reason why the choice was finished. |
usage | object | Usage information about tokens. |
usage.prompt_tokens | number | Number of tokens in the prompt. |
usage.completion_tokens | number | Number of tokens in the completion. |
usage.total_tokens | number | Total number of tokens in the response. |
overwritten | boolean | Indicates if the response was overwritten. |
provider | string | The provider used for generating the response. |
cache | object | (Optional) Cache information. |
cache.status | 500 | Cache status. |
cache.error | object | Cache error details. |
cache.error.message | string | Cache error message. |
cache.error.records | array (of objects) | Records of providers and their error responses. |
cache.error.records.provider | string | Provider that returned an error. |
cache.error.records.response | object | Response details of the provider error. |
cache.error.records.response.status | number | Status code of the provider error response. |
cache.error.records.response.data | any | (Optional) Data associated with the provider error. |
calledFunctions | array (of objects) | Array of called function details. |
calledFunctions[].name | string | Name of the called function. |
calledFunctions[].arguments | string | Arguments of the called function. |
calledFunctions[].role | 'function' | (Optional) Role of the called function (if applicable). |
calledFunctions[].content | string | (Optional) Content of the called function (if applicable). |
status | 500 | Status code indicating an error in the response. |
message | string | Error message. |
records | array (of objects) | Records of providers and their error responses. |
records.provider | string | Provider that returned an error. |
records.response | object | Response details of the provider error. |
records.response.status | number | Status code of the provider error response. |
records.response.data | any | (Optional) Data associated with the provider error. |
Example JSON Response
{
"id": "chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK",
"object": "chat.completion",
"created": 0,
"model": "gpt-3.5-turbo-0301",
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
},
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! As an AI language model, I don't have feelings, but I'm here and ready to assist you. How can I help you today?"
},
"finish_reason": null
}
],
"provider": "Churchless",
"overwritten": false,
"cache": {
"status": 500,
"error": {
"message": "Some of our providers returned with errors. Errors are automatically reported to our developers.",
"records": [
{
"provider": "CattoGPT",
"response": {
"status": 404,
"data": "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <title>Run this Repl to see the results here.</title>\n <link rel=\"stylesheet\"\n href=\"https://fonts.googleapis.com/css?family=IBM+Plex+Sans\">\n <style>\n body {\n margin: 0;\n height: 100vh;\n display: flex;\n justify-content: center;\n align-items: center;\n background: #1c2333;\n font-family: \"IBM Plex Sans\", \"sans\";\n color: #f5f9fc;\n }\n\n .title-box {\n font-size: 12px;\n inline-size: max-content;\n }\n\n .err-box {\n padding: 1em;\n max-width: 30em;\n width: 100vw;\n }\n\n .message {\n display: flex;\n flex-direction: column;\n align-items: center;\n }\n\n @media (max-width: 500px) {\n .message {\n flex-direction: column;\n align-items: center;\n }\n }\n\n .eval-bot {\n margin: 2em;\n }\n\n .console {\n background-color: #0e1628;\n color: #fff;\n font-family: \"IBM Plex Sans\", \"sans\";\n padding: 1em;\n margin: 1em;\n }\n\n .footer {\n margin: 1em;\n display: flex;\n justify-content: center;\n align-items: center;\n }\n\n .link-icon {\n margin-right: 20px;\n margin-top: 4px;\n }\n\n a {\n color: #c2c8cc;\n }\n </style>\n\n <script>\n var reload_timeout = setTimeout(function () {\n window.location.reload();\n }, 60000);\n </script>\n </head>\n\n <body>\n <div class=\"err-box\">\n <div class=\"message\">\n <div class=\"eval-bot\">\n <svg\n width=\"290\"\n height=\"147\"\n viewBox=\"0 0 290 147\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n d=\"M286.619 23.7207C289.534 27.4209 290.848 32.8497 287.611 40.7404C278.97 61.797 266.814 96.0691 266.814 96.0691C266.814 96.0691 263.84 110.374 247.366 110.374H81.9192L69.2234 94.1967L269.605 4.86339L273.294 6.84472L286.619 23.7207Z\"\n fill=\"#006D21\"\n />\n <path\n d=\"M69.2235 94.1967H234.671C251.144 94.1967 254.119 79.8915 254.119 79.8915C254.119 79.8915 266.274 45.6144 274.939 24.5628C283.605 3.51112 259.815 0.00416558 259.815 0.00416558H90.7234C90.7234 0.00416558 78.9745 -0.669489 71.2757 15.1168C63.5769 30.903 55.0652 58.8398 55.0652 58.8398L69.2235 94.1967Z\"\n fill=\"#77EA94\"\n />\n <path\n d=\"M143.619 64.4024L163.245 20.5902L194.308 48.5716L143.619 64.4024Z\"\n fill=\"#006D21\"\n />\n <path\n d=\"M117.935 55.9471L130.541 50.9095L117.751 94.4543V110.285H91.824L117.935 55.9471Z\"\n fill=\"#1D2332\"\n />\n <path\n d=\"M130.105 13.9131L129.406 36.1585L90.5153 119.825L91.2093 97.5798L130.105 13.9131Z\"\n fill=\"#283DC9\"\n />\n <path\n d=\"M29.6288 88.4013L45.4974 75.1214L18.3954 61.8118L130.105 13.9131L91.2093 97.5798L67.4734 85.9197L26.3768 124.244L1.69403 111.786L29.6288 88.4013Z\"\n fill=\"#5162F6\"\n />\n <path\n d=\"M91.2093 97.5798L90.5153 119.825L66.7794 108.165L67.4734 85.9197L91.2093 97.5798Z\"\n fill=\"#162DA3\"\n />\n <path\n d=\"M67.4734 85.9197L66.7794 108.165L25.6828 146.489L26.3768 124.244L67.4734 85.9197Z\"\n fill=\"#283DC9\"\n />\n <path\n d=\"M26.3768 124.244L25.6828 146.489L1 134.031L1.69403 111.786L26.3768 124.244Z\"\n fill=\"#162DA3\"\n />\n <path\n d=\"M45.4974 75.1214L29.6288 88.4013L20.3486 83.1211L18.3954 61.8118L45.4974 75.1214Z\"\n fill=\"#162DA3\"\n />\n <path\n d=\"M130.105 13.9131L18.3954 61.8118L45.4974 75.1214L29.6288 88.4013L1.69403 111.786L26.3768 124.244L67.4734 85.9197L91.2093 97.5798L130.105 13.9131Z\"\n stroke=\"#1D2332\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n <path\n d=\"M130.105 13.9131L129.406 36.1585L90.5153 119.825L66.7794 108.165L25.6828 146.489L1 134.031L1.69403 111.786\"\n stroke=\"#1D2332\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n <path\n d=\"M18.3954 61.8118L20.3486 83.1211L29.6288 88.4013L29.6586 88.4211\"\n stroke=\"#1D2332\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n <path\n d=\"M66.7794 108.165L67.4734 85.9197\"\n stroke=\"#1D2332\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n <path\n d=\"M91.2093 97.5798L90.5153 119.825\"\n stroke=\"#1D2332\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n <path\n d=\"M26.3768 124.244L25.6828 146.489\"\n stroke=\"#1D2332\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n </svg>\n </div>\n <div class=\"title-box\">\n <h1>Run this Repl to see the results here.</h1>\n </div>\n </div>\n <div class=\"footer\">\n <div class=\"link-icon\">\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n d=\"M6.66668 8.66666C6.95298 9.04942 7.31825 9.36612 7.73771 9.59529C8.15717 9.82446 8.62102 9.96074 9.09778 9.99489C9.57454 10.029 10.0531 9.96024 10.5009 9.79319C10.9487 9.62613 11.3554 9.36471 11.6933 9.02666L13.6933 7.02666C14.3005 6.39799 14.6365 5.55598 14.6289 4.68199C14.6213 3.808 14.2708 2.97196 13.6527 2.35394C13.0347 1.73591 12.1987 1.38535 11.3247 1.37775C10.4507 1.37016 9.60869 1.70614 8.98001 2.31333L7.83334 3.45333M9.33334 7.33333C9.04704 6.95058 8.68177 6.63388 8.26231 6.4047C7.84285 6.17553 7.37901 6.03925 6.90224 6.00511C6.42548 5.97096 5.94695 6.03975 5.49911 6.20681C5.05128 6.37387 4.6446 6.63528 4.30668 6.97333L2.30668 8.97333C1.69948 9.602 1.3635 10.444 1.3711 11.318C1.37869 12.192 1.72926 13.028 2.34728 13.6461C2.96531 14.2641 3.80135 14.6147 4.67534 14.6222C5.54933 14.6298 6.39134 14.2939 7.02001 13.6867L8.16001 12.5467\"\n stroke=\"#C2C8CC\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n </svg>\n </div>\n <div class=\"repl-links\">\n <a href=\"https://replit.com\">Go to Replit</a>\n </div>\n <div></div>\n </div>\n </div>\n </body>\n</html>\n"
}
},
{
"provider": "FoxGPT",
"response": {
"status": 403,
"data": "<!doctype html>\n<html lang=en>\n<title>403 Forbidden</title>\n<h1>Forbidden</h1>\n<p>You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.</p>\n"
}
},
{
"provider": "Pawan",
"response": {
"status": 504,
"data": "timeout of 60000ms exceeded"
}
}
]
}
}
}