{
  "slug": "posthog-mobile-proxy",
  "title": "How to Call Posthog API Securely from Mobile App",
  "metaTitle": "Call Posthog API Securely from - RealComposer",
  "metaDescription": "How to call posthog api securely from mobile app. Keep PostHog keys in RealComposer Vault; Mobile App (iOS & Android) uses rc_live_ tokens only.",
  "headline": "Vault-backed PostHog proxy tuned for Mobile App (iOS & Android)",
  "category": "security",
  "categoryLabel": "Security & Secret Vault",
  "urgency": 9,
  "clientPlatform": "Mobile App (iOS & Android)",
  "upstreamServices": [
    "PostHog"
  ],
  "searchIntentQuery": "how to call posthog api securely from mobile app",
  "directAnswerSummary": "Never place POSTHOG_PERSONAL_API_KEY inside Mobile App (iOS & Android) source. RealComposer injects them when calling https://us.posthog.com/api/projects/{{query.projectId}}/feature_flags, so browsers see only a client token.",
  "problem": {
    "title": "PostHog keys in Mobile App (iOS & Android) network tabs",
    "explanation": "Mobile App (iOS & Android) ships code or scripts to end-user devices. Any PostHog bearer token in those bundles can be copied from DevTools, proxies, or repackaged apps.",
    "risks": [
      "Shared Mobile App (iOS & Android) projects revealing PostHog tokens",
      "Sudden PostHog quota burn from scripted abuse",
      "Inability to rotate keys without redeploying clients"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Add vault secrets for this pipeline",
      "description": "Create POSTHOG_PERSONAL_API_KEY vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders."
    },
    {
      "stepNumber": 2,
      "title": "Configure upstream steps and output mapping",
      "description": "Use GET against https://us.posthog.com/api/projects/{{query.projectId}}/feature_flags. Allowed origins on the client token should match leave cache ttl at 0 when each response is user-specific (include userid or record id in query params before enabling cache)."
    },
    {
      "stepNumber": 3,
      "title": "Call from Mobile App (iOS & Android)",
      "description": "Allowed origins on the token should list every Mobile App (iOS & Android) host that calls this URL.",
      "codeSnippet": "let url = URL(string: \"https://realcomposer.com/v1/workspace/posthog-mobile-proxy\")!\nvar request = URLRequest(url: url)\nrequest.addValue(\"Bearer rc_live_token\", forHTTPHeaderField: \"Authorization\")"
    }
  ],
  "pipelineConfig": {
    "name": "How to Call Posthog API Securely from Mobile App",
    "method": "GET",
    "cacheTtlSeconds": 0,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "posthog",
        "upstreamUrlTemplate": "https://us.posthog.com/api/projects/{{query.projectId}}/feature_flags",
        "httpMethod": "GET",
        "headersTemplate": {
          "Authorization": "Bearer {{secrets.POSTHOG_PERSONAL_API_KEY}}"
        },
        "timeoutMs": 3000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "flagKey",
          "sourcePath": "results.0.key",
          "type": "string",
          "sourceStep": "posthog"
        },
        {
          "targetPath": "active",
          "sourcePath": "results.0.active",
          "type": "boolean",
          "sourceStep": "posthog"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_posthog-",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "posthog-mobile-proxy"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "flagKey": "sample",
    "active": "sample"
  },
  "curlSnippet": "curl -X GET \"https://realcomposer.com/v1/workspace/posthog-mobile-proxy\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "Which PostHog credential belongs in the vault for this pipeline?",
      "answer": "Yes for posthog-mobile-proxy. Ship only an rc_live_ client token in Mobile App (iOS & Android); RealComposer injects POSTHOG_PERSONAL_API_KEY on https://us.posthog.com/api/projects/{{query.projectId}}/feature_flags."
    },
    {
      "question": "What cache key does RealComposer use?",
      "answer": "posthog-mobile-proxy vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body."
    },
    {
      "question": "How do I rotate upstream credentials?",
      "answer": "Upstream steps in posthog-mobile-proxy honor timeoutMs and optional fallback JSON without leaking secrets."
    }
  ],
  "relatedRecipeSlugs": [
    "combine-multiple-webhooks-into-one-payload",
    "stripe-proxy-react-native",
    "reduce-json-size-flutter-app"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/posthog-mobile-proxy",
    "markdown": "https://realcomposer.com/recipes/posthog-mobile-proxy.md",
    "json": "https://realcomposer.com/recipes/posthog-mobile-proxy.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=posthog-mobile-proxy&via=agent"
  }
}