> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formal.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LLM Gateway

> Log every prompt and tool call, enforce policies on LLM traffic, and cap spend, on the device or in your network

## Overview

The LLM Gateway puts Formal in the path of traffic to LLM providers such as `api.anthropic.com` and `chatgpt.com`.
Formal logs each request and response, evaluates your [policies](https://docs.formal.ai/docs/glossary/index.md#policy), and forwards the request to the provider.

Formal can proxy LLM traffic in two places.

| | Formal Endpoint | Connector |
| - | - | - |
| Covers | AI apps and coding agents on laptops, VMs, and Pods | Applications in your infrastructure |
| How traffic arrives | [Transparent Mode](https://docs.formal.ai/docs/guides/client-apps/transparent-mode.md) intercepts it. No app changes. | The app calls the Connector hostname instead of the provider |
| Set up | A [network rule](https://docs.formal.ai/docs/guides/network-rules.md) that matches `llm` traffic | An [LLM resource](https://docs.formal.ai/docs/guides/core-concepts/resources/llm.md) on a Connector listener |

```text theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
your app  →  Formal Endpoint  →  LLM provider API
your app  →  Formal Endpoint (optional)  →  Connector  →  LLM provider API
```

## What Formal captures

* **Model and provider** for each request
* **Messages:** the full prompt and completion text
* **Tool calls,** with names, arguments, and results
* **Token usage:** prompt, completion, and total tokens

Streaming responses are reassembled before logging.
To encrypt or drop LLM content in logs, create a [log schema](https://docs.formal.ai/docs/guides/observability/log-schemas.md#llm-content).

## What you can enforce

Policies run on LLM traffic at the session, request, and response stages.

| Goal | Guide |
| - | - |
| Block a connection before it reaches the provider | [LLM policy inputs](https://docs.formal.ai/docs/guides/policies/evaluation.md#llm-resources) |
| Redact SSNs and other sensitive text from prompts | [Mask PII and Secrets](https://docs.formal.ai/docs/guides/policies/mask-pii.md) |
| Allow only your organization's provider account | [Restrict Anthropic Sign-Ins to One Org](https://docs.formal.ai/docs/guides/example-use-cases/restrict-anthropic-sign-ins.md) |
| Cap what each user spends | [Control LLM Spend](https://docs.formal.ai/docs/guides/ai-governance/spend.md) |
| Score conversations for alignment and risk | [Assessments](https://docs.formal.ai/docs/guides/core-concepts/assessments.md) |

## Get started

**1. Create an LLM resource**

Add one resource per provider API. See [Creating LLM Resources](https://docs.formal.ai/docs/guides/core-concepts/resources/llm.md#creating-llm-resources).

**2. Route traffic**

On devices, enable [Transparent Mode](https://docs.formal.ai/docs/guides/client-apps/transparent-mode.md) and add a network rule for `llm` traffic.
For applications, point them at a Connector. See [Connecting](https://docs.formal.ai/docs/guides/core-concepts/resources/llm.md#connecting).

**3. Verify**

Send a prompt from an AI harness. Open [Logs](https://app.formal.ai/logs) and filter on `resource.technology:llm`.

## Govern AI Harnesses

Formal recognizes these harnesses by their signed process identity, so rules and policies can target each one.

| Harness | Guide |
| - | - |
| Claude Code, Claude Desktop | [Govern Claude with Formal](https://docs.formal.ai/docs/guides/ai-governance/tools/claude.md) |
| Codex | [Govern ChatGPT and Codex with Formal](https://docs.formal.ai/docs/guides/ai-governance/tools/chatgpt.md) |
| Cursor | [Govern Cursor with Formal](https://docs.formal.ai/docs/guides/ai-governance/tools/cursor.md) |
| GitHub Copilot CLI, GitHub Copilot for Xcode | [Govern GitHub Copilot with Formal](https://docs.formal.ai/docs/guides/ai-governance/tools/copilot.md) |
| Devin | [Prevent Cloud Agents from Auto-Merging PRs](https://docs.formal.ai/docs/guides/example-use-cases/formal-endpoint-cloud-agents.md) |
| Grok | [Install Formal Endpoint on Grok Bot](https://docs.formal.ai/docs/guides/example-use-cases/formal-endpoint-grok-bot.md) |
| OpenCode, Windsurf, Antigravity, Amp, Amazon Q Developer, Crush, Hermes Agent, Warp Agent CLI | [Known agent identities](https://docs.formal.ai/docs/guides/network-rules.md#known-agent-identities) |

A network rule with `process.is_agent` covers every harness in this table at once.
See [Write Network Rules](https://docs.formal.ai/docs/guides/network-rules.md#process-identity).

## Next Steps

> [card] [Monitor AI Usage](https://docs.formal.ai/docs/guides/ai-governance/usage.md)
>
> Chart clients, models, and providers

> [card] [Insights](https://docs.formal.ai/docs/guides/observability/insights.md)
>
> Triage AI-generated findings about LLM traffic

> [card] [Seal Claude Code OAuth tokens](https://docs.formal.ai/docs/guides/example-use-cases/seal-claude-code-oauth-tokens.md)
>
> Keep provider tokens encrypted on the device

> [card] [MCP Gateway](https://docs.formal.ai/docs/guides/core-concepts/connectors/mcp-gateway.md)
>
> Govern the tools those models call


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.