curl --request POST \
--url https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions \
--header 'Content-Type: application/json' \
--data '
{
"chat_history": [
{
"content": "<string>",
"role": "user"
}
],
"prompt": "<string>",
"model_request_parameters": {
"bindings": {}
},
"temperature": 0.2,
"stop_sequences": [
"<string>"
],
"max_tokens": 123,
"top_p": 123,
"top_k": 123,
"frequency_penalty": 123,
"presence_penalty": 123,
"stream": false,
"logprobs": true,
"top_logprobs": 123,
"chat_template": "<string>",
"chat_template_kwargs": {}
}
'import requests
url = "https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions"
payload = {
"chat_history": [
{
"content": "<string>",
"role": "user"
}
],
"prompt": "<string>",
"model_request_parameters": { "bindings": {} },
"temperature": 0.2,
"stop_sequences": ["<string>"],
"max_tokens": 123,
"top_p": 123,
"top_k": 123,
"frequency_penalty": 123,
"presence_penalty": 123,
"stream": False,
"logprobs": True,
"top_logprobs": 123,
"chat_template": "<string>",
"chat_template_kwargs": {}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
chat_history: [{content: '<string>', role: 'user'}],
prompt: '<string>',
model_request_parameters: {bindings: {}},
temperature: 0.2,
stop_sequences: ['<string>'],
max_tokens: 123,
top_p: 123,
top_k: 123,
frequency_penalty: 123,
presence_penalty: 123,
stream: false,
logprobs: true,
top_logprobs: 123,
chat_template: '<string>',
chat_template_kwargs: {}
})
};
fetch('https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'chat_history' => [
[
'content' => '<string>',
'role' => 'user'
]
],
'prompt' => '<string>',
'model_request_parameters' => [
'bindings' => [
]
],
'temperature' => 0.2,
'stop_sequences' => [
'<string>'
],
'max_tokens' => 123,
'top_p' => 123,
'top_k' => 123,
'frequency_penalty' => 123,
'presence_penalty' => 123,
'stream' => false,
'logprobs' => true,
'top_logprobs' => 123,
'chat_template' => '<string>',
'chat_template_kwargs' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions"
payload := strings.NewReader("{\n \"chat_history\": [\n {\n \"content\": \"<string>\",\n \"role\": \"user\"\n }\n ],\n \"prompt\": \"<string>\",\n \"model_request_parameters\": {\n \"bindings\": {}\n },\n \"temperature\": 0.2,\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"max_tokens\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"stream\": false,\n \"logprobs\": true,\n \"top_logprobs\": 123,\n \"chat_template\": \"<string>\",\n \"chat_template_kwargs\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions")
.header("Content-Type", "application/json")
.body("{\n \"chat_history\": [\n {\n \"content\": \"<string>\",\n \"role\": \"user\"\n }\n ],\n \"prompt\": \"<string>\",\n \"model_request_parameters\": {\n \"bindings\": {}\n },\n \"temperature\": 0.2,\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"max_tokens\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"stream\": false,\n \"logprobs\": true,\n \"top_logprobs\": 123,\n \"chat_template\": \"<string>\",\n \"chat_template_kwargs\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"chat_history\": [\n {\n \"content\": \"<string>\",\n \"role\": \"user\"\n }\n ],\n \"prompt\": \"<string>\",\n \"model_request_parameters\": {\n \"bindings\": {}\n },\n \"temperature\": 0.2,\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"max_tokens\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"stream\": false,\n \"logprobs\": true,\n \"top_logprobs\": 123,\n \"chat_template\": \"<string>\",\n \"chat_template_kwargs\": {}\n}"
response = http.request(request)
puts response.read_body{
"completions": [
[
"<string>",
[
"<string>"
]
]
],
"finish_reason": "<string>",
"prompt_tokens": 0,
"response_tokens": 0,
"choices": [
{
"index": 123,
"logprobs": {
"content": [
{
"token": "<string>",
"logprob": 123,
"top_logprobs": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
],
"bytes": [
123
]
}
]
}
}
]
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Generate chat completion
Description
Interact with the LLM model using the specified model_deployment_id. You can include a list of messages as the conversation history. The conversation can feature multiple messages from the roles user, assistant, and system. If the chosen model does not support chat completion, the API will revert to simple completion, disregarding the provided history. The endpoint manages context length exceedance optimistically: it estimates the token count from the provided history and prompt, and if it exceeds the context or approaches 80% of it, the exact token count will be calculated, and the history will be trimmed to fit the context.
{
"prompt": "Generate 5 more",
"chat_history": [
{ "role": "system", "content": "You are a name generator. Do not generate anything else than names" },
{ "role": "user", "content": "Generate 5 names" },
{ "role": "assistant", "content": "1. Olivia Bennett\n2. Ethan Carter\n3. Sophia Ramirez\n4. Liam Thompson\n5. Ava Mitchell" }
],
}
curl --request POST \
--url https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions \
--header 'Content-Type: application/json' \
--data '
{
"chat_history": [
{
"content": "<string>",
"role": "user"
}
],
"prompt": "<string>",
"model_request_parameters": {
"bindings": {}
},
"temperature": 0.2,
"stop_sequences": [
"<string>"
],
"max_tokens": 123,
"top_p": 123,
"top_k": 123,
"frequency_penalty": 123,
"presence_penalty": 123,
"stream": false,
"logprobs": true,
"top_logprobs": 123,
"chat_template": "<string>",
"chat_template_kwargs": {}
}
'import requests
url = "https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions"
payload = {
"chat_history": [
{
"content": "<string>",
"role": "user"
}
],
"prompt": "<string>",
"model_request_parameters": { "bindings": {} },
"temperature": 0.2,
"stop_sequences": ["<string>"],
"max_tokens": 123,
"top_p": 123,
"top_k": 123,
"frequency_penalty": 123,
"presence_penalty": 123,
"stream": False,
"logprobs": True,
"top_logprobs": 123,
"chat_template": "<string>",
"chat_template_kwargs": {}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
chat_history: [{content: '<string>', role: 'user'}],
prompt: '<string>',
model_request_parameters: {bindings: {}},
temperature: 0.2,
stop_sequences: ['<string>'],
max_tokens: 123,
top_p: 123,
top_k: 123,
frequency_penalty: 123,
presence_penalty: 123,
stream: false,
logprobs: true,
top_logprobs: 123,
chat_template: '<string>',
chat_template_kwargs: {}
})
};
fetch('https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'chat_history' => [
[
'content' => '<string>',
'role' => 'user'
]
],
'prompt' => '<string>',
'model_request_parameters' => [
'bindings' => [
]
],
'temperature' => 0.2,
'stop_sequences' => [
'<string>'
],
'max_tokens' => 123,
'top_p' => 123,
'top_k' => 123,
'frequency_penalty' => 123,
'presence_penalty' => 123,
'stream' => false,
'logprobs' => true,
'top_logprobs' => 123,
'chat_template' => '<string>',
'chat_template_kwargs' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions"
payload := strings.NewReader("{\n \"chat_history\": [\n {\n \"content\": \"<string>\",\n \"role\": \"user\"\n }\n ],\n \"prompt\": \"<string>\",\n \"model_request_parameters\": {\n \"bindings\": {}\n },\n \"temperature\": 0.2,\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"max_tokens\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"stream\": false,\n \"logprobs\": true,\n \"top_logprobs\": 123,\n \"chat_template\": \"<string>\",\n \"chat_template_kwargs\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions")
.header("Content-Type", "application/json")
.body("{\n \"chat_history\": [\n {\n \"content\": \"<string>\",\n \"role\": \"user\"\n }\n ],\n \"prompt\": \"<string>\",\n \"model_request_parameters\": {\n \"bindings\": {}\n },\n \"temperature\": 0.2,\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"max_tokens\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"stream\": false,\n \"logprobs\": true,\n \"top_logprobs\": 123,\n \"chat_template\": \"<string>\",\n \"chat_template_kwargs\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.egp.scale.com/v4/models/{model_deployment_id}/chat-completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"chat_history\": [\n {\n \"content\": \"<string>\",\n \"role\": \"user\"\n }\n ],\n \"prompt\": \"<string>\",\n \"model_request_parameters\": {\n \"bindings\": {}\n },\n \"temperature\": 0.2,\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"max_tokens\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"stream\": false,\n \"logprobs\": true,\n \"top_logprobs\": 123,\n \"chat_template\": \"<string>\",\n \"chat_template_kwargs\": {}\n}"
response = http.request(request)
puts response.read_body{
"completions": [
[
"<string>",
[
"<string>"
]
]
],
"finish_reason": "<string>",
"prompt_tokens": 0,
"response_tokens": 0,
"choices": [
{
"index": 123,
"logprobs": {
"content": [
{
"token": "<string>",
"logprob": 123,
"top_logprobs": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
],
"bytes": [
123
]
}
]
}
}
]
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Body
Represents a chat completion request.
Attributes: chat_history (List[Message]): Chat history
What sampling temperature to use, between [0, 2]. Higher values like 1.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. Setting temperature=0.0 will enable fully deterministic (greedy) sampling.NOTE: The temperature parameter range for some model is limited to [0, 1] if the given value is above the available range, it defaults to the max value. Temperature is ignored for OpenAI reasoning models.
0 <= x <= 2The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length. If not, specified, max_tokens will be determined based on the model used:
| Model API family | Model API default | EGP applied default |
|---|---|---|
| OpenAI Completions | 16 | context window - prompt size |
| OpenAI Chat Completions | context window - prompt size | context window - prompt size |
| LLM Engine | max_new_tokens parameter is required | 100 |
| Anthropic Claude 2 | max_tokens_to_sample parameter is required | 10000 |