Skip to content

fix(gateway): apply posthog property headers on openai routes#60725

Merged
joshsny merged 1 commit into
masterfrom
llm-gateway/openai-posthog-property-headers
May 29, 2026
Merged

fix(gateway): apply posthog property headers on openai routes#60725
joshsny merged 1 commit into
masterfrom
llm-gateway/openai-posthog-property-headers

Conversation

@joshsny
Copy link
Copy Markdown
Contributor

@joshsny joshsny commented May 29, 2026

We were not applying headers to OpenAI routes, only to Anthropic ones, this adds support for doing that so we can use it for passing things like team id in django.

@joshsny joshsny changed the title fix(llm-gateway): apply posthog property headers on OpenAI routes fix(gateway): apply posthog property headers on openai routes May 29, 2026
@joshsny joshsny marked this pull request as ready for review May 29, 2026 19:46
@joshsny joshsny requested review from a team and Copilot May 29, 2026 19:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds PostHog header propagation to OpenAI-compatible LLM Gateway routes so request-scoped PostHog properties/flags are available during OpenAI request handling and callbacks.

Changes:

  • Adds Request injection and apply_posthog_context_from_headers calls across OpenAI chat, responses, and transcription endpoints.
  • Adds a regression test verifying x-posthog-property-* headers reach the request context for OpenAI chat completions.
  • Adds a type cast for non-streaming transcription handler return typing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
services/llm-gateway/src/llm_gateway/api/openai.py Applies PostHog context extraction on OpenAI routes before delegating to shared handlers.
services/llm-gateway/tests/test_openai.py Adds coverage confirming OpenAI route property headers populate request context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 29, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
services/llm-gateway/tests/test_openai.py:94-141
**Test covers only one of eight modified endpoints**

The PR applies `apply_posthog_context_from_headers` to eight route handlers (`chat_completions`, `chat_completions_with_product`, `responses_v1`, `responses_v1_with_product`, `responses`, `responses_with_product`, `audio_transcriptions`, `audio_transcriptions_with_product`), but the new test only exercises `/v1/chat/completions`. Given the team's preference for parameterised tests, parametrising this test over the full set of relevant routes (at a minimum the three non-transcription variants) would give confidence that the header-to-context wiring holds for each endpoint, not just the one that was already easiest to reach.

Reviews (1): Last reviewed commit: "fix(llm-gateway): apply posthog property..." | Re-trigger Greptile

Comment thread services/llm-gateway/tests/test_openai.py
Comment thread services/llm-gateway/src/llm_gateway/api/openai.py
@veria-ai
Copy link
Copy Markdown

veria-ai Bot commented May 29, 2026

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

The OpenAI chat-completions, responses, and transcription routes never
called apply_posthog_context_from_headers, so x-posthog-property-* headers
(e.g. a shared-key caller's team_id attribution override) were silently
dropped — only the Anthropic routes applied them. As a result $ai_generation
events fell back to the API key owner's team instead of the caller-supplied
team.

Apply the headers inline in each OpenAI endpoint, mirroring the Anthropic
routes, and add an end-to-end test asserting the property reaches the
request context during the LLM call.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@joshsny joshsny force-pushed the llm-gateway/openai-posthog-property-headers branch from a4f4c6d to 5b0109e Compare May 29, 2026 20:11
@joshsny joshsny merged commit 3f687e1 into master May 29, 2026
150 of 153 checks passed
@joshsny joshsny deleted the llm-gateway/openai-posthog-property-headers branch May 29, 2026 20:36
@deployment-status-posthog
Copy link
Copy Markdown

deployment-status-posthog Bot commented May 29, 2026

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-05-29 21:01 UTC Run
prod-us ✅ Deployed 2026-05-29 21:20 UTC Run
prod-eu ✅ Deployed 2026-05-29 21:23 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants