# How to Cache Github API Rate Limit 60 Requests Per Hour

> To how to cache github api rate limit 60 requests per hour, set cacheTtlSeconds on a GET pipeline targeting https://api.github.com/user/repos?per_page=5. Identical query strings reuse Cloudflare caches.default before upstream sees traffic.

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

## Problem: Uncached GitHub spikes cost and latency

Every Frontend / Web visitor can trigger a fresh GitHub call. Bursts exhaust per-minute quotas even when data changes slowly.

- Thundering herds after cache expiry on the origin
- Analytics skewed by client-side retry storms
- Support tickets blaming "API downtime" during spikes

## Solution steps

1. **Store upstream credentials in Secret Vault**: Add GITHUB_TOKEN to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2. **Set headers, mapping, and cache TTL**: Point step github at https://api.github.com/user/repos?per_page=5 with GET. Add output mapping fields that mirror the JSON contract your screen already expects. Set cache TTL to 300s so repeat GETs with the same query string hit caches.default.

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/cache-github-api-avoid-rate-limit', {
  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 Cache Github API Rate Limit 60 Requests Per Hour",
  "method": "GET",
  "cacheTtlSeconds": 300,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "github",
      "upstreamUrlTemplate": "https://api.github.com/user/repos?per_page=5",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.GITHUB_TOKEN}}",
        "Accept": "application/vnd.github+json"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "repoId",
        "sourcePath": "0.id",
        "type": "number",
        "sourceStep": "github"
      },
      {
        "targetPath": "fullName",
        "sourcePath": "0.full_name",
        "type": "string",
        "sourceStep": "github"
      },
      {
        "targetPath": "isPrivate",
        "sourcePath": "0.private",
        "type": "boolean",
        "sourceStep": "github"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/cache-github-api-avoid-rate-limit" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_cache-gi",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "cache-github-api-avoid-rate-limit"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "repoId": "sample",
  "fullName": "sample",
  "isPrivate": "sample"
}
```

## FAQ

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

Log request IDs for cache-github-api-avoid-rate-limit, not raw GitHub payloads, because upstream bodies may include PII.

### How do I forward JSON bodies to POST upstreams?

cache-github-api-avoid-rate-limit vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body.

### Can I restrict which domains call this pipeline?

Allowed origins on the cache-github-api-avoid-rate-limit client token restrict which domains may call the edge URL.
