{
  "slug": "algolia-write-api-secure-proxy",
  "title": "Call Algolia Write API from Client without Master Key",
  "metaTitle": "Call Algolia Write API from Client - RealComposer",
  "metaDescription": "Call algolia write api from client without master key. Keep Algolia keys in RealComposer Vault; Frontend / Web uses rc_live_ tokens only.",
  "headline": "Algolia secrets stay out of Frontend / Web bundles",
  "category": "security",
  "categoryLabel": "Security & Secret Vault",
  "urgency": 9,
  "clientPlatform": "Frontend / Web",
  "upstreamServices": [
    "Algolia"
  ],
  "searchIntentQuery": "call algolia write api from client without master key",
  "directAnswerSummary": "Frontend / Web cannot safely store Algolia production keys. Vault-bound headers reach https://{{secrets.ALGOLIA_APP_ID}}-dsn.algolia.net/1/indexes/{{query.index}}/query on Workers while apps call your algolia-write-api-secure-proxy edge URL.",
  "problem": {
    "title": "Why Frontend / Web leaks Algolia credentials",
    "explanation": "Attackers routinely extract Algolia secrets from Frontend / Web builds. Direct browser calls also expose internal error payloads with hostnames.",
    "risks": [
      "Production Algolia keys copied from Frontend / Web bundles",
      "Compliance violations after credential leaks",
      "Attackers replaying vault-grade scopes from a laptop"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Bind vault keys to the Worker",
      "description": "Add ALGOLIA_API_KEY to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream."
    },
    {
      "stepNumber": 2,
      "title": "Configure upstream steps and output mapping",
      "description": "Use POST against https://{{secrets.ALGOLIA_APP_ID}}-dsn.algolia.net/1/indexes/{{query.index}}/query. Allowed origins on the client token should match post pipelines set cache ttl to 0 because realcomposer only stores get responses at the edge."
    },
    {
      "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/algolia-write-api-secure-proxy', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "Call Algolia Write API from Client without Master Key",
    "method": "POST",
    "cacheTtlSeconds": 0,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "algolia",
        "upstreamUrlTemplate": "https://{{secrets.ALGOLIA_APP_ID}}-dsn.algolia.net/1/indexes/{{query.index}}/query",
        "httpMethod": "POST",
        "headersTemplate": {
          "X-Algolia-API-Key": "{{secrets.ALGOLIA_API_KEY}}",
          "X-Algolia-Application-Id": "{{secrets.ALGOLIA_APP_ID}}",
          "Content-Type": "application/json"
        },
        "timeoutMs": 10000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "hitCount",
          "sourcePath": "nbHits",
          "type": "number",
          "sourceStep": "algolia"
        },
        {
          "targetPath": "firstHit",
          "sourcePath": "hits.0.objectID",
          "type": "string",
          "sourceStep": "algolia"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_algolia-",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "algolia-write-api-secure-proxy"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "hitCount": "sample",
    "firstHit": "sample"
  },
  "curlSnippet": "curl -X POST \"https://realcomposer.com/v1/workspace/algolia-write-api-secure-proxy\" \\\n  -H \"Authorization: Bearer rc_live_client_token\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"model\":\"example\"}'",
  "faqs": [
    {
      "question": "Is it safe to log Algolia responses in Frontend / Web?",
      "answer": "Yes for algolia-write-api-secure-proxy. Ship only an rc_live_ client token in Frontend / Web; RealComposer injects ALGOLIA_API_KEY on https://{{secrets.ALGOLIA_APP_ID}}-dsn.algolia.net/1/indexes/{{query.index}}/query."
    },
    {
      "question": "Will Anthropic or Linear prompt bodies be rewritten?",
      "answer": "algolia-write-api-secure-proxy POST steps bypass caches.default even if cacheTtlSeconds is set in the dashboard."
    },
    {
      "question": "Can I restrict which domains call this pipeline?",
      "answer": "Allowed origins on the algolia-write-api-secure-proxy client token restrict which domains may call the edge URL."
    }
  ],
  "relatedRecipeSlugs": [
    "sub-10ms-api-for-mobile-apps",
    "cache-third-party-api-at-edge",
    "reduce-json-size-flutter-app"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/algolia-write-api-secure-proxy",
    "markdown": "https://realcomposer.com/recipes/algolia-write-api-secure-proxy.md",
    "json": "https://realcomposer.com/recipes/algolia-write-api-secure-proxy.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=algolia-write-api-secure-proxy&via=agent"
  }
}