How to Call Posthog API Securely from Mobile App
Vault-backed PostHog proxy tuned for Mobile App (iOS & Android)
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.
PostHog keys in Mobile App (iOS & Android) network tabs
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.
- Shared Mobile App (iOS & Android) projects revealing PostHog tokens
- Sudden PostHog quota burn from scripted abuse
- Inability to rotate keys without redeploying clients
How RealComposer Solves This at the Edge
Add vault secrets for this pipeline
Create POSTHOG_PERSONAL_API_KEY vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders.
Configure upstream steps and output mapping
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).
Call from Mobile App (iOS & Android)
Allowed origins on the token should list every Mobile App (iOS & Android) host that calls this URL.
let url = URL(string: "https://realcomposer.com/v1/workspace/posthog-mobile-proxy")!
var request = URLRequest(url: url)
request.addValue("Bearer rc_live_token", forHTTPHeaderField: "Authorization")
{
"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"
}
}
}
{
"flagKey": "sample",
"active": "sample"
}
Recipe Specs
- HTTP method
- GET
- Upstream calls
- 1
- Edge cache TTL
- No caching
- Client auth
- Restricted client token
- Mapped output fields
- 2
- Payload
- 239 B to 38 B (-84%)
curl -X GET "https://realcomposer.com/v1/workspace/posthog-mobile-proxy" \ -H "Authorization: Bearer rc_live_client_token"
Developer Questions & Troubleshooting
Which PostHog credential belongs in the vault for this pipeline?
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.
What cache key does RealComposer use?
posthog-mobile-proxy vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body.
How do I rotate upstream credentials?
Upstream steps in posthog-mobile-proxy honor timeoutMs and optional fallback JSON without leaking secrets.
Sources & Definitions Used in This Answer
Deploy this Mobile App (iOS & Android) + PostHog Recipe
Clone this pre-configured pipeline into your RealComposer workspace in one click. We pre-populate upstream URLs, headers, and mapping rules.