Model Gateway
Route requests to any LLM provider through a single endpoint. Bring your own keys, set budgets, and track usage. Use the gateway on its own, or name one of its models on the Drop-in API to keep Cadreen's rules, memory and receipts around it.
Three ways to use the gateway
The gateway gives you models, your own keys and budgets. Cadreen's rules, held calls, memory and receipts come only through the Drop-in API. Pick how much of Cadreen you want:
Drop-in API, model "cadreen"
OpenAI-compatible. Cadreen picks the model, and everything is included: rules on every tool call, held calls, memory, conversations and receipts.
/api/v1/cadreen/chat/completionsWhen to use: You want Cadreen to handle it all. Send model "cadreen" or leave it out.
Drop-in API, naming a gateway model
The same endpoint, with a model from GET /models as the model. That model answers. Cadreen's rules, held calls, memory and receipts still apply.
/api/v1/cadreen/chat/completionsWhen to use: You want a specific model, with Cadreen around it. Your workspace has to turn on named models first (off until it does).
Gateway endpoint, model access only
Pick a model, get its answer. No rules, no memory, no receipts: Cadreen adds nothing.
/api/v1/cadreen/gateway/responsesWhen to use: You want model access, your own keys and budgets, and nothing else.
model field to pick the provider and model. On the Drop-in API, cadreen (or no model) lets Cadreen pick, and a name from GET /models makes that model answer once your workspace has turned on named models. Any other name, one the catalogue doesn't have, is answered by Cadreen and never refused. Whenever Cadreen answers (no model, cadreen, a name it doesn't have, or a fallback), the response's model says cadreen, never the model underneath. The same holds on the Drop-in Responses endpoint (POST /responses), where the rules check every tool call the model proposes, as on chat completions. When a named model writes text before a tool call, that text streams as it is written. Only the tool calls are held until the rules have checked them.When the model you name can't answer
If the model you named can't be called (its credit is out, it is busy or down, or its key can't be used: the provider key you added under AI keys and budgets was refused, or Cadreen's own gateway key is missing or was refused, which is Cadreen's to fix, not yours), Cadreen answers instead. This only happens before any of the answer was sent or any tool ran. The response says so: its model is cadreen, the X-Cadreen-Model-Fallback header carries a code, and the cadreen.model_fallback object in the body gives requested_model, code and a sentence. A name that isn't in GET /models gets the same notice, with model_not_in_catalogue. You are charged at Cadreen's rates for that answer, never for the model you named. If you would rather get an error, send cadreen.model_fallback as false, or ask a workspace admin to fix it off on your key. A request that is itself wrong stays an error. A streamed answer has to start sending before a slow model has answered, so the headers X-Cadreen-Answered-By and X-Cadreen-Model-Fallback are set when the answer is known within 30 seconds; past that they are left out, and the first chunk always carries it (its model and, after a fall-back, cadreen.model_fallback). Read the first chunk, not the headers, when you need to be sure. Each turn is recorded under your Idempotency-Key: a second turn with the same key is 409 idempotency_conflict and the model is not asked. It is not a replay of the first answer, because a named model's answer isn't kept, so use a new key to ask again. If the first turn failed with none of its answer sent, the key is free again and you can send the same turn with it. The model field says who wrote the text: Cadreen's own sentence for a held call or a missing parameter says cadreen, and an error never says who answered.
Quick start
curl -X POST https://api.cadreen.com/api/v1/cadreen/gateway/responses \
-H "Authorization: Bearer sk_cadreen_..." \
-H "Content-Type: application/json" \
-d '{
"model": "<a model id from GET /models>",
"input": [{"type": "message", "role": "user", "content": "Hello"}],
"max_tokens": 100
}'import requests
response = requests.post(
"https://api.cadreen.com/api/v1/cadreen/gateway/responses",
headers={"Authorization": "Bearer sk_cadreen_..."},
json={
"model": "<a model id from GET /models>",
"input": [{"type": "message", "role": "user", "content": "Hello"}],
"max_tokens": 100,
},
)
print(response.json())const response = await fetch(
"https://api.cadreen.com/api/v1/cadreen/gateway/responses",
{
method: "POST",
headers: {
"Authorization": "Bearer sk_cadreen_...",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "<a model id from GET /models>",
input: [{ type: "message", role: "user", content: "Hello" }],
max_tokens: 100,
}),
}
);
const data = await response.json();model? The gateway's own routing policy picks one (that is the gateway's routing, set up in the gateway, not Cadreen's). Pin a model to bypass routing — budget and key checks still apply.Can I use the OpenAI SDK?
Not yet. The gateway takes requests at /api/v1/cadreen/gateway/responses in its own format, shown above, and lists models at /api/v1/cadreen/gateway/models. There's no chat-completions address for the OpenAI SDK to point at.
Supported providers and models
Use the format provider/model in the model field. The gateway supports 150+ models with live pricing:
| Model | Input / 1M | Output / 1M |
|---|---|---|
model and the gateway's own routing policy selects one for you (this is the gateway's routing, not Cadreen's). Or send cadreen to Cadreen's /chat/completions endpoint — Cadreen picks a model for you, with its rules and memory around it.Bring your own keys (BYOK)
Add your own provider API keys. Requests through your keys use your provider account directly. Once charges start, they cost what they cost plus 5%.
Your keys apply to the requests you send through the gateway. Cadreen's own work (chat, executions, the Cadreen API and AccomplishAnything) runs on Cadreen's keys.
In the dashboard, open AI keys and budgets → Add key
Select provider (e.g., OpenAI)
Paste your API keyKey behavior:
- Uses only your key — never falls back to managed credentials
- If your key is invalid, request fails with
provider_credentials_missing - Multiple keys supported — one per provider
Budgets
Set per-workspace spending limits. Choose soft limits (warn when exceeded) or hard limits (stop when exceeded).
In the dashboard, open AI keys and budgets → How much can your requests spend?
Amount: $50.00
Period: Monthly
Enforcement: Hard (stops when exceeded)Budget behavior:
- Checked AFTER each request completes (the request that pushes you over succeeds)
- Hard limit: next request returns
402 budget_exceeded - Soft limit: request proceeds, warning appears in dashboard
- Both BYOK and managed usage count toward the budget
Usage tracking
Track spending across providers, models, and time periods. See where your money goes.
curl -H "Authorization: Bearer sk_cadreen_..." \
"https://api.cadreen.com/api/v1/maas/gateway/usage?start=2026-07-01&end=2026-07-31"{
"byok_spend": 45.20,
"managed_spend": 12.50,
"total": 57.70,
"by_model": {
"<model id A>": 30.00,
"<model id B>": 15.20
}
}Streaming
Set "stream": true to receive SSE. The format matches OpenAI's streaming.
data: {"type":"response.output_text.delta","delta":"The "}
data: {"type":"response.output_text.delta","delta":"weather..."}
data: [DONE]How a stream ends:
- Before it opens — an HTTP status with error JSON (budget used up, bad request).
- When it works — the last event is
response.completed, with the answer's usage. - An event over 8 MiB — it can't be checked for routing details, so it isn't passed on. You get
event: errorin its place, with{"type":"error","error":{"code":"event_too_large",…}}: the same error object every response uses, undererror. - An event that can't be read — a data line that isn't one whole JSON object can't be checked either. You get
"error":{"code":"event_unreadable",…}in an error event in its place. - If you ask for routing details — nothing needs checking, so every event is passed on as it came, whatever its size.
Error reference
| Type | HTTP | When |
|---|---|---|
invalid_request_error | 400 | Malformed request or embedded routing not enabled |
authentication_error | 401 | Missing or invalid API key |
budget_exceeded | 402 | Hard budget exhausted |
permission_error | 403 | Customer is inactive or deleted |
not_found_error | 404 | Unknown customer or missing provider credentials |
unavailable | 503 | The configuration couldn't be read. Retry. |
When to use which endpoint
| I want to | Use | Why |
|---|---|---|
| Route to a specific model | /gateway/responses | Pin model. No governance. Pure routing. |
| Use my own API keys | /gateway/responses | BYOK. Your budget. |
| Get an answer with rules enforced | /chat/completions | OpenAI-compatible. Adds governance, memory, traces. |
| Let Cadreen choose the model | /intent | Full pipeline. Model selection, governance, execution. |
| Just use Cadreen as an OpenAI replacement | /chat/completions | Your tool calls go through your rules. Same API as OpenAI: change the base URL. |
Next steps
- Model Provider Guide — The completions endpoint (OpenAI-compatible, with Cadreen)
- Connect a Tool — Set up your first integration
- Gateway Dashboard — Manage keys, budgets, and usage