LLM governance / policy control planeDocs

Policy Gateway connectors

Open-source connectors for Next.js, FastAPI, LangChain, and LiteLLM to route traffic through Policy Gateway.

These connectors are small, open-source helpers that route traffic through the Policy Gateway AI endpoint.

Each connector includes a 5-minute quickstart, local dev mode, and sample log output for dashboards.

Updated Jan 13, 2026Policy Gateway

Quick start

Service notes

Connector matrix

#

Next.js (App Router) quickstart

#
Next.js (App Router) quickstart
import { createPolicyGatewayRoute } from "@/app/lib/policyGatewayRoute";

export const POST = createPolicyGatewayRoute({
  apiKey: process.env.POLICY_GATEWAY_KEY,
  policyId: "policy-gateway",
  policyProjectId: "support-bot",
});

FastAPI quickstart

#
FastAPI quickstart
from fastapi import FastAPI, Request
from policy_gateway import policy_gateway_client_from_env, policy_user_from_request

app = FastAPI()
client = policy_gateway_client_from_env()

@app.post("/chat")
async def chat(request: Request):
    body = await request.json()
    policy_user = policy_user_from_request(request)
    return await client.chat_completions(body, policy_user=policy_user)

LangChain quickstart

#
LangChain quickstart
from policy_gateway_langchain import build_policy_gateway_chat

llm = build_policy_gateway_chat(
    api_key="YOUR_POLICY_KEY",
    policy_id="policy-gateway",
    policy_user="user-12345",
    policy_project_id="support-bot",
)

response = llm.invoke("Summarize our refund policy.")
print(response.content)

LiteLLM quickstart

#
LiteLLM quickstart
from policy_gateway_litellm import policy_completion

response = policy_completion(
    messages=[{"role": "user", "content": "Summarize our refund policy."}],
    policy_id="policy-gateway",
    policy_user="user-12345",
    policy_project_id="support-bot",
)

print(response["choices"][0]["message"]["content"])

Local dev mode

#
Local dev mode
export POLICY_GATEWAY_BASE_URL=http://localhost:5000/policy

Sample log output

#
Sample log output
2026-01-13T10:12:42Z policy_id=policy-gateway decision=rewrite reason_code=REWRITE policy_user=user-12345 policy_project_id=support-bot

Common errors & fixes