◆ KQAI · “QUAI” · K · Query · AI

The secure way
you query AI.

A hardened black box around [Ollama + model] — authenticated, encrypted, audited inference over a tiny, stable contract. Local, on the LAN, or over the web.

Raw Ollama has no auth and no TLS. KQAI is the missing layer: it turns an open port into a guarded, auditable one — and never lets the AI make the call.

TLS always
Encrypted on the wire — even on localhost. Cert-pinned.
Three verbs only
generate · stream · health. Nothing else is reachable.
Boxed model
Ollama bound to loopback. The model never leaves the box.
Audited
Every request logged. Notarize to PORTAGE, don't reinvent it.
01Why it exists

An open model port is a door with no lock.

KAILib can already point an app's model call at an Ollama anywhere — localhost, a LAN box, a machine on the web — by config alone. But Ollama's native API has no authentication and no TLS, and it exposes model management next to inference. Reaching a remote Ollama directly means plaintext prompts on the wire, an open door for anyone who finds the port, and no record that anything happened.

KQAI sits in front of [Ollama + model] and makes that hop secure, narrow, authenticated, encrypted, and auditable — without the calling app changing a single line.

🔒
The governing rule holds. KQAI moves tokens; it never decides. Grounding stays with SYNTHEKOS, routing stays with PORTAGE. KQAI's product is policy at the edge — auth, transport, audit — not model or product logic.
02The contract

Small enough to be safe. Three verbs, two transports.

Anything not on this list is not reachable — no model pull/delete, no config passthrough, no arbitrary Ollama API. That narrowness is the security property. The shapes mirror KAILib's own types, so the client maps 1:1.

generate
POST /v1/generate · REST

One-shot completion. Returns a KAILib-shaped Completion: text, model, token counts.

stream
WSS /v1/stream · WebSocket

Token-by-token streaming. Not cached, not retried mid-flight — a half-emitted stream can't be replayed.

health
GET /v1/health · REST

Cheap and pollable — reachability, model, breaker state, load. What a router hits to pick a box.

⚠︎
Explicitly out of scope, forever: model pull/create/delete, listing arbitrary Ollama endpoints, raw passthrough, embeddings/RAG. Keeping this list short is a feature.
03Architecture

One box. The model, boxed inside it.

The only port on the network is KQAI's TLS listener. Ollama is bound to loopback — nothing reaches the model except KQAI itself. And because the KAILib-side connector is just another LLMProvider, moving from a local Ollama to a fleet of KQAIs is zero app-code change.

KAILib app AIBBProvider client.ask("…") KQAI authn · authz quota · audit on kai_lib core Ollama + model 127.0.0.1:11434 kai_lib store → PORTAGE pinned TLS / mTLS REST · WSS loopback only
transport
TLS everywhere, even on localhost. The caller pins KQAI's certificate fingerprint — a swapped or forged cert fails the connection.
auth
mTLS preferred (client cert, no shared secret on the wire); bearer token as the simpler fallback for a local sidecar.
authz
Per-identity model allowlist + quota + a server-enforced max_tokens cap. Appliances OOM on courtesy.
resilience
The model call runs through KAILib's core: retry · circuit breaker · concurrency limit. A dead model trips the breaker instead of surfacing as a bad answer.
audit
Every request → one infer event (identity, model, token counts, latency — not the prompt by default). Optional emit to PORTAGE for an offline-verifiable receipt.
04In use

From “hello” to a failover fleet.

Same KAILib surface throughout — client.ask(...) never changes. What changes is the box behind it.

Simple — a local sidecar

Stand a KQAI up in front of your own Ollama with one token. On the app side, point an AIBBProvider at it and call it like any model.

serve_kqai.py — the boxbuilt · Phase 1
from kqai.config import KQAIConfig, Identity
from kqai.server import KQAIServer

cfg = KQAIConfig(
    tls_cert="cert.pem", tls_key="key.pem",   # TLS is not optional
    model="llama3.1",                          # the one model this box serves
    tokens={"workshop-secret": Identity("workshop-app", models=["llama3.1"])},
)
KQAIServer(cfg).serve()          # https://127.0.0.1:8443 — audited, on kai_lib
app.py — the callerbuilt · Phase 1
from kai_lib import LLMClient
from kai_lib.llm import AIBBProvider

