curl https://api.liquid.ai/openai/v1/chat/completions \
-H "Authorization: Bearer $LIQUID_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "$MODEL_ID",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
}'import requests
url = "https://api.liquid.ai/openai/v1/chat/completions"
payload = {
"model": "$MODEL_ID",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '$MODEL_ID',
messages: [
{role: 'system', content: 'You are a helpful assistant.'},
{role: 'user', content: 'Hello!'}
]
})
};
fetch('https://api.liquid.ai/openai/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.liquid.ai/openai/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' => '$MODEL_ID',
'messages' => [
[
'role' => 'system',
'content' => 'You are a helpful assistant.'
],
[
'role' => 'user',
'content' => 'Hello!'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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.liquid.ai/openai/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"$MODEL_ID\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a helpful assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
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.liquid.ai/openai/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"$MODEL_ID\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a helpful assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.liquid.ai/openai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"$MODEL_ID\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a helpful assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1730419200,
"model": "$MODEL_ID",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 19,
"completion_tokens": 10,
"total_tokens": 29
}
}{
"error": {
"message": "Rate limit exceeded for model `$MODEL_ID`. To request a higher limit, contact us at https://www.liquid.ai/connect.",
"type": "rate_limit_error",
"param": null,
"code": "rate_limit_exceeded"
}
}Chat completions
Generate a model response for a chat conversation. See Text generation.
curl https://api.liquid.ai/openai/v1/chat/completions \
-H "Authorization: Bearer $LIQUID_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "$MODEL_ID",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
}'import requests
url = "https://api.liquid.ai/openai/v1/chat/completions"
payload = {
"model": "$MODEL_ID",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '$MODEL_ID',
messages: [
{role: 'system', content: 'You are a helpful assistant.'},
{role: 'user', content: 'Hello!'}
]
})
};
fetch('https://api.liquid.ai/openai/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.liquid.ai/openai/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' => '$MODEL_ID',
'messages' => [
[
'role' => 'system',
'content' => 'You are a helpful assistant.'
],
[
'role' => 'user',
'content' => 'Hello!'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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.liquid.ai/openai/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"$MODEL_ID\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a helpful assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
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.liquid.ai/openai/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"$MODEL_ID\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a helpful assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.liquid.ai/openai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"$MODEL_ID\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a helpful assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1730419200,
"model": "$MODEL_ID",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 19,
"completion_tokens": 10,
"total_tokens": 29
}
}{
"error": {
"message": "Rate limit exceeded for model `$MODEL_ID`. To request a higher limit, contact us at https://www.liquid.ai/connect.",
"type": "rate_limit_error",
"param": null,
"code": "rate_limit_exceeded"
}
}Authorizations
Body
The model id to use.
"$MODEL_ID"
The conversation so far. Messages follow OpenAI role-specific content requirements. User messages may include image_url parts for models that take images, each a base64 data: URL or an http(s) URL, and input_audio parts (base64 WAV, format: "wav") for models that take audio; other models return 400. Liquid downloads linked images itself before the request reaches the model, from public addresses only, and returns 400 when one cannot be downloaded or is not a PNG, JPEG, WebP, or GIF image; a request may link up to 8 images, of at most 10 MB each and 20 MB together.
When true, tokens stream back as server-sent events.
Output types. ["text", "audio"] asks a model with speech output for a spoken reply, returned in message.audio (or streamed in delta.audio) beside the text. Defaults to ["text"]; models without speech output return 400.
Spoken reply options when modalities includes "audio", as in OpenAI: { "voice", "format" }. format is pcm16 (headerless 16-bit PCM, 24 kHz mono), or wav (each streamed chunk a complete WAV file); other formats return 400. The reply arrives in message.audio or streamed delta.audio, with its words in transcript. voice is accepted but does not change the voice.
Response
Successful response.
The completion id.
Always "chat.completion".
Unix timestamp (seconds).
The model that generated the response.
The generated choices.
Token counts: { prompt_tokens, completion_tokens, total_tokens }, plus cost in USD when the model is priced. Audio models also report OpenAI's prompt_tokens_details and completion_tokens_details, whose audio_tokens say how much of each total was audio. Some vision models bill each image as a multiple of its tokens, counted in prompt_tokens as OpenAI does. Streaming responses report it on the final usage chunk.
Was this page helpful?