Create a chat completion
Proxies an OpenAI-compatible request to an eligible provider and meters the response.
POST
/
v1
/
chat
/
completions
Create a chat completion
curl --request POST \
--url https://api.example.com/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'X-Tulip-Permit: <x-tulip-permit>' \
--data '
{
"model": "<string>",
"messages": [
{
"content": "<unknown>"
}
],
"offer": "<string>",
"max_tokens": 2,
"max_completion_tokens": 2,
"temperature": 123,
"top_p": 123,
"stop": "<string>",
"stream": true,
"tools": [
"<unknown>"
],
"tool_choice": "<unknown>",
"response_format": "<unknown>",
"seed": 123,
"user": "<string>"
}
'import requests
url = "https://api.example.com/v1/chat/completions"
payload = {
"model": "<string>",
"messages": [{ "content": "<unknown>" }],
"offer": "<string>",
"max_tokens": 2,
"max_completion_tokens": 2,
"temperature": 123,
"top_p": 123,
"stop": "<string>",
"stream": True,
"tools": ["<unknown>"],
"tool_choice": "<unknown>",
"response_format": "<unknown>",
"seed": 123,
"user": "<string>"
}
headers = {
"X-Tulip-Permit": "<x-tulip-permit>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-Tulip-Permit': '<x-tulip-permit>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: '<string>',
messages: [{content: '<unknown>'}],
offer: '<string>',
max_tokens: 2,
max_completion_tokens: 2,
temperature: 123,
top_p: 123,
stop: '<string>',
stream: true,
tools: ['<unknown>'],
tool_choice: '<unknown>',
response_format: '<unknown>',
seed: 123,
user: '<string>'
})
};
fetch('https://api.example.com/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/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([
'model' => '<string>',
'messages' => [
[
'content' => '<unknown>'
]
],
'offer' => '<string>',
'max_tokens' => 2,
'max_completion_tokens' => 2,
'temperature' => 123,
'top_p' => 123,
'stop' => '<string>',
'stream' => true,
'tools' => [
'<unknown>'
],
'tool_choice' => '<unknown>',
'response_format' => '<unknown>',
'seed' => 123,
'user' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"X-Tulip-Permit: <x-tulip-permit>"
],
]);
$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/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<unknown>\"\n }\n ],\n \"offer\": \"<string>\",\n \"max_tokens\": 2,\n \"max_completion_tokens\": 2,\n \"temperature\": 123,\n \"top_p\": 123,\n \"stop\": \"<string>\",\n \"stream\": true,\n \"tools\": [\n \"<unknown>\"\n ],\n \"tool_choice\": \"<unknown>\",\n \"response_format\": \"<unknown>\",\n \"seed\": 123,\n \"user\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Tulip-Permit", "<x-tulip-permit>")
req.Header.Add("Authorization", "Bearer <token>")
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/v1/chat/completions")
.header("X-Tulip-Permit", "<x-tulip-permit>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<unknown>\"\n }\n ],\n \"offer\": \"<string>\",\n \"max_tokens\": 2,\n \"max_completion_tokens\": 2,\n \"temperature\": 123,\n \"top_p\": 123,\n \"stop\": \"<string>\",\n \"stream\": true,\n \"tools\": [\n \"<unknown>\"\n ],\n \"tool_choice\": \"<unknown>\",\n \"response_format\": \"<unknown>\",\n \"seed\": 123,\n \"user\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Tulip-Permit"] = '<x-tulip-permit>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<unknown>\"\n }\n ],\n \"offer\": \"<string>\",\n \"max_tokens\": 2,\n \"max_completion_tokens\": 2,\n \"temperature\": 123,\n \"top_p\": 123,\n \"stop\": \"<string>\",\n \"stream\": true,\n \"tools\": [\n \"<unknown>\"\n ],\n \"tool_choice\": \"<unknown>\",\n \"response_format\": \"<unknown>\",\n \"seed\": 123,\n \"user\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{}{
"error": {
"code": "<string>",
"type": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"type": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"type": "<string>",
"message": "<string>"
}
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Pattern:
^0x[0-9a-fA-F]{64}$Pattern:
^0x[0-9a-fA-F]{64}$Body
application/json
Minimum array length:
1Show child attributes
Show child attributes
Pattern:
^0x[0-9a-fA-F]{64}$Required range:
x >= 1Required range:
x >= 1Response
Upstream OpenAI-compatible JSON or server-sent event stream.
The response is of type object.
⌘I
Create a chat completion
curl --request POST \
--url https://api.example.com/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'X-Tulip-Permit: <x-tulip-permit>' \
--data '
{
"model": "<string>",
"messages": [
{
"content": "<unknown>"
}
],
"offer": "<string>",
"max_tokens": 2,
"max_completion_tokens": 2,
"temperature": 123,
"top_p": 123,
"stop": "<string>",
"stream": true,
"tools": [
"<unknown>"
],
"tool_choice": "<unknown>",
"response_format": "<unknown>",
"seed": 123,
"user": "<string>"
}
'import requests
url = "https://api.example.com/v1/chat/completions"
payload = {
"model": "<string>",
"messages": [{ "content": "<unknown>" }],
"offer": "<string>",
"max_tokens": 2,
"max_completion_tokens": 2,
"temperature": 123,
"top_p": 123,
"stop": "<string>",
"stream": True,
"tools": ["<unknown>"],
"tool_choice": "<unknown>",
"response_format": "<unknown>",
"seed": 123,
"user": "<string>"
}
headers = {
"X-Tulip-Permit": "<x-tulip-permit>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-Tulip-Permit': '<x-tulip-permit>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: '<string>',
messages: [{content: '<unknown>'}],
offer: '<string>',
max_tokens: 2,
max_completion_tokens: 2,
temperature: 123,
top_p: 123,
stop: '<string>',
stream: true,
tools: ['<unknown>'],
tool_choice: '<unknown>',
response_format: '<unknown>',
seed: 123,
user: '<string>'
})
};
fetch('https://api.example.com/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/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([
'model' => '<string>',
'messages' => [
[
'content' => '<unknown>'
]
],
'offer' => '<string>',
'max_tokens' => 2,
'max_completion_tokens' => 2,
'temperature' => 123,
'top_p' => 123,
'stop' => '<string>',
'stream' => true,
'tools' => [
'<unknown>'
],
'tool_choice' => '<unknown>',
'response_format' => '<unknown>',
'seed' => 123,
'user' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"X-Tulip-Permit: <x-tulip-permit>"
],
]);
$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/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<unknown>\"\n }\n ],\n \"offer\": \"<string>\",\n \"max_tokens\": 2,\n \"max_completion_tokens\": 2,\n \"temperature\": 123,\n \"top_p\": 123,\n \"stop\": \"<string>\",\n \"stream\": true,\n \"tools\": [\n \"<unknown>\"\n ],\n \"tool_choice\": \"<unknown>\",\n \"response_format\": \"<unknown>\",\n \"seed\": 123,\n \"user\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Tulip-Permit", "<x-tulip-permit>")
req.Header.Add("Authorization", "Bearer <token>")
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/v1/chat/completions")
.header("X-Tulip-Permit", "<x-tulip-permit>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<unknown>\"\n }\n ],\n \"offer\": \"<string>\",\n \"max_tokens\": 2,\n \"max_completion_tokens\": 2,\n \"temperature\": 123,\n \"top_p\": 123,\n \"stop\": \"<string>\",\n \"stream\": true,\n \"tools\": [\n \"<unknown>\"\n ],\n \"tool_choice\": \"<unknown>\",\n \"response_format\": \"<unknown>\",\n \"seed\": 123,\n \"user\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Tulip-Permit"] = '<x-tulip-permit>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<unknown>\"\n }\n ],\n \"offer\": \"<string>\",\n \"max_tokens\": 2,\n \"max_completion_tokens\": 2,\n \"temperature\": 123,\n \"top_p\": 123,\n \"stop\": \"<string>\",\n \"stream\": true,\n \"tools\": [\n \"<unknown>\"\n ],\n \"tool_choice\": \"<unknown>\",\n \"response_format\": \"<unknown>\",\n \"seed\": 123,\n \"user\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{}{
"error": {
"code": "<string>",
"type": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"type": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"type": "<string>",
"message": "<string>"
}
}