API DOCUMENTATION
The interface that exists today.
Reference for the private Gateway implemented in backend version 0.4.0. Examples require an authorised private environment and a scoped Bearer credential. This website does not call these endpoints.
Authentication and access
Send a Bearer credential in the Authorization header. Both catalogue routes require models:read; the estimate route requires usage:estimate. Credentials are limited, expiring and revocable. Do not put credentials in URLs or browser code.
Three implemented routes
The model identifier currently enabled is mock-extractive-v1. The model description includes provider_id, model_id, capabilities, limits and simulated. Capabilities describe the adapter; text.generate does not imply a public execution route.
| Endpoint | Required scope |
|---|---|
GET/api/v1/models | models:read |
GET/api/v1/models/{model_id} | models:read |
POST/api/v1/models/{model_id}/estimate | usage:estimate |
Read the catalogue and estimate usage
This Python example uses the standard library. SOVREG_API_BASE must point to your authorised private API, and SOVREG_API_TOKEN must contain a credential issued for the required scopes. These are operator-side environment variables, not settings requested by the website.
import json
import os
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
# Use only an authorised private API and a scoped credential.
base = os.environ["SOVREG_API_BASE"].rstrip("/")
token = os.environ["SOVREG_API_TOKEN"]
def request(path, payload=None):
data = None if payload is None else json.dumps(payload).encode("utf-8")
req = Request(
base + path,
data=data,
headers={
"Authorization": "Bearer " + token,
"Content-Type": "application/json",
},
)
try:
with urlopen(req, timeout=10) as response:
return json.load(response)
except HTTPError as error:
raise RuntimeError(f"API returned HTTP {error.code}") from None
except (URLError, TimeoutError):
raise RuntimeError("Private API is unavailable") from None
catalogue = request("/api/v1/models")
print([item["model_id"] for item in catalogue["items"]])
estimate = request(
"/api/v1/models/mock-extractive-v1/estimate",
{"text": "First second third", "max_output_tokens": 2},
)
assert estimate["financial_quote"] is False
assert estimate["estimate"]["simulated"] is True
print(estimate["estimate"])Estimation is not a financial quote
POST accepts text and max_output_tokens. The response contains a simulated word-based upper bound and financial_quote=false. It neither generates a summary nor reserves, issues or spends credits.
- Text: non-empty, at most 8192 UTF-8 bytes and 2048 whitespace-separated words.
- max_output_tokens: integer from 1 to 256; default 64. Booleans, floats and extra fields are rejected.
- The common API body limit is 16 KiB. JSON escaping can reach it before the text byte limit.
- The estimate is read-only and does not require an Idempotency-Key. Authenticated calls still produce a safe audit record.
{
"text": "First second third",
"max_output_tokens": 2
}{
"model_id": "mock-extractive-v1",
"estimate": {
"input_tokens_upper_bound": 3,
"output_tokens_cap": 2,
"additional_cost_cap": "0",
"estimation_method": "mock_whitespace_words",
"simulated": true
},
"financial_quote": false
}Handle failure explicitly
Do not interpret a failed or unknown estimate as zero usage. Authentication errors may contain only detail; do not assume every response has a domain code.
- 401
- Missing, expired or invalid credential.
- 403
- The credential does not grant the required scope.
- 404
- The requested model is not in the enabled catalogue.
- 411
- A modifying HTTP method requires Content-Length; native Node fetch supplies it for the JSON body.
- 413
- The JSON body exceeds the common 16 KiB limit.
- 422
- Invalid fields, types or model input limits.
- 429
- The API rate limit has been reached.
- 503
- The private service or its database is unavailable.
A typed client for private server code
This repository includes a Node.js-only adapter for the three routes above. It requires an explicitly configured API origin and scoped credential provider; the public website does not import or activate it.
- listModels, getModel and estimateUsage validate responses against the current Gateway contract.
- A deadline and AbortSignal cover credential lookup, transport and response reading. Requests are not retried automatically.
- GatewayClientError exposes a normalised code and optional HTTP status, request ID and Retry-After seconds. It does not retain credentials, input text or raw server error bodies.
- This adapter does not implement public user authentication, computation, payments or a financial quote.
// Trusted Node.js code in a private application, never a browser component.
import {
createPrivateGatewayClient,
GatewayClientError,
} from "@/lib/private-gateway/client";
const baseUrl = process.env.SOVREG_API_BASE;
if (!baseUrl) throw new Error("Private API origin is not configured");
const client = createPrivateGatewayClient({
baseUrl,
timeoutMs: 5000,
getCredential: () => {
const value = process.env.SOVREG_API_TOKEN;
if (!value) throw new Error("Scoped credential is unavailable");
return value;
},
});
try {
const catalogue = await client.listModels();
const model = await client.getModel("mock-extractive-v1");
const result = await client.estimateUsage(model.model_id, {
text: "First second third",
max_output_tokens: 2,
});
// result.financial_quote is false; result.estimate.simulated is true.
console.log(catalogue.items.length, result.estimate.input_tokens_upper_bound);
} catch (error) {
if (error instanceof GatewayClientError) {
// Only normalised fields, never credentials, prompt or raw response.
console.error(error.code, error.status);
} else {
throw error;
}
}