routing-outbound-api-calls
Skill721 starsChanged 59 days agoMITView on GitHub
Use before adding or changing Python code that calls a third-party HTTP API from PostHog (a vendor REST call, a vendor SDK client, a scraping or enrichment service), and before adding or changing a domain under posthog/egress/: its budget, priority lanes, identity, metrics, or rate-limit headers. Routes the call to an existing egress domain, a new gated domain, a record-only domain, or no domain at all, names the reference domain to copy, and lists the tests that catch a missing priority reserve. Trigger terms: egress, outbound API, third-party API, vendor client, rate limit, 429, Retry-After, budget, priority lane, BATCH, reserve, EgressClient, RecordedEgressClient, github_request.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- PostHog/posthogword for word, first seen Oct 4, 2026
Other versions1 project uses a version of this.
Word for word · 1
- PostHog/posthog★ 40k100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository119 other files it gives its agents.
- AGENTS.mdAGENTS.md
- common/AGENTS.mdAGENTS.md
- proto/AGENTS.mdAGENTS.md
- rust/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- common/CLAUDE.mdCLAUDE.md
- proto/CLAUDE.mdCLAUDE.md
- rust/CLAUDE.mdCLAUDE.md
- .cursor/rules/django-python.mdcCursor rule
- .cursor/rules/react-typescript.mdcCursor rule
- .cursor/rules/rust.mdcCursor rule
- adding-activity-loggingSkill
- adding-api-scopesSkill
- adding-inbound-webhooksSkill
- adding-inbox-sourcesSkill
- adding-ingestion-warningsSkill
- adding-mcp-store-serversSkill
- adding-personhog-rpcSkill
- adding-product-alertingSkill
- adding-project-secret-api-key-authSkill
- adopting-generated-api-typesSkill
- analyzing-experiment-precompute-canarySkill
- analyzing-experiment-query-performanceSkill
- analyzing-insights-across-teamsSkill
- announcing-behavior-changesSkill
- auditing-llm-gateway-paritySkill
- auditing-warehouse-source-coverageSkill
- authenticating-to-clickhouseSkill
- authoring-ci-workflowsSkill
- autoresolving-pr-conflictsSkill
- building-product-empty-statesSkill
- clickhouse-migrationsSkill
- debugging-ci-failuresSkill
- debugging-local-replaySkill
- debugging-local-task-agent-runsSkill
- debugging-mcp-analyticsSkill
- debugging-signals-pipelineSkill
- debugging-table-access-deniedSkill
- depot-ciSkill
- depot-container-buildsSkill
- depot-github-runnersSkill
- developing-subscriptionsSkill
- django-migrationsSkill
- django-startup-timeSkill
- documenting-warehouse-sourcesSkill
- editing-agents-mdSkill
- establishing-code-ownershipSkill
- extending-hobby-smoke-testsSkill
- extending-personhog-test-harnessSkill
- finding-llm-gateway-migration-candidatesSkill
- fixing-flaky-testsSkill
- gating-production-deploysSkill
- gating-sensitive-actionsSkill
- generating-clickhouse-query-performance-reportsSkill
- hogliSkill
- implementing-mcp-toolsSkill
- implementing-mcp-ui-appsSkill
- implementing-warehouse-sourcesSkill
- improving-drf-endpointsSkill
- improving-mcp-toolsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 34
Write these four answers into the domain README.md first.
- Distinctive: line 49
Write "unverified" when no source loads: Never turn an unchecked fact into a confident sentence.
- Distinctive: line 51
Rule out your own code before you blame the vendor: Before you write that a header does not arrive, confirm three things: the recorder …
- Distinctive: line 76
Update the domain README.md in the same PR when its identity, budget, lanes, callers, or headers change.
- Distinctive: line 77
Never rename a shipped metric or label.
- Very specific: line 89
Lanes, only for a domain that overrides the reserve: Use the real policy through OutboundRateLimiter(LimitsBackend()) and a unique key.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Routing outbound API calls
posthog/egress/ owns every outbound third-party API call that needs a shared budget or telemetry.
posthog/egress/README.md is the reference for the mechanisms, and each domain's own README.md holds the facts about that API.
This skill holds the procedure and the traps.
Route first
| Situation | Route |
A domain for the API exists (ls posthog/egress/*/README.md) | Call its <domain>_request helper or typed client. Read its README for identity and lanes. Never add a second client. |
| New API, PostHog owns the credential, and the vendor publishes a request limit or bills per call | New gated domain: EgressClient, or AsyncEgressClient for an aiohttp client |
| New API, PostHog owns the credential, and the vendor publishes no request limit that a rate budget can model | New record-only domain: RecordedEgressClient |
| The customer owns the credential on their own vendor account, and no PostHog process shares it | No domain. Honor 429 and Retry-After at the caller. See "who owns the token" in /implementing-warehouse-sources. |
| Throttling requests that reach PostHog's own API | posthog/rate_limit.py, not egress |
A budget that needs burst capacity, refunds, or a real per-caller Retry-After | /using-redis-token-buckets |
A secret-URL webhook (a Slack incoming webhook, an interactivity response_url) | Out of scope. The URL is the credential, so it must never become a metric label. |
| A vendor calls PostHog (an inbound webhook) | /adding-inbound-webhooks |
Decide before you write code
Write these four answers into the domain README.md first.
Take each answer from the vendor's documentation or from production traffic, never from a sibling domain.
- Identity. The budget owner in the vendor's own id space: an installation, an account, a fleet. Never a PostHog row id. A secret identity goes through
scope_fingerprintbefore it becomes a scope. - Budget. A documented vendor limit means the budget stays under it. No documented limit means an operator ceiling on spend, read from settings. When the API already has a caller, check its peak requests per scope per minute and per hour before you pick numbers.
- Lanes. Keep the default reserve:
BATCHis denied at 70% of a window,NORMALat 90%. Passreserve={}only when every caller runs on one lane, say why in the limiter docstring, and add the domain to_FLAT_DOMAINSinposthog/egress/test/test_domains.py. Give every caller an explicit lane: a person waiting getsNORMAL, background work getsBATCH. A call built from user-controlled input never runsCRITICAL, becauseCRITICALis never shed. - Headers. Parse only the rate-limit headers the vendor documents, and declare a gauge only for those. A header with an undocumented encoding (epoch or seconds) gets no gauge.
Source every vendor fact
A limit, a cost, a quota, a header name, or a claim that a header is absent is a vendor fact.
Each one goes into the domain README.md with its evidence under ## Sources. test_domains.py fails a README without that section.
- Cite the vendor's own page. A PR description, a sibling domain, a code comment, a blog post, or a search-result summary is not a source. Open the page it points at and cite that.
- Render docs that need JavaScript. WebFetch returns an empty shell for a single-page docs site and can get a 429. Open the page in a headless browser (the Playwright MCP) or fetch the site's
llms-full.txt. A docs site that renders nothing is not proof that the vendor documents nothing. - Write "unverified" when no source loads. Never turn an unchecked fact into a confident sentence.
- Check the gauges after the first deploy. Query the domain's rate-limit gauges once the domain has traffic. An empty gauge means the headers do not reach PostHog, even when the docs say they do.
- Rule out your own code before you blame the vendor. Before you write that a header does not arrive, confirm three things: the recorder passes a scope, the parser reads the documented name, and the process exports other gauges.
Build a new domain
Work through "Adding a new egress domain" in the egress README. Copy the closest reference domain for the file layout:
| Shape | Reference |
| Sync, gated, with rate-limit headers | posthog/egress/github/ |
| Sync, gated, no rate-limit headers | posthog/egress/firecrawl/ |
| Record-only, no gate | posthog/egress/openai_auth/ |
| Async (aiohttp) | posthog/egress/harmonic/ |
| Vendor SDK | posthog/egress/slack/client.py |
- Copy the layout, not the numbers. Redo the four decisions above for the new API. A copy keeps the reference's settings defaults, lane defaults, and header names.
- Let the base client record. The client sets
observability = <domain>_egress. Do not addrecord_<domain>_responsewrappers. - Add a mechanism to the base, never to one domain. Tracing, request timing, retries and recording go into the base clients in
transport/transport.py, so every domain gets them. A reference domain is the next domain's template, so a mechanism added there spreads under new names. A true one-off stays in the domain with a# One-off:comment that says why, then a# nosemgrep: shared-mechanisms-stay-out-of-egress-and-ingress-domainsline. See "Shared mechanisms" in the egress README. - Keep metric names explicit and stable. Dashboards and alerts query them by name.
- Keep
posthog.modelsimports out of the domain package. - The limiter never blocks. The caller catches
<Domain>EgressBudgetExhaustedand backs off, defers, or degrades. A caller that folds exceptions into "not found" must catch it first. - A caller that walks pages paces with
pace_secondsandadmission_interval_secondsinstead of getting denied.
Change an existing domain
- Update the domain
README.mdin the same PR when its identity, budget, lanes, callers, or headers change. - Never rename a shipped metric or label.
- A move between a flat and a laned policy changes production behavior. Compare the domain's peak traffic with the new thresholds and state the result in the PR.
- A new caller of an existing domain passes its lane explicitly and goes into the domain README's callers.
- A policy registered outside
posthog/egress/gets the same default reserve. A single-lane throttle there passesreserve={}.
Tests
Invoke /writing-tests first. In this package, these tests earn their place:
- Transport wiring. Patch
requests.request(or the aiohttp session), call the real<domain>_request, and assert the scope, the headers, and the recorded counter. Assert that a secret never reaches a label. - Settings names. Assert
resolve_policy(key).limitsunderoverride_settings. Thegetattrdefaults silently swallow a misspelled setting. - Header parsing. One parser case per documented header, plus garbage values.
- Lanes, only for a domain that overrides the reserve. Use the real policy through
OutboundRateLimiter(LimitsBackend())and a unique key.
These do not:
- A lane claim proven with a patched gate. A test that patches
consume_*_syncto returnFalsepasses when the policy has no reserve at all. - A per-domain copy of the default-ladder test.
test_outbound_rate_limiter.pycovers the ladder, andtest_domains.pypins the flat domains.
Traps this package already hit
- A fake gate.
CRITICALplus a huge budget, or_consumethat always returnsTrue. UseRecordedEgressClientinstead. - A missing scope. A scope of
Noneor""skips the gate. A single-account domain passes a constant scope such as"default", or every call goes through ungated. - The base lane.
EgressClient.requestdefaults toCRITICAL. The<domain>_requesthelper sets its own sheddable default. - Header names guessed from another vendor. Firecrawl shipped gauges for GitHub-style
X-RateLimit-*names that Firecrawl never documented, and they never recorded a value. - A vendor fact copied from a PR description. Open the vendor page, even when the page needs a browser to render.
- A caller from an unmerged PR documented as if it exists.
- A domain added as a side effect of a product PR, with no README.
test_domains.pyfails it. Write the README rather than skipping the test. - Position words and hand-kept lists in docs ("like the two above", "the second domain"). They break when the next domain lands.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