client = LLMClient(AIBBProvider(
    "https://127.0.0.1:8443",
    token="workshop-secret",
    pin="sha256/…",          # pin the box's cert — no MITM
    model="llama3.1"))

print(client.ask("What's the torque spec for the caliper bolt?"))
# → "42 Nm" — over TLS, authenticated, and logged on the box

More complex — mTLS, quotas, and a failover fleet

Give each caller a client certificate and its own model allowlist + cap. Then compose several KQAIs behind one RouterProvider that prefers local → LAN → web and routes around a dead box on its circuit breaker.

box.py — an appliance for several appsdesign · Phase 3
cfg = KQAIConfig(
    tls_cert="box.pem", tls_key="box.key",
    model="llama3.1",
    ollama_host="http://127.0.0.1:11434",   # boxed — loopback only
    max_tokens=1024,                       # server-enforced ceiling
    tokens={
        "svc-dispatch": Identity("dispatch", models=["llama3.1"], max_tokens=512),
        "svc-report":   Identity("reporting", models=["llama3.1"]),
    },
)
fleet.py — three boxes, automatic failoverdesign · Phase 4
from kai_lib import KAIApp, LLMClient
from kai_lib.llm import RouterProvider, AIBBProvider

def box(url):
    return AIBBProvider(url, client_cert="client.pem",
                        ca="ca.pem", pin="sha256/…")   # mutual TLS

router = RouterProvider([
    box("https://127.0.0.1:8443"),     # local sidecar
    box("https://ai-box.lan:8443"),    # LAN appliance
    box("https://infer.koperwas.com"),  # web endpoint
], strategy="prefer_local")          # local → LAN → web

app = KAIApp(llm=LLMClient(router))
print(app.llm.ask("hello"))
# pull the local box's plug → the LAN box answers. No app code changed.
Each AIBBProvider carries its own circuit breaker, so a tripped box drops out of the rotation and the router moves on — failover from machinery KAILib already has, not new code.

Streaming — hands-free, token by token

The same secured channel, upgraded to a WebSocket for live tokens — the transport a voice/eyes-free client wants.

stream.pybuilt · Phase 2
for tok in client.stream("Walk me through the failover procedure."):
    speak(tok)          # WSS /v1/stream — not cached, not retried mid-flight
05Possibilities

What a locked door on the model makes possible.

Once the inference hop is authenticated, encrypted, and audited, whole classes of deployment that were “don't put that on the wire” become ordinary.

The engine under SYNTHEKOS

SYNTHEKOS's own to-do list says: “encrypt the hop to a separate Ollama box.” That's precisely KQAI. Point the sovereign grounded-AI appliance at a KQAI and its model can live on another, hardened box — while grounding and abstention stay entirely SYNTHEKOS's.

closes a written SYNTHEKOS gap
A provable inference trail

Every infer event can emit to PORTAGE for a hash-chained, offline-verifiable receipt — who queried which model, when, and with what result. KQAI records; PORTAGE notarizes. The compliance artifact a regulated buyer actually wants.

KQAI records · PORTAGE notarizes
A machine-to-model API

Sensors, dashboards, and test harnesses get an authenticated key and a stable three-verb contract — grounded, capped, audited answers — without ever touching a raw model port.

EUser-style machine identity
One model, many tenants

Per-token identity, allowlist, and quota let a single boxed model serve several apps or teams, each seeing only its own models and each held to its own cap — on hardware that never leaves the building.

policy at the edge
Sovereign, off the LAN

Behind a real cert or a tunnel with Access in front, the same box becomes a private web endpoint — authenticated and audited — with the model still boxed on loopback. Sovereign doesn't have to mean “only on this desk.”

local · LAN · web — same code
Swap the model, not the app

Because a KQAI is just another LLMProvider, upgrading a model, moving it to a beefier box, or splitting traffic across a fleet is a config change. The application never learns the difference.

the KAILib provider seam
Honest status. Phases 1–2 — REST generate + health and WSS token stream, over TLS, with token auth, model allowlist, max_tokens cap, cert pinning, and audit — are built and tested on KAILib (proven end-to-end on localhost with a fake provider; a real-Ollama run is still pending). Mutual-TLS + per-identity authz (Phase 3) and the RouterProvider fleet (Phase 4) are designed and on the roadmap. The badges above say which is which — a system whose whole claim is “it tells you the truth” starts with the page doing the same.