Skip to main content
POST

AI Gateway

The AI Gateway is KnoxCall’s AI-native proxy layer. It sits between your applications and upstream AI providers (Anthropic and OpenAI are the configurable providers; Bedrock is supported only as a shape-translation target), providing:
  • Phantom tokens — short-lived DPoP-bound capability tokens; your application never holds a raw provider API key.
  • Streaming PII redaction — Aho-Corasick + Presidio detector stack with a configurable hold-back buffer.
  • Prompt injection firewall — built-in heuristic patterns + tenant-supplied regex/keyword rules; optional canary token injection detects system-prompt extraction.
  • Budget enforcement — per-agent daily/monthly USD caps with configurable overage actions.
  • Shape translation — automatic Anthropic ↔ OpenAI request/response translation when routes target a different provider format.
  • Compliance packs — HIPAA Safe Harbor, GDPR, PCI-DSS, and SOC 2 packs install recognizers and audit-log alert rules in one operation.

Authentication

All AI Gateway proxy endpoints authenticate via phantom tokens — capability tokens minted for a specific agent. Send the token via any of the three accepted header schemes:
For DPoP-bound tokens, you must additionally include a valid DPoP header on every request. Gateway and agent CRUD, token minting, firewall policies, MCP servers and usage are control-plane operations and are served on two different surfaces: An earlier revision of this page said the control plane requires a session JWT and not an API key. That has been false since /v1/ai-gateway/* shipped: the /v1 surface authenticates with the same credentials as the rest of the Management API.

Execute AI request

The execute (data-plane) endpoint is served on your tenant’s proxy subdomain — https://{slug}.knoxcall.com (sandbox: https://sandbox-{slug}.knoxcall.com), not api.knoxcall.com. Use the agent_url returned when the agent was created as the base URL. Forwards the request to the agent’s configured primary route. The request body must be a valid JSON body for the upstream provider (Anthropic Messages API, OpenAI Chat Completions API, etc.). If the agent has streaming_enabled and the request asks the provider to stream — "stream": true in the body, or Gemini’s :streamGenerateContent endpoint — the response is streamed as SSE. An Accept: text/event-stream header on its own does not stream: it asks nothing of the provider, so the response is served buffered (and fully redacted). Streaming is available on the endpoints whose event stream KnoxCall redacts mid-stream — Anthropic /v1/messages, OpenAI-compatible /chat/completions, Gemini :streamGenerateContent — and is refused with 400 streaming_redaction_unsupported elsewhere (for example the OpenAI Responses API); send those requests without stream: true.

Request headers

Response headers

Firewall responses

When the prompt injection firewall blocks a request, HTTP 400 in the data plane’s one error envelope:
error and code always carry the same identifier — branch on either. Every refusal this endpoint can return, and whether to retry it, is on the errors page. The firewall always runs — the built-in heuristics cannot be disabled and they scan every request. What a policy decides is the outcome. With no firewall policy attached to the agent, the outcome is capped at warn: a match is recorded and the request still reaches the upstream. block requires a firewall policy attached to the agent with action: "block". Create one via POST /v1/ai-gateway/firewall-policies and set the agent’s firewall_policy_id.

Shape translation

When the caller’s provider format differs from the route’s target provider format, the AI Gateway translates automatically: Format is detected from the route’s target_base_url (e.g. api.anthropic.com → Anthropic format). Response shapes are translated back to match the caller’s expected format on the buffered path.

Canary token injection

When a firewall policy has canary_enabled: true, the gateway injects a kc_canary_<16hex> token into every system prompt before forwarding upstream. If the model echoes the token verbatim in its response (a sign of system-prompt extraction via prompt injection), the gateway:
  1. Emits an ai_gateway.canary_leak audit log entry at critical severity.
  2. Records the policy’s own action as firewall_outcome on the usage record — block when the attached policy’s action is block, otherwise warn. (Before AIGW-171 this was hard-coded to warn, so a tenant who had configured block read their own firewall report as saying the control had held.)
  3. On a block policy, refuses the response rather than serving it. A canary echo is not a heuristic guess about intent: the token is a value KnoxCall generated, put in the system prompt, and never gave the caller. Buffered, that is 400 canary_leak. Streamed, the 200 has already gone out, so the stream stops at the frame carrying the leak and ends with an event: error frame whose code is canary_leak — nothing after the leak is delivered, and anything sent before it contained no canary. The refusal reports a matched_count, never the token itself.
  4. Fires any compliance-pack alert rules listening on audit_action = 'ai_gateway.canary_leak'.
Either way the marker itself is spliced out of the body the caller receives ([REDACTED:CANARY]), on the buffered path and mid-stream — except in the monitor streaming mode, which passes the response through unredacted by design and only inspects it once it has finished.

Compliance packs

Install compliance packs via the Packs API or from the Admin UI. Each pack installs:
  1. PII recognizers — entity-type patterns for the detector stack.
  2. Alert rules — ai_gateway_event alerts that fire when specific audit actions appear.
Currently available packs: hipaa-safe-harbor, gdpr, pci-dss, soc2.

OpenTelemetry export

Set OTEL_EXPORTER_OTLP_ENDPOINT to enable per-request span export with GenAI semantic conventions:

Authorizations

Authorization
string
header
required

The AI data plane credential — a kp_-prefixed capability token, not a Management API credential. It is minted per agent (or per MCP resource) at POST /v1/ai-gateway/agents/{agentId}/tokens, or exchanged from a CI workload's OIDC token at POST /v1/oauth/token, and it is the ONLY credential /v1/ai/* accepts: an OAuth kc_ access token or a tk_ API key is refused there, and a kp_ token is refused on api.knoxcall.com.

Three header spellings are accepted, so an existing provider SDK can be pointed at the agent URL without rewriting its auth:

kp_live_ is refused on the sandbox host and kp_test_ on the Live host — the env segment is enforced, not cosmetic. DPoP-bound tokens additionally require a valid DPoP proof header on every request, signed over the canonical public URL rather than a rewritten Host.

A rejected credential answers 401/403 in the data-plane error envelope with the cause in code and in the X-Auth-Failure response header.

Path Parameters

agentSlug
string
required

The agent's slug. Selects the upstream route, the policies and the budget.

Pattern: ^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$
upstreamPath
string
required

The provider's own path, forwarded verbatim — including its slashes, which OpenAPI cannot express as a single path segment. v1/messages for Anthropic, v1/chat/completions for OpenAI-shaped providers, v1beta/models/{model}:generateContent for Gemini. Everything after /v1/ai/{agentSlug}/ is the upstream path (src/ai-gateway/route-matcher.ts), so the gateway adds no path of its own.

Body

application/json

The upstream provider's own request body, forwarded after screening.

The body is of type object.

Response

The provider's own response, passed through after response-side screening. text/event-stream when the call was streamed.

The response is of type object.