{
  "slug": "cache-google-places-api-reduce-bills",
  "title": "Cache Google Places Autocomplete API to Reduce Bills",
  "metaTitle": "Cache Google Places Autocomplete - RealComposer",
  "metaDescription": "Cache google places autocomplete api to reduce bills. Shield Google Maps with 300s GET edge cache; cache key uses query params on.",
  "headline": "Edge TTL shield for Frontend / Web Google Maps calls",
  "category": "caching",
  "categoryLabel": "Edge Caching & Rate Limits",
  "urgency": 9,
  "clientPlatform": "Frontend / Web",
  "upstreamServices": [
    "Google Maps"
  ],
  "searchIntentQuery": "cache google places autocomplete api to reduce bills",
  "directAnswerSummary": "To cache google places autocomplete api to reduce bills, set cacheTtlSeconds on a GET pipeline targeting https://maps.googleapis.com/maps/api/place/autocomplete/json?input={{query.input}}&key={{secrets.GOOGLE_MAPS_API_KEY}}. Identical query strings reuse Cloudflare caches.default before upstream sees traffic.",
  "problem": {
    "title": "Uncached Google Maps spikes cost and latency",
    "explanation": "Every Frontend / Web visitor can trigger a fresh Google Maps call. Bursts exhaust per-minute quotas even when data changes slowly.",
    "risks": [
      "Thundering herds after cache expiry on the origin",
      "Analytics skewed by client-side retry storms",
      "Support tickets blaming \"API downtime\" during spikes"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Bind vault keys to the Worker",
      "description": "Create GOOGLE_MAPS_API_KEY vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders."
    },
    {
      "stepNumber": 2,
      "title": "Set headers, mapping, and cache TTL",
      "description": "Point step maps at https://maps.googleapis.com/maps/api/place/autocomplete/json?input={{query.input}}&key={{secrets.GOOGLE_MAPS_API_KEY}} 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."
    },
    {
      "stepNumber": 3,
      "title": "Call from Frontend / Web",
      "description": "Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.",
      "codeSnippet": "const res = await fetch('https://realcomposer.com/v1/workspace/cache-google-places-api-reduce-bills', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "Cache Google Places Autocomplete API to Reduce Bills",
    "method": "GET",
    "cacheTtlSeconds": 300,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "maps",
        "upstreamUrlTemplate": "https://maps.googleapis.com/maps/api/place/autocomplete/json?input={{query.input}}&key={{secrets.GOOGLE_MAPS_API_KEY}}",
        "httpMethod": "GET",
        "headersTemplate": {},
        "timeoutMs": 3000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "description",
          "sourcePath": "predictions.0.description",
          "type": "string",
          "sourceStep": "maps"
        },
        {
          "targetPath": "placeId",
          "sourcePath": "predictions.0.place_id",
          "type": "string",
          "sourceStep": "maps"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_cache-go",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "cache-google-places-api-reduce-bills"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "description": "sample",
    "placeId": "sample"
  },
  "curlSnippet": "curl -X GET \"https://realcomposer.com/v1/workspace/cache-google-places-api-reduce-bills\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "What should Frontend / Web store instead of Google Maps secrets?",
      "answer": "Point Frontend / Web at /recipes/cache-google-places-api-reduce-bills edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins."
    },
    {
      "question": "Will Anthropic or Linear prompt bodies be rewritten?",
      "answer": "Cache key for cache-google-places-api-reduce-bills: internal edge-cache path plus sorted query. Identical params hit; vary userId per user."
    },
    {
      "question": "How do I rotate upstream credentials?",
      "answer": "Rotate vault secrets for cache-google-places-api-reduce-bills anytime; clients keep the same rc_live_ token."
    }
  ],
  "relatedRecipeSlugs": [
    "filter-json-response-at-edge",
    "flutterflow-multiple-apis-page-load",
    "stitch-two-rest-apis-flutterflow"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/cache-google-places-api-reduce-bills",
    "markdown": "https://realcomposer.com/recipes/cache-google-places-api-reduce-bills.md",
    "json": "https://realcomposer.com/recipes/cache-google-places-api-reduce-bills.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=cache-google-places-api-reduce-bills&via=agent"
  }
}