Skip to content
All guides

LLM gateway

Point direct API use at Trakkwise instead of Anthropic or OpenAI. Each person or service gets its own gateway key; Trakkwise forwards each call with the organization's own vendor key and records who used which model and how many tokens. Answers come back unchanged, streams included. Prompts and answers pass through and are never stored.

Set it up (Settings → Gateway, admins)

  1. Your API keys. Add the Anthropic and/or OpenAI API key the gateway calls the vendor with. Use keys made for the gateway, so its calls are easy to tell apart on the vendor's bill. They're kept encrypted (SSO_SECRET_KEY) and never shown again.

  2. Gateway keys. Create one per person (with their work email) or per service (no email). The key (tkg_…) is shown once.

  3. Point the SDKs at it. Set the base URL and use the gateway key as the API key:

    SDK Base URL
    Anthropic https://<api host>/gateway/anthropic
    OpenAI https://<api host>/gateway/openai/v1
    new Anthropic({ apiKey: "tkg_…", baseURL: "https://<api host>/gateway/anthropic" });
    new OpenAI({ apiKey: "tkg_…", baseURL: "https://<api host>/gateway/openai/v1" });
    

What it supports

  • Anthropic Messages (POST /v1/messages), OpenAI Chat Completions (POST /v1/chat/completions) and OpenAI Responses (POST /v1/responses), streamed or not. Other endpoints answer 404.
  • The key goes where the SDK already sends one: x-api-key or Authorization: Bearer. Either works on both.
  • Forwarded: the body, content-type, accept, anthropic-version, anthropic-beta, openai-beta. Never the caller's credentials or cookies.
  • Streamed Chat Completions are sent with stream_options.include_usage: true (unless the caller set it), so their tokens can be counted. The extra last chunk has an empty choices array, which the SDKs expect.
  • Errors come back in the vendor's own shape: the vendor's errors unchanged; the gateway's own (unknown or revoked key, no vendor key set, vendor unreachable) as {"type":"error","error":{…}} for Anthropic and {"error":{…}} for OpenAI.
  • Limits: 600 calls a minute per gateway key (RATE_LIMIT_GATEWAY_*), 32 MB per request, 10 minutes per call.

What it records

  • Per call, kept 30 days (Settings → Gateway → Recent calls): when, which key and person, provider, endpoint, model, streamed or not, status, tokens (in, out, cached, cache writes), time taken, and the gateway's reason when it failed. Never the prompt, the answer or the vendor's error text.
  • Per day, person and model, in the usage records (source gateway): requests and tokens. They show in Spend (the vendor's bill, from the Anthropic or OpenAI integration, is split between people by these tokens), Efficiency and Savings (premium models used for short requests).

Deploying

The gateway is part of the API: no new service. The load balancer's idle timeout is 10 minutes so a long, unstreamed call isn't cut off, and the WAF's common rule set doesn't inspect /gateway/ bodies (prompts are full of code and markup it would block); IP reputation and known bad inputs still apply. Gateway keys are redacted from WAF logs.

Rules for gateway calls

Checked before a call is forwarded, in this order:

  1. Allowed models (Settings → Gateway): when the list isn't empty, other models are refused. A dated snapshot of an allowed model counts as it.
  2. Budgets (Settings → Budgets), when "Stop calls while a budget that covers them is over" is on: the organization's, the API's (anthropic-api, openai-api) or the person's. Service keys have no person, so only the first two apply to them.
  3. Policy rules (Policies) with the LLM gateway as a target, or no target: over the newest message the caller wrote, checked with the same sensitive-data detectors as the browser extension (packages/policy/src/dlp.ts). Earlier turns are resent with every call and were checked when they were new. The subject is kind: prompt, the tool anthropic-api or openai-api, category model_api, and the person of the key.
    • block: refused (403, in the vendor's error format, with the rule's message).
    • warn: an API call can't stop to ask, so it goes through, recorded as going ahead (warn_continued).
    • coach, monitor and test mode: go through, recorded.

A call with sensitive data, or one a rule acted on, also makes a prompt event (source gateway) like the extension's, so it shows in Violations and Risk. With prompt capture on (Settings → Privacy), gateway calls are kept under the same mode as browser prompts, secrets removed first. Changes to these rules reach the gateway within 30 seconds.