Generate chat completion
curl --request POST \
--url https://api.example.com/api/v1/chat/completions \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"content": "<string>",
"role": "<string>",
"name": "<string>",
"completion_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"metadata": "<unknown>"
}
],
"model": "<string>",
"stop": [
"<string>"
],
"max_tokens": 1,
"temperature": 123,
"top_p": 123,
"max_ttft_ms": 1,
"stream": true,
"stream_options": {
"include_usage": true
},
"session_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"user": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"ab_campaign": "76d1fab3-214c-47ef-bb04-16270639bf89",
"n": 1,
"labels": {
"key": "value"
},
"metadata": {
"key": "value"
},
"system_prompt_args": {},
"tags": [
"<string>"
],
"use_tools": true,
"tools": [
{
"id": "<string>",
"enabled": true
}
],
"store": true
}
'import requests
url = "https://api.example.com/api/v1/chat/completions"
payload = {
"messages": [
{
"content": "<string>",
"role": "<string>",
"name": "<string>",
"completion_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"metadata": "<unknown>"
}
],
"model": "<string>",
"stop": ["<string>"],
"max_tokens": 1,
"temperature": 123,
"top_p": 123,
"max_ttft_ms": 1,
"stream": True,
"stream_options": { "include_usage": True },
"session_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"user": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"ab_campaign": "76d1fab3-214c-47ef-bb04-16270639bf89",
"n": 1,
"labels": { "key": "value" },
"metadata": { "key": "value" },
"system_prompt_args": {},
"tags": ["<string>"],
"use_tools": True,
"tools": [
{
"id": "<string>",
"enabled": True
}
],
"store": True
}
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: [
{
content: '<string>',
role: '<string>',
name: '<string>',
completion_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
metadata: '<unknown>'
}
],
model: '<string>',
stop: ['<string>'],
max_tokens: 1,
temperature: 123,
top_p: 123,
max_ttft_ms: 1,
stream: true,
stream_options: {include_usage: true},
session_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
user: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
ab_campaign: '76d1fab3-214c-47ef-bb04-16270639bf89',
n: 1,
labels: {key: 'value'},
metadata: {key: 'value'},
system_prompt_args: {},
tags: ['<string>'],
use_tools: true,
tools: [{id: '<string>', enabled: true}],
store: true
})
};
fetch('https://api.example.com/api/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_URL => "https://api.example.com/api/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' => [
[
'content' => '<string>',
'role' => '<string>',
'name' => '<string>',
'completion_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'metadata' => '<unknown>'
]
],
'model' => '<string>',
'stop' => [
'<string>'
],
'max_tokens' => 1,
'temperature' => 123,
'top_p' => 123,
'max_ttft_ms' => 1,
'stream' => true,
'stream_options' => [
'include_usage' => true
],
'session_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'user' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'ab_campaign' => '76d1fab3-214c-47ef-bb04-16270639bf89',
'n' => 1,
'labels' => [
'key' => 'value'
],
'metadata' => [
'key' => 'value'
],
'system_prompt_args' => [
],
'tags' => [
'<string>'
],
'use_tools' => true,
'tools' => [
[
'id' => '<string>',
'enabled' => true
]
],
'store' => true
]),
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.example.com/api/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"role\": \"<string>\",\n \"name\": \"<string>\",\n \"completion_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"metadata\": \"<unknown>\"\n }\n ],\n \"model\": \"<string>\",\n \"stop\": [\n \"<string>\"\n ],\n \"max_tokens\": 1,\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_ttft_ms\": 1,\n \"stream\": true,\n \"stream_options\": {\n \"include_usage\": true\n },\n \"session_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"user\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"ab_campaign\": \"76d1fab3-214c-47ef-bb04-16270639bf89\",\n \"n\": 1,\n \"labels\": {\n \"key\": \"value\"\n },\n \"metadata\": {\n \"key\": \"value\"\n },\n \"system_prompt_args\": {},\n \"tags\": [\n \"<string>\"\n ],\n \"use_tools\": true,\n \"tools\": [\n {\n \"id\": \"<string>\",\n \"enabled\": true\n }\n ],\n \"store\": true\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.example.com/api/v1/chat/completions")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"role\": \"<string>\",\n \"name\": \"<string>\",\n \"completion_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"metadata\": \"<unknown>\"\n }\n ],\n \"model\": \"<string>\",\n \"stop\": [\n \"<string>\"\n ],\n \"max_tokens\": 1,\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_ttft_ms\": 1,\n \"stream\": true,\n \"stream_options\": {\n \"include_usage\": true\n },\n \"session_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"user\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"ab_campaign\": \"76d1fab3-214c-47ef-bb04-16270639bf89\",\n \"n\": 1,\n \"labels\": {\n \"key\": \"value\"\n },\n \"metadata\": {\n \"key\": \"value\"\n },\n \"system_prompt_args\": {},\n \"tags\": [\n \"<string>\"\n ],\n \"use_tools\": true,\n \"tools\": [\n {\n \"id\": \"<string>\",\n \"enabled\": true\n }\n ],\n \"store\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/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 \"messages\": [\n {\n \"content\": \"<string>\",\n \"role\": \"<string>\",\n \"name\": \"<string>\",\n \"completion_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"metadata\": \"<unknown>\"\n }\n ],\n \"model\": \"<string>\",\n \"stop\": [\n \"<string>\"\n ],\n \"max_tokens\": 1,\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_ttft_ms\": 1,\n \"stream\": true,\n \"stream_options\": {\n \"include_usage\": true\n },\n \"session_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"user\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"ab_campaign\": \"76d1fab3-214c-47ef-bb04-16270639bf89\",\n \"n\": 1,\n \"labels\": {\n \"key\": \"value\"\n },\n \"metadata\": {\n \"key\": \"value\"\n },\n \"system_prompt_args\": {},\n \"tags\": [\n \"<string>\"\n ],\n \"use_tools\": true,\n \"tools\": [\n {\n \"id\": \"<string>\",\n \"enabled\": true\n }\n ],\n \"store\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"created": 123,
"choices": [
{
"index": 1,
"message": {
"id": "<string>",
"role": "<string>",
"content": "<string>"
},
"completion_id": "<string>",
"model": "<string>",
"finish_reason": "<string>"
}
],
"session_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"usage": {
"completion_tokens": 1,
"prompt_tokens": 1,
"total_tokens": 1
}
}Generate chat completion
Generate a chat completion from a prompt using one model in your project. Your prompt messages can include several roles. This endpoints supports streaming
POST
/
api
/
v1
/
chat
/
completions
Generate chat completion
curl --request POST \
--url https://api.example.com/api/v1/chat/completions \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"content": "<string>",
"role": "<string>",
"name": "<string>",
"completion_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"metadata": "<unknown>"
}
],
"model": "<string>",
"stop": [
"<string>"
],
"max_tokens": 1,
"temperature": 123,
"top_p": 123,
"max_ttft_ms": 1,
"stream": true,
"stream_options": {
"include_usage": true
},
"session_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"user": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"ab_campaign": "76d1fab3-214c-47ef-bb04-16270639bf89",
"n": 1,
"labels": {
"key": "value"
},
"metadata": {
"key": "value"
},
"system_prompt_args": {},
"tags": [
"<string>"
],
"use_tools": true,
"tools": [
{
"id": "<string>",
"enabled": true
}
],
"store": true
}
'import requests
url = "https://api.example.com/api/v1/chat/completions"
payload = {
"messages": [
{
"content": "<string>",
"role": "<string>",
"name": "<string>",
"completion_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"metadata": "<unknown>"
}
],
"model": "<string>",
"stop": ["<string>"],
"max_tokens": 1,
"temperature": 123,
"top_p": 123,
"max_ttft_ms": 1,
"stream": True,
"stream_options": { "include_usage": True },
"session_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"user": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"ab_campaign": "76d1fab3-214c-47ef-bb04-16270639bf89",
"n": 1,
"labels": { "key": "value" },
"metadata": { "key": "value" },
"system_prompt_args": {},
"tags": ["<string>"],
"use_tools": True,
"tools": [
{
"id": "<string>",
"enabled": True
}
],
"store": True
}
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: [
{
content: '<string>',
role: '<string>',
name: '<string>',
completion_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
metadata: '<unknown>'
}
],
model: '<string>',
stop: ['<string>'],
max_tokens: 1,
temperature: 123,
top_p: 123,
max_ttft_ms: 1,
stream: true,
stream_options: {include_usage: true},
session_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
user: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
ab_campaign: '76d1fab3-214c-47ef-bb04-16270639bf89',
n: 1,
labels: {key: 'value'},
metadata: {key: 'value'},
system_prompt_args: {},
tags: ['<string>'],
use_tools: true,
tools: [{id: '<string>', enabled: true}],
store: true
})
};
fetch('https://api.example.com/api/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_URL => "https://api.example.com/api/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' => [
[
'content' => '<string>',
'role' => '<string>',
'name' => '<string>',
'completion_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'metadata' => '<unknown>'
]
],
'model' => '<string>',
'stop' => [
'<string>'
],
'max_tokens' => 1,
'temperature' => 123,
'top_p' => 123,
'max_ttft_ms' => 1,
'stream' => true,
'stream_options' => [
'include_usage' => true
],
'session_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'user' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'ab_campaign' => '76d1fab3-214c-47ef-bb04-16270639bf89',
'n' => 1,
'labels' => [
'key' => 'value'
],
'metadata' => [
'key' => 'value'
],
'system_prompt_args' => [
],
'tags' => [
'<string>'
],
'use_tools' => true,
'tools' => [
[
'id' => '<string>',
'enabled' => true
]
],
'store' => true
]),
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.example.com/api/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"role\": \"<string>\",\n \"name\": \"<string>\",\n \"completion_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"metadata\": \"<unknown>\"\n }\n ],\n \"model\": \"<string>\",\n \"stop\": [\n \"<string>\"\n ],\n \"max_tokens\": 1,\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_ttft_ms\": 1,\n \"stream\": true,\n \"stream_options\": {\n \"include_usage\": true\n },\n \"session_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"user\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"ab_campaign\": \"76d1fab3-214c-47ef-bb04-16270639bf89\",\n \"n\": 1,\n \"labels\": {\n \"key\": \"value\"\n },\n \"metadata\": {\n \"key\": \"value\"\n },\n \"system_prompt_args\": {},\n \"tags\": [\n \"<string>\"\n ],\n \"use_tools\": true,\n \"tools\": [\n {\n \"id\": \"<string>\",\n \"enabled\": true\n }\n ],\n \"store\": true\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.example.com/api/v1/chat/completions")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"role\": \"<string>\",\n \"name\": \"<string>\",\n \"completion_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"metadata\": \"<unknown>\"\n }\n ],\n \"model\": \"<string>\",\n \"stop\": [\n \"<string>\"\n ],\n \"max_tokens\": 1,\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_ttft_ms\": 1,\n \"stream\": true,\n \"stream_options\": {\n \"include_usage\": true\n },\n \"session_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"user\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"ab_campaign\": \"76d1fab3-214c-47ef-bb04-16270639bf89\",\n \"n\": 1,\n \"labels\": {\n \"key\": \"value\"\n },\n \"metadata\": {\n \"key\": \"value\"\n },\n \"system_prompt_args\": {},\n \"tags\": [\n \"<string>\"\n ],\n \"use_tools\": true,\n \"tools\": [\n {\n \"id\": \"<string>\",\n \"enabled\": true\n }\n ],\n \"store\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/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 \"messages\": [\n {\n \"content\": \"<string>\",\n \"role\": \"<string>\",\n \"name\": \"<string>\",\n \"completion_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"metadata\": \"<unknown>\"\n }\n ],\n \"model\": \"<string>\",\n \"stop\": [\n \"<string>\"\n ],\n \"max_tokens\": 1,\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_ttft_ms\": 1,\n \"stream\": true,\n \"stream_options\": {\n \"include_usage\": true\n },\n \"session_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"user\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"ab_campaign\": \"76d1fab3-214c-47ef-bb04-16270639bf89\",\n \"n\": 1,\n \"labels\": {\n \"key\": \"value\"\n },\n \"metadata\": {\n \"key\": \"value\"\n },\n \"system_prompt_args\": {},\n \"tags\": [\n \"<string>\"\n ],\n \"use_tools\": true,\n \"tools\": [\n {\n \"id\": \"<string>\",\n \"enabled\": true\n }\n ],\n \"store\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"created": 123,
"choices": [
{
"index": 1,
"message": {
"id": "<string>",
"role": "<string>",
"content": "<string>"
},
"completion_id": "<string>",
"model": "<string>",
"finish_reason": "<string>"
}
],
"session_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"usage": {
"completion_tokens": 1,
"prompt_tokens": 1,
"total_tokens": 1
}
}Body
application/json
Show child attributes
Show child attributes
can be of the form {project}/{model} or {project}. In the latter it will use the default model
Required range:
x >= 0Required range:
x >= 0Show child attributes
Show child attributes
id or key of the entity
Example:
"76d1fab3-214c-47ef-bb04-16270639bf89"
Required range:
x >= 0dictionnary with key and values as string
Show child attributes
Show child attributes
Example:
{ "key": "value" }
alias for labels
Show child attributes
Show child attributes
Example:
{ "key": "value" }
Will be used to render system prompt template
Show child attributes
Show child attributes
Override tool configuration for this request - enables/disables specific tools
Show child attributes
Show child attributes
Was this page helpful?
⌘I

