Skip to main content
POST
Chat completion (metered, per-subject)
This endpoint is served by the in-VM managed proxy at 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.
See the Managed AI Proxy guide for the full integration walkthrough, including streaming and the subject usage read.

Headers

X-Rigbox-Subject
string

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.

Example:

"tenant-42"

X-Rigbox-Subject-Budget
string

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.

Example:

"50;period=30d"

X-Rigbox-Subject-Rate
string

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.

Example:

"5;window=1h"

Body

application/json

A standard OpenAI chat-completion request. Any OpenAI/OpenRouter field is forwarded verbatim; only the fields below are highlighted.

model
string
required

OpenRouter model slug — choose the upstream provider here.

Example:

"openai/gpt-4o-mini"

messages
object[]
required
Example:
max_tokens
integer
Example:

256

stream
boolean

When true, the settled cost is appended to the final usage chunk (stream_options.include_usage is forced on).

Example:

false

user
string

OpenAI end-user field. Used as the subject when X-Rigbox-Subject is absent.

Example:

"tenant-42"

Response

Chat completion. Carries the settled cost in both headers and the body usage.

A standard OpenAI chat-completion response; usage is augmented with the settled cost.

id
string
Example:

"gen-abc123"

model
string
Example:

"openai/gpt-4o-mini"

choices
object[]
usage
object

Token usage plus the rigbox-credit settled cost.