Coverage-by-construction LLM governance — architecture & integration reference
CF's /api/v1/verify endpoint is a voluntary checkpoint — clients call it before calling their LLM. That model is honest only when clients remember every call. The Gateway closes that gap by making CF the network endpoint the client's LLM SDK points at. One config line changes; every prompt physically routes through CF; there is no other path. Coverage is no longer a procedural promise — it is an architectural property.
/verify vs /batch-verifyThe EU AI Act, Article 12 requires a complete record of system decisions. "Complete" means every call — not "every call our integration covered." The audit answer "we audit traffic that calls us" is procedural; an auditor will ask "how do you know that's all of it?" Today, you cannot answer that question with proof.
Three failure modes the voluntary-checkpoint pattern can't prevent:
In every case, the audit ledger looks cleaner than reality — and in discovery, the gap between "what's in the ledger" and "what your CFO billed for from OpenAI" becomes the plaintiff's exhibit.
The gateway is the architectural fix: the LLM's URL becomes ours. Code that doesn't call us doesn't reach an LLM.
┌─────────────────────────────────────────────────────────────────────┐
│ Client application (Python, JS, Go, no-code tool, curl, anything) │
│ │
│ client = OpenAI(api_key="sk-...", │
│ base_url="https://cognitivfusion.com/...gateway") │
│ client.chat.completions.create(...) ← unchanged code │
└─────────────────────────────────────────────────┬───────────────────┘
│ HTTPS
▼
┌─────────────────────────────────────────────────────────────────────┐
│ CognitivFusion Gateway │
│ │
│ 1. Auth: CF tenant key (Authorization: Bearer) │
│ 2. Validate request shape (block stream:true, image, tool content) │
│ 3. PII scrub — Stage 1 regex + Stage 2 NER + vault tokenisation │
│ 4. Ingress verify — regex engine + sync LLM judge │
│ ├─ blocked → return provider-shaped refusal, never forward │
│ └─ passed/flagged → continue │
│ 5. Forward to upstream with client's provider key (x-upstream-key) │
│ 6. Receive upstream response │
│ 7. Egress verify — regex engine (judge async-shadowed in v0) │
│ 8. PII restore — replace tokens with original values │
│ 9. Audit — ONE hash-chained ledger row, ingress + egress + policy │
│ 10. Return provider-shaped response with _cf_audit_id annotation │
└─────────────────────────────────────────────────┬───────────────────┘
│ HTTPS (client's key)
▼
┌─────────────────────────────────────────────────────────────────────┐
│ Upstream LLM provider (OpenAI, Anthropic, Groq, Azure, etc.) │
│ BYOAPI — the client's provider key passes through CF unchanged │
└─────────────────────────────────────────────────────────────────────┘
Every step from 3 onwards reuses the existing governance pipeline. The gateway is a new entry point, not a new engine.
| Endpoint | Shape | Providers covered via this one path |
|---|---|---|
POST /api/v1/gateway/openai/v1/chat/completions |
OpenAI Chat Completions | OpenAI · Azure OpenAI · Groq · Together · Fireworks · OpenRouter · Mistral API · xAI · Anyscale · DeepInfra · vLLM · Ollama · LM Studio · Voiceflow/Botpress OpenAI connectors · most "OpenAI-compatible" self-hosts |
POST /api/v1/gateway/anthropic/v1/messages |
Anthropic Messages | Anthropic API (direct Claude) · Amazon Bedrock via Anthropic SDK · Claude Platform on AWS |
/v1/chat/completions shape became the de-facto LLM API lingua franca — most LLM startups copy it so existing tooling works without changes. Direct Claude is the other dominant pattern in regulated industries.
| Header | Carries | Used for | Stored? |
|---|---|---|---|
Authorization: Bearer <cf_key> |
The client's CF tenant key (e.g. sk_hr_dev_...) |
Authenticate to CF, attach decision to the right tenant, bill the right account, write to the right ledger | SHA-256 hash only (Rule #3) |
x-upstream-key: <provider_key> |
The client's LLM provider key (sk-... / sk-ant-... / etc.) |
Forwarded verbatim to the upstream LLM in the appropriate header for that provider | Never persisted — passes through memory only |
x-upstream-base-url: <url> (optional) |
Override upstream destination (e.g. https://api.groq.com/openai, https://<tenant>.openai.azure.com) |
Use the OpenAI shape against a non-OpenAI provider, or hit a self-hosted endpoint | Only a SHA-256 hash of the base URL is written to the audit row (for routing diff detection) |
from openai import OpenAI
client = OpenAI(
api_key="sk-your-openai-key", # passes through to OpenAI
base_url="https://staging.cognitivfusion.com/api/v1/gateway/openai/v1",
default_headers={
"Authorization": "Bearer sk_hr_your_cf_tenant_key", # overrides OpenAI's Authorization
"x-upstream-key": "sk-your-openai-key",
},
)
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Draft a JD for a senior backend engineer."}],
)
print(response.choices[0].message.content)
print("CF audit id:", response.model_extra.get("_cf_audit_id"))
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "sk-your-openai-key",
baseURL: "https://staging.cognitivfusion.com/api/v1/gateway/openai/v1",
defaultHeaders: {
"Authorization": "Bearer sk_hr_your_cf_tenant_key",
"x-upstream-key": "sk-your-openai-key",
},
});
const r = await client.chat.completions.create({
model: "gpt-4",
messages: [{ role: "user", content: "Draft a JD for a senior backend engineer." }],
});
Most providers (Groq, Together, Fireworks, OpenRouter, Mistral) speak the OpenAI shape. Use the same endpoint with x-upstream-base-url:
curl https://staging.cognitivfusion.com/api/v1/gateway/openai/v1/chat/completions \
-H "Authorization: Bearer sk_hr_your_cf_tenant_key" \
-H "x-upstream-key: gsk-your-groq-key" \
-H "x-upstream-base-url: https://api.groq.com/openai" \
-H "Content-Type: application/json" \
-d '{"model":"llama-3.3-70b","messages":[{"role":"user","content":"Hello"}]}'
from anthropic import Anthropic
client = Anthropic(
api_key="sk-ant-your-anthropic-key",
base_url="https://staging.cognitivfusion.com/api/v1/gateway/anthropic",
default_headers={
"Authorization": "Bearer sk_hr_your_cf_tenant_key",
"x-upstream-key": "sk-ant-your-anthropic-key",
},
)
msg = client.messages.create(
model="claude-opus-4-8",
max_tokens=1024,
messages=[{"role": "user", "content": "Summarise the candidate's recent roles."}],
)
print(msg.content[0].text)
curl https://staging.cognitivfusion.com/api/v1/gateway/anthropic/v1/messages \
-H "Authorization: Bearer sk_hr_your_cf_tenant_key" \
-H "x-upstream-key: sk-ant-your-anthropic-key" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model":"claude-opus-4-8",
"max_tokens":1024,
"messages":[{"role":"user","content":"Summarise the candidate."}]
}'
You do not need any SDK. The gateway is a normal HTTPS endpoint. Any client that can make POST requests can use it:
Most tools expose an "API URL" or "Custom endpoint" setting on their AI/LLM connector. Change two things:
https://staging.cognitivfusion.com/api/v1/gateway/openai/v1 (or /anthropic)Authorization: Bearer <cf_key> and x-upstream-key: <your_provider_key>Nothing in the chatbot's logic changes. Every conversation now lands in CF's audit ledger.
Same pattern as the curl example above. Anything that can fetch() can use the gateway.
| Step | What runs | What happens |
|---|---|---|
| 1 | Auth | CF tenant key validated; tenant context attached to the request |
| 2 | Shape validation | stream:true → 400 · image/tool content → 400 · empty prompt → 400 |
| 3 | PII gateway | Stage 1 regex (PAN/Luhn, SSN, NINO, email, phone, IBAN) + Stage 2 NER (names, locations, orgs via Haiku); replaces with vault tokens |
| 4 | Ingress verify (regex) | Deterministic engine fires CF cluster codes against the scrubbed text; returns decision + audit_codes + clusters + risk_metrics |
| 5 | Tenant thresholds | Deployer-configured max_harm/max_bias/hitl_harm/hitl_bias applied (Art 14) |
| 6 | Sync LLM judge | Claude Haiku judges semantically; stricter-of-(regex, judge) wins; fail-closed if judge unavailable |
| 7 | Blocked path | Return provider-shaped refusal with codes in content_filter (OpenAI) or stop_reason: refusal (Anthropic); never forward to upstream |
| 8 | Forward | Original request body + client's upstream key sent to upstream LLM; client's key never persisted |
| 9 | Egress verify (regex) | Same regex engine runs on the upstream's response text |
| 10 | PII restore | Vault tokens replaced with original values before response reaches client |
| 11 | Audit | One hash-chained gateway_call row written; both verdicts + tenant policy + governance stamp inside |
| 12 | Return | Provider-shaped response with _cf_audit_id + _cf_egress_verdict annotations |
Every gateway round-trip writes exactly one row of event_type = 'gateway_call' to audit_ledger. The row's event_data JSONB contains:
{
"provider": "openai" | "anthropic",
"upstream_path": "/v1/chat/completions",
"upstream_base_url_hash": "9a3...", // sha256[0..16) — never the URL itself
"model": "gpt-4",
"ingress_verdict": "passed" | "flagged" | "blocked",
"egress_verdict": "passed" | "flagged" | "blocked" | null,
"forwarded_to_upstream": true | false,
"upstream_status": 200,
"upstream_latency_ms": 412,
"total_latency_ms": 487,
"ingress_codes": ["CF-AGE_BIAS", ...],
"egress_codes": [...],
"ingress_clusters": ["AGE_BIAS", ...],
"ingress_violations": [
{ "code": "CF-AGE_BIAS", "reason": "Age bias in a hiring directive",
"impact": "...", "framework": "CF" }
],
"judge_outcome": { "decision": "passed", "provider": "openrouter", ... },
"judge_error": null,
"token_usage": { "input": 32, "output": 184 },
"tenant_policy": { "max_harm": 50, "max_bias": 50,
"hitl_harm": 10, "hitl_bias": 10 },
"governance_stamp": { // injected by appendAudit()
"engine_fingerprint": "9ab36261bee16445",
"judge_prompt_hash": "...",
"judge_primary_model": "anthropic/claude-haiku-4-5",
"corpus_hash": "...",
"app_version": "0.1.0",
"build": "K_REVISION-..."
}
}
The row's current_hash = SHA256 of a stored record holding the previous hash, timestamp, event type, initiator and event_data, chained from the prior row. The verifier checks the row's fields still match that record, so an edited field fails verification (rows from before 24 November 2026 prove linkage only). The hash chain covers every field including tenant_policy and governance_stamp, so the verdict is reproducible against the exact rule set and threshold configuration in force at decision time (Art 15(2)).
| Limit | What v0 does | Why deferred | Target |
|---|---|---|---|
Streaming (stream: true) |
Returns 400 with explicit error | SSE pass-through with mid-stream egress governance has subtle ordering/buffering bugs that cost more than they save in v0 | Sprint 1 |
| Non-text content (images, tool_use blocks) | Returns 400 with explicit error | PII scrub and regex governance currently operate on text; vision/tool semantics need a separate adapter layer | Sprint 2 |
| Google Gemini / Cohere / native Bedrock shapes | 404 — not exposed | OpenAI + Anthropic shapes cover ~90% of clients; the rest will be added by demand | Sprint 1 |
| Egress LLM judge (sync) | Regex egress runs sync; judge runs as a shadow (logged but does not gate) | Doubling the round-trip latency to wait for an egress judge is rarely worth it. Art 12 wants record, not block, on output | Configurable per-tenant in Sprint 2 |
| Provider failover (OpenAI down → fall back to Anthropic) | Fail-closed: returns 503 + audit row marking upstream_unavailable |
Failover requires per-tenant rules and prompt translation — bigger feature, separate decision | Sprint 2 |
/verify vs /batch-verifyAll three remain. They are different entry points to the same governance core. Pick the right one per use case:
| Endpoint | Use when | Client controls |
|---|---|---|
POST /api/v1/verify |
The client wants explicit, code-visible governance — usually an internal Python script, the CF dashboard "Test" panel, or a recruiter typing into a CF-aware UI. | Client decides whether to forward to an LLM based on the verdict. |
POST /api/v1/admin/batch-verify |
Bulk résumé screening — N résumés in, N decisions out, all audited. | Operator-driven workflow, not a live LLM pipeline. |
POST /api/v1/gateway/<provider>/... |
The client's app uses an LLM SDK. They want every call governed without code changes beyond base_url. |
CF forwards to the LLM if and only if governance permits; client app is unaware of the indirection. |
"How many AI calls did you make this month?"
Client: "We don't know. CF only has the ones we sent."
The gap between OpenAI's bill and CF's ledger is what the auditor asks about.
"How many AI calls did you make this month?"
Client: "127,432 — every one of them is in CF's ledger. Their base URL points at CF; bypassing means literally rewriting their integration."
| Sprint | What ships |
|---|---|
| v0 (this release, 12 Jun 2026) | OpenAI shape · Anthropic shape · sync ingress judge · regex egress · BYOAPI · single audit row · governance stamp + tenant policy embedded |
| Sprint 1 (post-launch, ~2 weeks) | SSE streaming pass-through · Google Gemini shape · /gateway/custom escape hatch (configure any upstream URL) · token-cost meter on dashboard · coverage-attestation metric (governed_calls / total_provider_calls) |
| Sprint 2 | Multimodal (image/tool content) · per-tenant egress judge mode (sync / shadow / off) · provider failover · regional routing · per-provider rate limit propagation |
Approximate v0 overhead per request, p99:
For voice / sub-second UX, set sync_llm_judge=false on the tenant (judge runs in shadow). Cuts overhead to < 30 ms but loses synchronous semantic gating.
The gateway adds CF as a hard dependency for the client's AI features. upstream_unavailable → 503 (fail-closed; no ungoverned passthrough). If the client's risk profile cannot tolerate this, they should continue using /verify as a voluntary checkpoint and accept the coverage gap.
x-upstream-key): in-memory only; never persisted, never logged, never returned. The audit row records a SHA-256 hash of the upstream base URL, not the URL itself.gateway_call row is identical in integrity guarantees to verify."Demonstrate that your audit trail covers every AI-driven decision your firm made under Annex III in the relevant period."
Without the gateway: "Here is the record of every call our integration sent to CF. We instructed developers to call CF before every LLM call."
With the gateway: "Here is the audit ledger. Every LLM call our firm made this period went through CF — there is no other path from our application to an LLM. The completeness is an architectural property, not a procedural one. The hash chain proves the ledger is unaltered. Each row records the rule set, judge prompt, and tenant thresholds in force at decision time, so any verdict can be independently reproduced."
That second answer is the one that closes the matter.