# Secure Anthropic Claude API Proxy for Frontend

> Never place ANTHROPIC_API_KEY inside Frontend / Web source. RealComposer injects them when calling https://api.anthropic.com/v1/messages, so browsers see only a client token.

- Canonical page: https://realcomposer.com/recipes/anthropic-claude-api-frontend-proxy
- Client platform: Frontend / Web
- Upstream services: Anthropic
- Category: Security & Secret Vault
- JSON version: https://realcomposer.com/recipes/anthropic-claude-api-frontend-proxy.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=anthropic-claude-api-frontend-proxy&via=agent

## Problem: Anthropic keys in Frontend / Web network tabs

Frontend / Web ships code or scripts to end-user devices. Any Anthropic bearer token in those bundles can be copied from DevTools, proxies, or repackaged apps.

- Shared Frontend / Web projects revealing Anthropic tokens
- Sudden Anthropic quota burn from scripted abuse
- Inability to rotate keys without redeploying clients

## Solution steps

1. **Add vault secrets for this pipeline**: Store ANTHROPIC_API_KEY in the vault. Frontend / Web never embeds the raw secret, only a revocable rc_live_ client token.

2. **Configure upstream steps and output mapping**: Configure headersTemplate to inject vault secrets, target https://api.anthropic.com/v1/messages, and Add output mapping fields that mirror the JSON contract your screen already expects.

3. **Call from Frontend / Web**: Allowed origins on the token should list every Frontend / Web host that calls this URL.

```
const res = await fetch('https://realcomposer.com/v1/workspace/anthropic-claude-api-frontend-proxy', {
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
```

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "Secure Anthropic Claude API Proxy for Frontend",
  "method": "POST",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "anthropic",
      "upstreamUrlTemplate": "https://api.anthropic.com/v1/messages",
      "httpMethod": "POST",
      "headersTemplate": {
        "x-api-key": "{{secrets.ANTHROPIC_API_KEY}}",
        "anthropic-version": "2023-06-01",
        "Content-Type": "application/json"
      },
      "timeoutMs": 10000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "role",
        "sourcePath": "content.0.text",
        "type": "string",
        "sourceStep": "anthropic"
      },
      {
        "targetPath": "model",
        "sourcePath": "model",
        "type": "string",
        "sourceStep": "anthropic"
      },
      {
        "targetPath": "stopReason",
        "sourcePath": "stop_reason",
        "type": "string",
        "sourceStep": "anthropic"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X POST "https://realcomposer.com/v1/workspace/anthropic-claude-api-frontend-proxy" \
  -H "Authorization: Bearer rc_live_client_token" \
  -H "Content-Type: application/json" \
  -d '{"model":"example"}'
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_anthropi",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "anthropic-claude-api-frontend-proxy"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "role": "sample",
  "model": "sample",
  "stopReason": "sample"
}
```

## FAQ

### Which Anthropic credential belongs in the vault for this pipeline?

Yes for anthropic-claude-api-frontend-proxy. Ship only an rc_live_ client token in Frontend / Web; RealComposer injects ANTHROPIC_API_KEY on https://api.anthropic.com/v1/messages.

### What cache key does RealComposer use?

anthropic-claude-api-frontend-proxy vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body.

### What happens if an upstream step times out?

Upstream steps in anthropic-claude-api-frontend-proxy honor timeoutMs and optional fallback JSON without leaking secrets.
