Chat Completions
curl --request POST \
--url https://api.gregapi.com/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are GregAPI's product assistant."
},
{
"role": "user",
"content": "Introduce GregAPI in three sentences."
}
],
"temperature": 0.7
}
EOFimport requests
url = "https://api.gregapi.com/v1/chat/completions"
payload = {
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are GregAPI's product assistant."
},
{
"role": "user",
"content": "Introduce GregAPI in three sentences."
}
],
"temperature": 0.7
}
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: 'gpt-4o-mini',
messages: [
{role: 'system', content: 'You are GregAPI\'s product assistant.'},
{role: 'user', content: 'Introduce GregAPI in three sentences.'}
],
temperature: 0.7
})
};
fetch('https://api.gregapi.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.gregapi.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' => 'gpt-4o-mini',
'messages' => [
[
'role' => 'system',
'content' => 'You are GregAPI\'s product assistant.'
],
[
'role' => 'user',
'content' => 'Introduce GregAPI in three sentences.'
]
],
'temperature' => 0.7
]),
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.gregapi.com/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are GregAPI's product assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Introduce GregAPI in three sentences.\"\n }\n ],\n \"temperature\": 0.7\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.gregapi.com/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are GregAPI's product assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Introduce GregAPI in three sentences.\"\n }\n ],\n \"temperature\": 0.7\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gregapi.com/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\": \"gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are GregAPI's product assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Introduce GregAPI in three sentences.\"\n }\n ],\n \"temperature\": 0.7\n}"
response = http.request(request)
puts response.read_bodyLarge Language Models (LLM)
Chat Completions
Use GregAPI’s OpenAI-compatible chat completion and tool-calling interface.
POST
/
v1
/
chat
/
completions
Chat Completions
curl --request POST \
--url https://api.gregapi.com/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are GregAPI's product assistant."
},
{
"role": "user",
"content": "Introduce GregAPI in three sentences."
}
],
"temperature": 0.7
}
EOFimport requests
url = "https://api.gregapi.com/v1/chat/completions"
payload = {
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are GregAPI's product assistant."
},
{
"role": "user",
"content": "Introduce GregAPI in three sentences."
}
],
"temperature": 0.7
}
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: 'gpt-4o-mini',
messages: [
{role: 'system', content: 'You are GregAPI\'s product assistant.'},
{role: 'user', content: 'Introduce GregAPI in three sentences.'}
],
temperature: 0.7
})
};
fetch('https://api.gregapi.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.gregapi.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' => 'gpt-4o-mini',
'messages' => [
[
'role' => 'system',
'content' => 'You are GregAPI\'s product assistant.'
],
[
'role' => 'user',
'content' => 'Introduce GregAPI in three sentences.'
]
],
'temperature' => 0.7
]),
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.gregapi.com/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are GregAPI's product assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Introduce GregAPI in three sentences.\"\n }\n ],\n \"temperature\": 0.7\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.gregapi.com/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are GregAPI's product assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Introduce GregAPI in three sentences.\"\n }\n ],\n \"temperature\": 0.7\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gregapi.com/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\": \"gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are GregAPI's product assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Introduce GregAPI in three sentences.\"\n }\n ],\n \"temperature\": 0.7\n}"
response = http.request(request)
puts response.read_bodyPOST /v1/chat/completions is the most commonly used chat generation endpoint. It supports streaming output, function calling (tools/functions), and JSON mode.
Request example
curl -X POST "https://api.gregapi.com/v1/chat/completions" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are the GregAPI product assistant."},
{"role": "user", "content": "Introduce GregAPI in three sentences."}
],
"temperature": 0.7
}'
Common usage
- Streaming: set
stream: truein the request body. Add-Nfor cURL, or userequests.post(..., stream=True)in Python to read line by line. - Function calling: describe callable functions via
toolsandtool_choice, then parsetool_callsin the response and run your business logic. - JSON constraint: set
response_formatto{"type": "json_schema"}to have the model return structured data strictly.
GregAPI extension fields
The following fields are GregAPI’s extensions on top of the standard OpenAI response body, used to expose billing details of the upstream model.usage.prompt_tokens_details
| Field | Meaning | Applicable models |
|---|---|---|
cached_tokens | Number of input tokens that hit the cache | All cache-enabled models |
cached_write_tokens | Total cache writes (= 5m + 1h) | Claude |
cached_write_5m_tokens | Tokens written to the 5-minute cache | Claude |
cached_write_1h_tokens | Tokens written to the 1-hour cache | Claude |
prompt_tokens is the total input tokens (including cache hits and cache writes). Cache-write fields are omitempty, so models without cache writes (e.g. GPT) do not output them.
{
"usage": {
"prompt_tokens": 58518,
"prompt_tokens_details": {
"cached_tokens": 11944,
"cached_write_tokens": 46109,
"cached_write_5m_tokens": 29762,
"cached_write_1h_tokens": 16347
}
}
}
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
Model name
Conversation messages
Show child attributes
Show child attributes
Sampling temperature, default 1
Whether to stream output
Callable function definitions
Output format, e.g. JSON Schema (json_schema)
Response
200
Successful chat completion response