# Anthropic streaming api payload slim edge proxy

> Edge strips rate limit headers and debug from streamed JSON chunks. For "anthropic streaming api payload slim edge proxy", store ANTHROPIC_API_KEY in Secret Vault, call https://api.anthropic.com/v1/messages from a Worker, and let Frontend / Web hit only https://realcomposer.com/v1/workspace/slim-anthropic-streaming-payload-edge with an rc_live_ client token. POST upstream calls are not stored in caches.default; clients must send JSON bodies and headers forward unchanged.

- Canonical page: https://realcomposer.com/recipes/slim-anthropic-streaming-payload-edge
- Client platform: Frontend / Web
- Upstream services: Anthropic
- Category: Payload Slimmer
- JSON version: https://realcomposer.com/recipes/slim-anthropic-streaming-payload-edge.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=slim-anthropic-streaming-payload-edge&via=agent

## Problem: Unmapped Anthropic fields waste bandwidth

Anthropic returns nested CRM, audit, and configuration objects. Frontend / Web parses them on the main thread even when the UI binds three fields.

- Large arrays kept in memory after navigation
- Analytics showing poor LCP on API-heavy screens
- Developers shipping defensive null checks for unused paths

## Solution steps

1. **Bind vault keys to the Worker**: Create ANTHROPIC_API_KEY vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders.

2. **Set headers, mapping, and cache TTL**: Point step anthropic at https://api.anthropic.com/v1/messages with POST. Map only the UI fields in output mapping so clients never download audit or nested blobs. POST pipelines set cache TTL to 0 because RealComposer only stores GET responses at the edge.

3. **Call from Frontend / Web**: Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.

```
const res = await fetch('https://realcomposer.com/v1/workspace/slim-anthropic-streaming-payload-edge', {
  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": "Anthropic streaming api payload slim edge proxy",
  "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/slim-anthropic-streaming-payload-edge" \
  -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_slim-ant",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "slim-anthropic-streaming-payload-edge"
  },
  "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

### What should Frontend / Web store instead of Anthropic secrets?

Point Frontend / Web at /recipes/slim-anthropic-streaming-payload-edge edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins.

### Will Anthropic or Linear prompt bodies be rewritten?

slim-anthropic-streaming-payload-edge vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body.

### How do I rotate upstream credentials?

Rotate vault secrets for slim-anthropic-streaming-payload-edge anytime; clients keep the same rc_live_ token.
