# How to Avoid Third Party API Rate Limits with Edge Caching

> REST API rate limits hit fast from Frontend / Web. Cache 300s on GET calls where the query string scopes the response.

- Canonical page: https://realcomposer.com/recipes/avoid-third-party-api-rate-limits
- Client platform: Frontend / Web
- Upstream services: REST API
- Category: Edge Caching & Rate Limits
- JSON version: https://realcomposer.com/recipes/avoid-third-party-api-rate-limits.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=avoid-third-party-api-rate-limits&via=agent

## Problem: REST API rate limits from Frontend / Web traffic

Without edge caching, identical REST API reads during a session still round-trip to the origin.

- HTTP 429 responses during launch traffic
- Surprise SaaS overages from duplicate reads
- Slower repeat views than necessary

## Solution steps

1. **Store upstream credentials in Secret Vault**: Create API_BEARER_TOKEN vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders.

2. **Target the real upstream URL**: Configure headersTemplate to inject vault secrets, target https://jsonplaceholder.typicode.com/users/{{query.userId}}, 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/avoid-third-party-api-rate-limits', {
  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 Avoid Third Party API Rate Limits with Edge Caching",
  "method": "GET",
  "cacheTtlSeconds": 300,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "upstream",
      "upstreamUrlTemplate": "https://jsonplaceholder.typicode.com/users/{{query.userId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.API_BEARER_TOKEN}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "userId",
        "sourcePath": "id",
        "type": "number",
        "sourceStep": "upstream"
      },
      {
        "targetPath": "name",
        "sourcePath": "name",
        "type": "string",
        "sourceStep": "upstream"
      },
      {
        "targetPath": "email",
        "sourcePath": "email",
        "type": "string",
        "sourceStep": "upstream"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/avoid-third-party-api-rate-limits" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_avoid-th",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "avoid-third-party-api-rate-limits"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "userId": "sample",
  "name": "sample",
  "email": "sample"
}
```

## FAQ

### Does Frontend / Web need CORS changes after adding RealComposer?

Store API_BEARER_TOKEN for avoid-third-party-api-rate-limits. Frontend / Web never sees decrypted values.

### When does edge caching apply to this recipe?

avoid-third-party-api-rate-limits forwards client JSON to POST upstreams unchanged; secrets interpolate only in URLs and header templates.

### How do I rotate upstream credentials?

Upstream steps in avoid-third-party-api-rate-limits honor timeoutMs and optional fallback JSON without leaking secrets.
