curl --request POST \
--url http://172.16.0.1:9090/v1/chat/completions \
--header 'Content-Type: application/json' \
--data '
{
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Explain microVMs in one paragraph."
}
],
"max_tokens": 256,
"stream": false,
"user": "tenant-42"
}
'import requests
url = "http://172.16.0.1:9090/v1/chat/completions"
payload = {
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Explain microVMs in one paragraph."
}
],
"max_tokens": 256,
"stream": False,
"user": "tenant-42"
}
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({
model: 'openai/gpt-4o-mini',
messages: [{role: 'user', content: 'Explain microVMs in one paragraph.'}],
max_tokens: 256,
stream: false,
user: 'tenant-42'
})
};
fetch('http://172.16.0.1:9090/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 => "9090",
CURLOPT_URL => "http://172.16.0.1:9090/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' => 'openai/gpt-4o-mini',
'messages' => [
[
'role' => 'user',
'content' => 'Explain microVMs in one paragraph.'
]
],
'max_tokens' => 256,
'stream' => false,
'user' => 'tenant-42'
]),
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://172.16.0.1:9090/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"openai/gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain microVMs in one paragraph.\"\n }\n ],\n \"max_tokens\": 256,\n \"stream\": false,\n \"user\": \"tenant-42\"\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://172.16.0.1:9090/v1/chat/completions")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"openai/gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain microVMs in one paragraph.\"\n }\n ],\n \"max_tokens\": 256,\n \"stream\": false,\n \"user\": \"tenant-42\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://172.16.0.1:9090/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 \"model\": \"openai/gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain microVMs in one paragraph.\"\n }\n ],\n \"max_tokens\": 256,\n \"stream\": false,\n \"user\": \"tenant-42\"\n}"
response = http.request(request)
puts response.read_body{
"id": "gen-abc123",
"model": "openai/gpt-4o-mini",
"choices": [
{}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 3,
"total_tokens": 15,
"cost": 0.0000036,
"cost_micro": 360,
"cost_credits": 0.00036
}
}{
"error": {
"code": "subject_limit_malformed",
"message": "Malformed X-Rigbox-Subject-Budget/-Rate header: expected '<amount>;period=<window>' (amount is credits, or a request count with a 'req' suffix).",
"type": "rigbox_gateway_error",
"param": null
}
}{
"error": {
"code": "subject_over_budget",
"message": "Subject 'tenant-42' is over its budget: 50 credits per 2592000s.",
"type": "rigbox_gateway_error",
"param": null,
"details": {
"reason": "subject_over_budget",
"subject": "tenant-42",
"limit": {
"kind": "credits",
"amount": 50,
"window_seconds": 2592000
},
"used": {
"credits": 50.3,
"credits_micro": 50300000
},
"resets_at": "2026-07-15T06:04:15Z",
"retry_after": 2592000
}
}
}{
"error": {
"code": "subject_rate_limited",
"message": "Subject 'tenant-42' hit a rate limit: 5 credits per 3600s.",
"type": "rigbox_gateway_error",
"param": null,
"details": {
"reason": "subject_rate_limited",
"subject": "tenant-42",
"limit": {
"kind": "credits",
"amount": 5,
"window_seconds": 3600
},
"used": {
"credits": 5,
"credits_micro": 5000000
},
"resets_at": "2026-06-15T13:00:00Z",
"retry_after": 3600
}
}
}Chat Completion (metered, per-subject)
OpenAI-compatible chat completion through the managed proxy, with the settled cost on the response and optional per-subject budget/rate enforcement.
curl --request POST \
--url http://172.16.0.1:9090/v1/chat/completions \
--header 'Content-Type: application/json' \
--data '
{
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Explain microVMs in one paragraph."
}
],
"max_tokens": 256,
"stream": false,
"user": "tenant-42"
}
'import requests
url = "http://172.16.0.1:9090/v1/chat/completions"
payload = {
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Explain microVMs in one paragraph."
}
],
"max_tokens": 256,
"stream": False,
"user": "tenant-42"
}
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({
model: 'openai/gpt-4o-mini',
messages: [{role: 'user', content: 'Explain microVMs in one paragraph.'}],
max_tokens: 256,
stream: false,
user: 'tenant-42'
})
};
fetch('http://172.16.0.1:9090/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 => "9090",
CURLOPT_URL => "http://172.16.0.1:9090/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' => 'openai/gpt-4o-mini',
'messages' => [
[
'role' => 'user',
'content' => 'Explain microVMs in one paragraph.'
]
],
'max_tokens' => 256,
'stream' => false,
'user' => 'tenant-42'
]),
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://172.16.0.1:9090/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"openai/gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain microVMs in one paragraph.\"\n }\n ],\n \"max_tokens\": 256,\n \"stream\": false,\n \"user\": \"tenant-42\"\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://172.16.0.1:9090/v1/chat/completions")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"openai/gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain microVMs in one paragraph.\"\n }\n ],\n \"max_tokens\": 256,\n \"stream\": false,\n \"user\": \"tenant-42\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://172.16.0.1:9090/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 \"model\": \"openai/gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain microVMs in one paragraph.\"\n }\n ],\n \"max_tokens\": 256,\n \"stream\": false,\n \"user\": \"tenant-42\"\n}"
response = http.request(request)
puts response.read_body{
"id": "gen-abc123",
"model": "openai/gpt-4o-mini",
"choices": [
{}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 3,
"total_tokens": 15,
"cost": 0.0000036,
"cost_micro": 360,
"cost_credits": 0.00036
}
}{
"error": {
"code": "subject_limit_malformed",
"message": "Malformed X-Rigbox-Subject-Budget/-Rate header: expected '<amount>;period=<window>' (amount is credits, or a request count with a 'req' suffix).",
"type": "rigbox_gateway_error",
"param": null
}
}{
"error": {
"code": "subject_over_budget",
"message": "Subject 'tenant-42' is over its budget: 50 credits per 2592000s.",
"type": "rigbox_gateway_error",
"param": null,
"details": {
"reason": "subject_over_budget",
"subject": "tenant-42",
"limit": {
"kind": "credits",
"amount": 50,
"window_seconds": 2592000
},
"used": {
"credits": 50.3,
"credits_micro": 50300000
},
"resets_at": "2026-07-15T06:04:15Z",
"retry_after": 2592000
}
}
}{
"error": {
"code": "subject_rate_limited",
"message": "Subject 'tenant-42' hit a rate limit: 5 credits per 3600s.",
"type": "rigbox_gateway_error",
"param": null,
"details": {
"reason": "subject_rate_limited",
"subject": "tenant-42",
"limit": {
"kind": "credits",
"amount": 5,
"window_seconds": 3600
},
"used": {
"credits": 5,
"credits_micro": 5000000
},
"resets_at": "2026-06-15T13:00:00Z",
"retry_after": 3600
}
}
}http://172.16.0.1:9090, not the public api.rigbox.dev gateway. It is IP-attested — no API key; SDKs that require one can send a placeholder Authorization: Bearer managed-by-rigbox.Headers
End-user id this call's cost is attributed to. Wins over the OpenAI user body field. Trimmed; empty is treated as absent; capped at 256 characters.
"tenant-42"
At most one. Total spend cap for the subject over a rolling window: <amount>;period=<window>. <amount> is credits (a float) or a request count with a req suffix (e.g. 100req). <window> is 5h/30m/7d or a bare number of seconds. Requires X-Rigbox-Subject. A breach returns 402 subject_over_budget. Malformed → 400 subject_limit_malformed.
"50;period=30d"
May be sent multiple times. A sliding rolling-window rate limit for the subject: <amount>;window=<window> (same amount/window grammar as the budget header). Requires X-Rigbox-Subject. A breach returns 429 subject_rate_limited with a Retry-After header. Malformed → 400 subject_limit_malformed.
"5;window=1h"
Body
A standard OpenAI chat-completion request. Any OpenAI/OpenRouter field is forwarded verbatim; only the fields below are highlighted.
OpenRouter model slug — choose the upstream provider here.
"openai/gpt-4o-mini"
[
{
"role": "user",
"content": "Explain microVMs in one paragraph."
}
]
256
When true, the settled cost is appended to the final usage chunk (stream_options.include_usage is forced on).
false
OpenAI end-user field. Used as the subject when X-Rigbox-Subject is absent.
"tenant-42"
Response
Chat completion. Carries the settled cost in both headers and the body usage.