Hosted Gateway
Call B3IQ hosted OpenAI-compatible endpoints with gateway keys, billing policy, receipts, and streaming metadata.
The hosted gateway exposes OpenAI-compatible HTTP endpoints backed by B3IQ router policy. It selects eligible supply, enforces billing and customer policy, and records receipt metadata without storing raw prompts or outputs in the control plane.
Endpoints
| Method | Path | Purpose |
|---|---|---|
| GET | /v1/models | List router-eligible, observed, paid-route-capable public model profiles |
| POST | /v1/chat/completions | Run a hosted OpenAI-compatible chat completion through B3IQ route policy |
| GET | /v1/billing/account | Read customer prepaid balance and gateway policy |
| GET | /v1/billing/usage | Export authenticated customer ledger usage |
| GET | /v1/receipts/{receipt_hash} | Read public-safe receipt evidence |
List Models
bash: "${B3IQ_GATEWAY_BASE_URL:?set B3IQ_GATEWAY_BASE_URL}": "${B3IQ_GATEWAY_KEY_FILE:?set B3IQ_GATEWAY_KEY_FILE}"cfg="$(mktemp)"chmod 600 "$cfg"trap 'rm -f "$cfg"' EXIT{ printf 'url = "%s/v1/models"\n' "${B3IQ_GATEWAY_BASE_URL%/}" printf 'header = "Authorization: Bearer %s"\n' "$(sed -n '1p' "$B3IQ_GATEWAY_KEY_FILE")"} > "$cfg"curl --fail --silent --show-error --config "$cfg"
/v1/models is intentionally narrow. It lists only models with at least one
route-eligible public profile backed by observed benchmark evidence.
Chat Completion
bash: "${B3IQ_GATEWAY_BASE_URL:?set B3IQ_GATEWAY_BASE_URL}": "${B3IQ_GATEWAY_KEY_FILE:?set B3IQ_GATEWAY_KEY_FILE}"cfg="$(mktemp)"chmod 600 "$cfg"trap 'rm -f "$cfg"' EXIT{ printf 'url = "%s/v1/chat/completions"\n' "${B3IQ_GATEWAY_BASE_URL%/}" printf 'request = "POST"\n' printf 'header = "Authorization: Bearer %s"\n' "$(sed -n '1p' "$B3IQ_GATEWAY_KEY_FILE")" printf 'header = "Content-Type: application/json"\n'} > "$cfg"curl --fail --silent --show-error --config "$cfg" --data-binary @- <<'JSON'{ "model": "Qwen3.6-35B-A3B-UD-Q5_K_XL.gguf", "messages": [{ "role": "user", "content": "Say hello from B3IQ." }], "max_tokens": 64}JSON
javascriptimport { readFileSync } from "node:fs";const baseURL = process.env.B3IQ_GATEWAY_BASE_URL;const token = readFileSync(process.env.B3IQ_GATEWAY_KEY_FILE, "utf8").trim();const response = await fetch(`${baseURL}/v1/chat/completions`, { method: "POST", headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, body: JSON.stringify({ model: "Qwen3.6-35B-A3B-UD-Q5_K_XL.gguf", messages: [{ role: "user", content: "Say hello from B3IQ." }], max_tokens: 64 })});console.log(await response.json());
Streaming
Set stream: true to request SSE streaming. Customer-billed hosted streaming
proxies the selected node stream while parsing final usage and b3iq.receipt_hash
metadata for billing and receipt settlement.
json{ "model": "Qwen3.6-35B-A3B-UD-Q5_K_XL.gguf", "messages": [{ "role": "user", "content": "Stream a short response." }], "stream": true}
Billing And Policy
Hosted chat can fail closed when:
- No healthy candidate passes route, protocol, model, benchmark, and policy gates.
- The gateway key lacks scope or a usable customer identity.
- Customer balance is insufficient.
- The request exceeds max price, model allowlist, route tier, or spend cap.
- Router or customer rate limits are exceeded.
- An incident control pauses a route class, node, or payout path.
See Errors for stable machine codes.
Headers
| Header | Direction | Description |
|---|---|---|
| Authorization | Request | Bearer hosted gateway key |
| Idempotency-Key | Request | Optional for paid gateway requests. Stored only as a hash. |
| X-B3IQ-Router-Dispatch-Mode | Response | Routed response dispatch mode |
| X-B3IQ-Router-Node-ID | Response | Selected node ID when policy exposes it |
| X-B3IQ-Receipt-Hash | Response | Receipt hash returned by the selected node |
Customer-owned gateway keys can carry billing ownership. Do not also send raw customer headers with those keys unless an operator smoke path explicitly requires it.
