migrating-llm-gateway-callers

Migrates LLM callers from the Python llm-gateway to the Go-based PostHog AI gateway.

713|118|Updated Aug 11, 2020
One-click install
npx skills add https://github.com/PostHog/posthog-foss --skill migrating-llm-gateway-callers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: migrating-llm-gateway-callers
Source: https://github.com/PostHog/posthog-foss/tree/main/.agents/skills/migrating-llm-gateway-callers
Command: npx skills add https://github.com/PostHog/posthog-foss --skill migrating-llm-gateway-callers

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Moving an LLM caller from PostHog's legacy Python services/llm-gateway to the new Go-based PostHog/ai-gateway involves many subtle contracts—URL shapes, credential scopes, header formats, billing attribution, and feature parity—that are easy to get wrong. This Skill guides the migration end to end so callers are converted correctly or stopped with a documented blocker when Go parity is missing.

Core Features & Use Cases

  • Caller Inventory: Locates the production call site, client construction, settings, deployment wiring, and tests, recording credentials, billing ownership, model, streaming, and attribution requirements.
  • Parity-Gated Migration: Checks every required contract against services/llm-gateway/PARITY.md and stops with an explicit blocker when a Go gap exists, keeping the Python path intact.
  • Guided Implementation: Applies shared Go-capable client builders (build_openai_client, build_async_openai_client, build_async_anthropic_client), slugless base URLs, phs_/pha_ credentials, and X-PostHog-Properties attribution, with verified PR examples for Django, sandbox, and cross-repository patterns.
  • Use Case: An engineer needs to route the Signals grouping workload through the AI gateway. The Skill inventories the caller, confirms parity, wires the opt-in client with correct headers and billing attribution, updates tests, and summarizes the migration.

Quick Start

Ask the agent to migrate a specific LLM caller, such as "migrate the eval-report agent from services/llm-gateway to the AI gateway," and it will inventory the caller, check parity, implement the migration, and update tests.

Frequently Asked Questions about migrating-llm-gateway-callers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate an LLM caller to the PostHog AI gateway?

Inventory the caller's contract (credentials, billing, model, attribution), check each requirement against services/llm-gateway/PARITY.md, then implement using the shared builders in posthog/llm/gateway_client.py with the slugless Go base URL. Update tests to cover the selected URL, headers, and attribution.

What credentials does the Go AI gateway require?

The Go gateway requires a supported phs_ or pha_ credential with the llm_gateway:read scope. Create a phs_ project secret in the PostHog dashboard and wire it through the existing deployment secret mechanism; never weaken auth or expose shared secrets to untrusted runtimes.

When should an LLM gateway migration be stopped?

Stop when a required contract maps to a parity gap in PARITY.md, when migration would charge a customer incorrectly, lose required customer budget policy, or violate a requirement to debit no wallet. Report the exact blocker and keep the Python path.

How does attribution differ between the Python and Go gateways?

The Go gateway expects event labels in a single X-PostHog-Properties JSON object plus dedicated distinct ID and trace ID headers, rather than Python's per-key metadata headers. The ai_product field is telemetry only and must not replace trusted product auth or billing policy.

Can I keep a Python fallback during the gateway migration?

Yes, keep a Python fallback when rollout needs it, but make the switch explicit in settings or the shared builder. Staged rollout patterns let you move one workload at a time and revert by clearing the opt-in setting.