# How to call anthropic api from framer without cors

> Framer fetch to RealComposer with streaming-friendly headers. For "how to call anthropic api from framer without cors", store ANTHROPIC_API_KEY in Secret Vault, call https://api.anthropic.com/v1/messages from a Worker, and let Framer hit only https://realcomposer.com/v1/workspace/anthropic-api-framer-without-cors 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/anthropic-api-framer-without-cors
- Client platform: Framer
- Upstream services: Anthropic
- Category: Platforms & Frameworks
- JSON version: https://realcomposer.com/recipes/anthropic-api-framer-without-cors.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=anthropic-api-framer-without-cors&via=agent

## Problem: Framer cannot attach secret headers to Anthropic

Framer runs in the browser or a sandbox without a secret store. Anthropic rejects unsigned browser origins or requires server-only headers.

- Proxy hacks that break when vendors tighten CSP
- Zapier-only workarounds adding cost and latency
- Guest users seeing failed network requests in demos

## Solution steps

1. **Add vault secrets for this pipeline**: Create ANTHROPIC_API_KEY vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders.

2. **Configure upstream steps and output mapping**: Use POST against https://api.anthropic.com/v1/messages. Allowed origins on the client token should match post pipelines set cache ttl to 0 because realcomposer only stores get responses at the edge.

3. **Fetch inside Framer overrides**: Allowed origins on the token should list every Framer host that calls this URL.

```
fetch('https://realcomposer.com/v1/workspace/anthropic-api-framer-without-cors', {
  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": "How to call anthropic api from framer without cors",
  "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-api-framer-without-cors" \
  -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-api-framer-without-cors"
  },
  "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

### Can Framer call Anthropic without holding the production key?

Store ANTHROPIC_API_KEY for anthropic-api-framer-without-cors. Framer never sees decrypted values.

### Does POST traffic get cached?

anthropic-api-framer-without-cors keeps cache TTL at 0 because it uses POST upstream calls or per-user responses. Add ids to query strings before enabling GET cache.

### How do I rotate upstream credentials?

Upstream steps in anthropic-api-framer-without-cors honor timeoutMs and optional fallback JSON without leaking secrets.
