
Migrating LLM Gateway Callers
FreeStreamline the transition to PostHog's AI Gateway.
Free Β· Opens the source repo
What Migrating LLM Gateway Callers does
The Migrating LLM Gateway Callers skill provides a structured approach for developers looking to migrate LLM callers from the legacy llm-gateway service to the new ai-gateway within PostHog. This skill is particularly useful when integrating new gateway callers, converting existing Python integrations, or modifying gateway configurations such as URLs and headers. By following the outlined steps, developers can ensure a smooth transition while maintaining the integrity of their applicationβs architecture.
The migration process begins with an inventory of the existing caller's contract, which includes critical parameters such as API shape, authorization policies, and error handling behavior. The skill guides users through verifying that the required contracts are supported by the new gateway. If any gaps are identified, the migration is halted, and the specific blocker is documented, preventing potential issues before they arise.
Once the necessary checks are complete, developers can implement the migration using established patterns and examples provided in the accompanying documentation. This includes leveraging existing client builders and ensuring that all configurations adhere to the required standards without compromising security. The skill emphasizes the importance of updating tests and documentation to reflect changes made during the migration process, ensuring that the entire team is aligned with the new setup.
This skill is designed for developers and engineers who are tasked with maintaining or upgrading PostHogβs integrations with LLM services. By following the skill's instructions, users can confidently navigate the complexities of migration while minimizing disruptions to their existing workflows.
When to use it
Use this skill when you need to migrate existing LLM gateway callers or integrate new ones into PostHog's ai-gateway.
When not to use it
This skill is not suitable for scenarios where you are not using PostHog's infrastructure or when migrating non-LLM services.
What you can build with it
Migrating an Existing Caller
When transitioning an existing LLM caller to the new ai-gateway, this skill provides a step-by-step guide to ensure all contracts are met.
Integrating a New Gateway Caller
Use this skill to streamline the process of adding a new LLM gateway caller, ensuring compliance with PostHog's standards.
Updating Gateway Configurations
When changing gateway URLs or headers, this skill helps maintain consistency and security throughout the migration.
How to install Migrating LLM Gateway Callers
View source1. Install with the skills CLI
npx skills add posthog/posthog/migrating-llm-gateway-callers --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by posthogMigrating 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
Frequently asked questions about Migrating LLM Gateway Callers
Similar skills
WinMD API Search
Easily find and explore Windows desktop APIs.
WebMCPify
Transform any web app into an agent-ready platform.
Phoenix Tracing
Instrument LLM applications with OpenInference tracing.
Foundry Hosted Agent CopilotKit
Guidance for developing agentic web apps on Azure.
Power Automate Foundation
Connect AI agents to Power Automate seamlessly.
Power Automate Flow Builder
Efficiently build and deploy Power Automate flows programmatically.
