> ## 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.

# Restrict Anthropic Sign-Ins to One Org

> Inject Anthropic tenant restrictions so users can only sign in with your organization ID

## Overview

> [!TIP]
>
> The [Restrict Anthropic sign-ins](https://app.formal.ai/recipes/restrict-anthropic-sign-ins)
> recipe creates this network rule and policy for you. See
> [Recipes](https://docs.formal.ai/docs/guides/getting-started/recipes.md).

Anthropic [Tenant Restrictions](https://support.claude.com/en/articles/13198485-enforce-network-level-access-control-with-tenant-restrictions) let a proxy allowlist organization IDs. Your proxy injects `anthropic-allowed-org-ids` on Claude traffic. Anthropic then allows only those orgs for sign-in and API use.

Formal adds that header with a request-stage `rewrite` [policy](https://docs.formal.ai/docs/glossary/index.md#policy). A [network rule](https://docs.formal.ai/docs/guides/network-rules.md) selects the Anthropic traffic that the policy runs on. Users on the Formal Endpoint can sign in only with your Anthropic org. Personal Claude accounts and other orgs receive a 403 from Anthropic.

This guide uses the Formal Endpoint on macOS.

## Find your Anthropic organization ID

You need the UUID Anthropic shows for your org.

**1. Open Anthropic settings**

For Enterprise, go to **Settings** → **Account**, or **Organization settings** → **Organization**. For Console orgs, go to **Settings** → **Organization**.

**2. Copy the Organization ID**

Copy the UUID. It looks like `000a0000-a00a-00a0-a000-000000000000`.

See Anthropic's [Tenant Restrictions](https://support.claude.com/en/articles/13198485-enforce-network-level-access-control-with-tenant-restrictions) article for where the ID appears in each plan.

## Route Anthropic traffic through Formal

The Formal Endpoint must intercept Anthropic requests so the rewrite can run. A [network rule](https://docs.formal.ai/docs/guides/network-rules.md) selects that traffic.

**1. Enable Transparent Mode**

On macOS, install and start [Transparent Mode](https://docs.formal.ai/docs/guides/client-apps/transparent-mode.md):

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
formal transparent-proxy install
formal transparent-proxy enable
formal transparent-proxy status
```

**Verify:** the status command reports that Transparent Mode is running.

**2. Create the network rule**

Intercept Anthropic hostnames and classify them as LLM traffic.

> [tab] Control Plane
>
> 1. Navigate to [Network Rules](https://app.formal.ai/network-rules)
> 2. Create a rule named `anthropic-llm`
> 3. Paste the CEL below
> 4. Leave **Forward to Connector** unset
> 5. Save the rule and set it to **Active**
>
> ```cel theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> {
>   "condition": {
>     "pre_tcp": port == 443,
>     "pre_tls": hostname == "api.anthropic.com" || hostname.endsWith(".anthropic.com"),
>     "post_tls": technology == "llm"
>   }
> }
> ```

> [tab] Terraform
>
> ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> resource "formal_network_rule" "anthropic_llm" {
>   name        = "anthropic-llm"
>   description = "Intercept Anthropic LLM traffic on the Formal Endpoint"
>   status      = "active"
>
>   cel_expression = <<-EOT
>     {
>       "condition": {
>         "pre_tcp": port == 443,
>         "pre_tls": hostname == "api.anthropic.com" || hostname.endsWith(".anthropic.com"),
>         "post_tls": technology == "llm"
>       }
>     }
>   EOT
> }
> ```

**Verify:** send an Anthropic request and confirm it appears in [Logs](https://app.formal.ai/logs).

Apps can keep using `api.anthropic.com`. The Endpoint intercepts that hostname and applies policies.

## Create the rewrite policy

The policy merges `anthropic-allowed-org-ids` into outgoing LLM request headers. `object.union` puts your value second, so it overwrites a client-supplied header.

Replace `<YOUR_ORG_ID>` with the UUID you copied.

> [tab] Control Plane
>
> 1. Navigate to [Policies](https://app.formal.ai/policies)
> 2. Click **Create Policy**
> 3. In **Choose a Template**, select **Restrict Anthropic Sign-Ins To One Org**
> 4. Replace `<YOUR_ORG_ID>` with the UUID you copied
> 5. Click **Create Policy** to save
>
> You can also paste this Rego if you skip the template:
>
> ```rego theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> package formal.v2
>
> import future.keywords.if
>
> rewritten_headers := object.union(input.http.headers, {
>   "anthropic-allowed-org-ids": ["<YOUR_ORG_ID>"],
> })
>
> request := {
>   "action": "rewrite",
>   "headers": rewritten_headers,
> } if {
>   input.resource.technology == "llm"
> }
> ```

> [tab] Terraform
>
> ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> resource "formal_policy" "restrict_anthropic_org" {
>   name        = "restrict-anthropic-org"
>   description = "Allow Anthropic sign-ins only for the approved organization ID"
>   status      = "active"
>
>   module = <<-EOT
>     package formal.v2
>
>     import future.keywords.if
>
>     rewritten_headers := object.union(input.http.headers, {
>       "anthropic-allowed-org-ids": ["<YOUR_ORG_ID>"],
>     })
>
>     request := {
>       "action": "rewrite",
>       "headers": rewritten_headers,
>     } if {
>       input.resource.technology == "llm"
>     }
>   EOT
> }
> ```

Header values must be arrays of strings. For more than one org, use a comma-separated list in a single value. Do not put spaces between IDs:

```rego theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
"anthropic-allowed-org-ids": ["<ORG_ID_1>,<ORG_ID_2>"],
```

> [!WARNING]
>
> Anthropic rejects duplicate `anthropic-allowed-org-ids` headers. Keep one header value. Do not list each org as a separate array element.

This policy matches every LLM request. If you also intercept other providers, scope the rule to Anthropic hostnames:

```rego theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
request := {
  "action": "rewrite",
  "headers": rewritten_headers,
} if {
  input.resource.technology == "llm"
  input.http.hostname == "api.anthropic.com"
}
```

Create the policy in **Draft** or **Dry-run** first. Then set it to **Active**.

## Verify

**Verify an allowed org:**

1. Sign in to Claude with an account in your Anthropic org.
2. Send a Messages API request, or use Claude Code as usual.
3. Open [Logs](https://app.formal.ai/logs) and confirm the rewrite ran.

Look for `triggered_policies.type:rewrite` on LLM requests. Sent headers should include `anthropic-allowed-org-ids` with your UUID.

**Verify a blocked org:**

Sign in with a personal Claude account, or call the API with a key from another org. Anthropic should return HTTP 403:

```json theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
{
  "type": "error",
  "error": {
    "type": "permission_error",
    "message": "Access restricted by network policy. Contact IT Administrator.",
    "error_code": "tenant_restriction_violation"
  }
}
```

You can also probe the API with your org key after the header is in place:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-sonnet-4-6","max_tokens":32,"messages":[{"role":"user","content":"Hello"}]}'
```

**Expected:** HTTP 200 when the key belongs to `<YOUR_ORG_ID>`. HTTP 403 `tenant_restriction_violation` otherwise.

## Troubleshooting

> [accordion] Personal accounts still sign in
>
> **Possible causes:**
>
> * Transparent Mode is not running
> * The network rule or the policy is Draft or Dry-run, not Active
> * Traffic uses a host the network rule does not match (`claude.ai` vs `api.anthropic.com`)
>
> **Fix:**
>
> 1. Run `formal transparent-proxy status`
> 2. Set the network rule and the policy to **Active**
> 3. Add the Anthropic hostname the app uses to the network rule

> [accordion] Requests return 403 tenant\_restriction\_violation
>
> **Possible causes:**
>
> * The UUID is not the org that owns the account or API key
> * Extra spaces or quotes in the header value
> * You are testing with a personal account (this is expected)
>
> **Fix:**
>
> 1. Re-copy the Organization ID from Anthropic settings
> 2. Keep a single UUID string in the header array
> 3. Sign in with an account in that org

> [accordion] Requests return 400 for the header
>
> **Possible causes:**
>
> * More than one `anthropic-allowed-org-ids` header on the request
> * Multiple array elements instead of a comma-separated string
>
> **Fix:**
>
> 1. Use `object.union` so Formal overwrites the header
> 2. Put every org ID in one comma-separated value

## Next Steps

> [card] [LLM Resources](https://docs.formal.ai/docs/guides/core-concepts/resources/llm.md)
>
> Proxy Anthropic and other LLM APIs

> [card] [Rewrite Action](https://docs.formal.ai/docs/guides/policies/enforcement.md#example-rewrite-llm-request-headers)
>
> Header rewrite reference

> [card] [LLM Policy Inputs](https://docs.formal.ai/docs/guides/policies/evaluation.md#example-rewrite-request-headers)
>
> Request-stage LLM fields and examples

> [card] [Formal Endpoint](https://docs.formal.ai/docs/guides/client-apps/transparent-mode.md)
>
> Enable Transparent Mode

> [card] [Network Rules](https://docs.formal.ai/docs/guides/network-rules.md)
>
> Select which Endpoint traffic Formal intercepts


## Related topics

- [Policy Examples](https://docs.formal.ai/docs/guides/policies/examples.md)
- [Policy Enforcement](https://docs.formal.ai/docs/guides/policies/enforcement.md)
- [What is Formal?](https://docs.formal.ai/docs/guides/getting-started/what-is-formal.md)
- [Policy Evaluation](https://docs.formal.ai/docs/guides/policies/evaluation.md)
- [HTTP](https://docs.formal.ai/docs/guides/core-concepts/resources/http.md)


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