migrating-llm-gateway-callers
Skill721 starsChanged 2 months agoMITView on GitHub
Migrates an LLM caller from services/llm-gateway to PostHog/ai-gateway. Use when adding a gateway caller, converting an existing Python gateway integration, adopting shared Go-capable client builders, changing gateway URLs or headers for a caller, or removing a Python fallback. Inventories the caller's contract, checks the parity record, implements the supported migration, updates tests, and stops with a documented blocker when Go parity is missing.
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
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. About 0 are common, 8 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 9
Use services/llm-gateway/PARITY.md as the current decision record.
- Very specific: line 23
Search for the product name, LLM_GATEWAY, AI_GATEWAY, gateway client helpers, and gateway headers.
- Distinctive: line 29
If all required contracts are supported, continue with the migration.
- Distinctive: line 30
If a 🔎 item applies, verify it against the caller's actual model, request, and configuration.
- Distinctive: line 31
If a ⛔ gap applies, stop the migration.
- Distinctive: line 39
Prefer the smallest existing pattern that matches the caller:
- Distinctive: line 41
Read migration examples for verified PRs covering Django clients, staged workload rollout, sandbox wiring, and attribution continuity.
- Very specific: line 43
Use build_openai_client, build_async_openai_client, or build_async_anthropic_client from posthog/llm/gateway_client.py for Django callers …
- Very specific: line 44
Use the slugless Go base URL.
- Very specific: line 45
Use a supported phs_ or pha_ credential with llm_gateway:read.
- Very specific: line 47
Treat ai_product as telemetry only.
- Distinctive: line 50
Keep a Python fallback only when rollout needs it, and make the switch explicit in settings or the shared builder.
- Very specific: line 71
Update nearby docs and settings descriptions when the operator workflow changes.
- Distinctive: line 75
Run the narrow caller tests and the formatter or type checker for touched code.
- Distinctive: line 77
Before handing off, summarize:
≈ “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
Migrating LLM gateway callers
Use services/llm-gateway/PARITY.md as the current decision record. If it is stale or the migration reveals a new gap, run /auditing-llm-gateway-parity before continuing.
Inventory the caller
Find the production call site, client construction, settings, deployment wiring, and tests. Record:
- caller and user-facing use case
- credential source and required authorization policy
- spend owner, budgets, current Python billing behavior, and the team wallet that should own Go spend
- API shape, model, provider, streaming, and tool or structured-output requirements
- distinct ID, trace, product, team, feature flag, and custom property attribution
- timeout, retry, fallback, and error-handling behavior
- usage or quota APIs read by the caller
Search for the product name, LLM_GATEWAY, AI_GATEWAY, gateway client helpers, and gateway headers. Follow configuration into sandbox or deployment code when the call does not run in Django.
Check whether migration is supported
Match every required contract to the parity record and current code.
- If all required contracts are supported, continue with the migration.
- If a 🔎 item applies, verify it against the caller's actual model, request, and configuration.
- If a ⛔ gap applies, stop the migration. Report the exact blocker and keep the Python path.
An existing Python client or product route is not a blocker by itself.
Python's unbilled flag is not a blocker when an internal workload should debit a PostHog-owned team wallet for spend attribution. Confirm that the Go credential resolves to that team. Stop only when migration would charge a customer incorrectly, lose required customer budget policy, or violate a requirement to debit no wallet.
Implement the migration
Prefer the smallest existing pattern that matches the caller:
Read migration examples for verified PRs covering Django clients, staged workload rollout, sandbox wiring, and attribution continuity. Follow the contract demonstrated by the relevant example rather than copying its code mechanically.
- Use
build_openai_client,build_async_openai_client, orbuild_async_anthropic_clientfromposthog/llm/gateway_client.pyfor Django callers when possible. - Use the slugless Go base URL. Do not carry a Python
/{product}/path into the Go URL. - Use a supported
phs_orpha_credential withllm_gateway:read. Do not weaken auth or expose a shared secret to an untrusted runtime. - Send event labels in one
X-PostHog-PropertiesJSON object. Use the dedicated distinct ID and trace ID headers where required. - Treat
ai_productas telemetry only. Do not use it to replace trusted product auth or billing policy. - Confirm the canonical model and API shape against the Go model catalog.
- Preserve the caller's provider and fallback requirements. Use provider pinning only when the caller requires a specific host.
- Keep a Python fallback only when rollout needs it, and make the switch explicit in settings or the shared builder.
For sandbox callers, follow the existing SANDBOX_AI_GATEWAY_URL and product rollout patterns rather than inventing another environment contract.
For internal products, check with the AI gateway team before adding deployment variables or secrets so existing shared configuration can be reused.
If the target process does not have a Go credential, enable the ai-gateway feature flag for the intended paying team, then create a phs_ project secret in the PostHog dashboard with llm_gateway:read and wire it through the existing deployment secret mechanism. Credential creation is normal migration work, not a parity exception.
Update tests and docs
Invoke /writing-tests before changing tests.
Cover the observable migration contract at the lowest useful level:
- selected base URL and absence of the Python product slug
- credential and required headers without asserting secret values
- converted JSON properties and trace attribution
- model and API shape
- rollout fallback when one remains
- failure behavior the caller handles
Update nearby docs and settings descriptions when the operator workflow changes. Do not update the parity record unless implementation evidence changed; use /auditing-llm-gateway-parity when it did.
Verify
Run the narrow caller tests and the formatter or type checker for touched code. Exercise a real request when credentials and a safe development gateway are available. Confirm the event attribution and billing behavior when those contracts matter.
Before handing off, summarize:
- migrated caller and use case
- Go contracts relied on
- fallback left in place, if any
- parity blocker, if migration stopped
- checks run and any environment limitation
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.

