Simulators
Rate limits
Check that your integration slows down and retries when PostHog throttles a personal API key. Turning on rate_limits: real applies the limits in the Rate limits table. Each key has its own project API allowance, whose window opens at that key’s first request, while local evaluation has one allowance for the project. Calls to the control plane, such as /_rystic/network, are left out of every count.
The example turns the limits on and sends 241 insight reads and one feature flag read with one key over one connection. It then reads the refusal and tries a second key. Next it sends 601 local evaluations, which share one allowance for the project, and keeps the last one’s body and every response’s headers, then tries the second key there. Last, it resets the simulator:
KEY=phx_rysticexamplepersonalkey000000000000000
OTHER=phx_rysticsecondpersonalkey00000000000000
INSIGHTS="$RYSTIC_URL/api/projects/3104/insights/"
FLAGS="$RYSTIC_URL/api/projects/3104/feature_flags/"
curl -s -X POST "$RYSTIC_URL/_rystic/network" -o /dev/null -w '%{http_code}\n' -d '{"rate_limits": "real"}'
# -> 204
curl -s -H "Authorization: Bearer $KEY" -w '%{http_code}\n' $(for i in $(seq 241); do echo "-o /dev/null $INSIGHTS"; done) -o /dev/null "$FLAGS" | sort | uniq -c | awk '{print $2, $1}'
# -> 200 241
# -> 429 1
curl -s -H "Authorization: Bearer $KEY" "$INSIGHTS" | jq -c .
# -> {"type":"throttled_error","code":"throttled","detail":"Request was throttled.","attr":null}
curl -s -H "Authorization: Bearer $KEY" -D - -o /dev/null "$INSIGHTS" | awk 'tolower($1) == "retry-after:" {print "Retry-After sent"}'
# -> Retry-After sent
curl -s -H "Authorization: Bearer $OTHER" -o /dev/null -w '%{http_code}\n' "$INSIGHTS"
# -> 200
DEFINITIONS="$RYSTIC_URL/flags/definitions?token=phc_93a00453928e7bff26aac13f55056c3e3f5fdd7c2eb"
BODY=$(mktemp); HEADERS=$(mktemp)
curl -s -H "Authorization: Bearer $KEY" -D "$HEADERS" -w '%{http_code}\n' $(for i in $(seq 600); do echo "-o /dev/null $DEFINITIONS"; done) -o "$BODY" "$DEFINITIONS" | sort | uniq -c | awk '{print $2, $1}'
# -> 200 600
# -> 429 1
jq -r .code "$BODY"
# -> rate_limit_exceeded
awk '/^HTTP\// {r++} tolower($1) == "retry-after:" {n++} END {print r+0, n+0}' "$HEADERS"
# -> 601 0
curl -s -H "Authorization: Bearer $OTHER" -o /dev/null -w '%{http_code}\n' "$DEFINITIONS"
# -> 429
curl -s -X POST "$RYSTIC_URL/_rystic/reset" -o /dev/null -w '%{http_code}\n'
# -> 204
curl -s "$RYSTIC_URL/_rystic/network" | jq -r .rate_limits
# -> real
curl -s -H "Authorization: Bearer $KEY" -o /dev/null -w '%{http_code}\n' "$INSIGHTS"
# -> 200
The flag read fit beside the refused insight read because insights and the other project routes draw on separate allowances. The second key started with its full project API allowance. The 601st local evaluation returned rate_limit_exceeded, and none of the burst’s 601 responses sent Retry-After. The second key was refused too, since local evaluation counts for the project, not the key. The reset left the setting at real and gave the first key its insight reads back.