Create a chat completion
curl --request POST \
--url http://localhost:9000/v1/chat/completions \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "system",
"content": "<string>"
}
],
"model": "<string>",
"temperature": 1,
"top_p": 1,
"stream": false
}
'import requests
url = "http://localhost:9000/v1/chat/completions"
payload = {
"messages": [
{
"role": "system",
"content": "<string>"
}
],
"model": "<string>",
"temperature": 1,
"top_p": 1,
"stream": False
}
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({
messages: [{role: 'system', content: '<string>'}],
model: '<string>',
temperature: 1,
top_p: 1,
stream: false
})
};
fetch('http://localhost:9000/v1/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_PORT => "9000",
CURLOPT_URL => "http://localhost:9000/v1/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([
'messages' => [
[
'role' => 'system',
'content' => '<string>'
]
],
'model' => '<string>',
'temperature' => 1,
'top_p' => 1,
'stream' => false
]),
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 := "http://localhost:9000/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 1,\n \"top_p\": 1,\n \"stream\": false\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("http://localhost:9000/v1/chat/completions")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 1,\n \"top_p\": 1,\n \"stream\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:9000/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 1,\n \"top_p\": 1,\n \"stream\": false\n}"
response = http.request(request)
puts response.read_body{
"object": "chat.completion",
"choices": [
{
"index": 123,
"message": {
"role": "assistant",
"content": "<string>"
},
"finish_reason": "stop"
}
],
"id": "<string>",
"created": 123,
"model": "<string>",
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}Endpoint Examples
/v1/chat/completions
Creates a completion for the chat message
POST
/
v1
/
chat
/
completions
Create a chat completion
curl --request POST \
--url http://localhost:9000/v1/chat/completions \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "system",
"content": "<string>"
}
],
"model": "<string>",
"temperature": 1,
"top_p": 1,
"stream": false
}
'import requests
url = "http://localhost:9000/v1/chat/completions"
payload = {
"messages": [
{
"role": "system",
"content": "<string>"
}
],
"model": "<string>",
"temperature": 1,
"top_p": 1,
"stream": False
}
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({
messages: [{role: 'system', content: '<string>'}],
model: '<string>',
temperature: 1,
top_p: 1,
stream: false
})
};
fetch('http://localhost:9000/v1/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_PORT => "9000",
CURLOPT_URL => "http://localhost:9000/v1/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([
'messages' => [
[
'role' => 'system',
'content' => '<string>'
]
],
'model' => '<string>',
'temperature' => 1,
'top_p' => 1,
'stream' => false
]),
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 := "http://localhost:9000/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 1,\n \"top_p\": 1,\n \"stream\": false\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("http://localhost:9000/v1/chat/completions")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 1,\n \"top_p\": 1,\n \"stream\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:9000/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 1,\n \"top_p\": 1,\n \"stream\": false\n}"
response = http.request(request)
puts response.read_body{
"object": "chat.completion",
"choices": [
{
"index": 123,
"message": {
"role": "assistant",
"content": "<string>"
},
"finish_reason": "stop"
}
],
"id": "<string>",
"created": 123,
"model": "<string>",
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}Body
application/json
A list of messages comprising the conversation so far.
- Option 1
- Option 2
- Option 3
Show child attributes
Show child attributes
ID of the model to use.
What sampling temperature to use, between 0 and 2.
Required range:
0 <= x <= 2An alternative to sampling with temperature, called nucleus sampling
Required range:
0 <= x <= 1If set, partial message deltas will be sent.
Response
200 - application/json
OK
Represents a chat completion response returned by model, based on the provided input.
The object type, which is always "chat.completion"
Available options:
chat.completion A list of chat completion choices.
Show child attributes
Show child attributes
A unique identifier for the chat completion.
The Unix timestamp (in seconds) of when the chat completion was created.
The model used for the chat completion.
Show child attributes
Show child attributes
⌘I
