Repository navigation
Conversation
… response
response.created and response.in_progress echo the requested service
tier ("auto"), and only the terminal response names the tier that
served the request. The stream state kept the first value it saw, so
$ai_service_tier was "auto" for streamed Responses calls. Keep the
latest non-null tier instead.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
A streamed OpenAI Responses call reports the wrong
$ai_service_tier. In a real stream,response.createdandresponse.in_progressecho the requested tier and only the terminal response names the tier that served the request. In the recorded posthog-js cassettepackages/ai/harness/fixtures/openai-responses-stream.jsonthe values areauto, thenauto, thendefault._ResponsesStreamState._record_response_metadata(posthog/ai/openai/_streaming.py) kept the first non-null value it saw. So every streamed Responses call that asked forservice_tier="auto"(or left it to the project default) captured$ai_service_tier: "auto", and$ai_model_parameters.service_tierwas"auto"too. Neither is a served tier. Non-streamed calls already read the tier from the final response, and@posthog/ai'sOpenAIResponsesStreamAccumulatorkeeps the latest non-null value.The state now keeps the latest non-null tier, which is the one on the terminal response. Chat Completions streams aren't changed, because their chunks all carry the served tier.
Repro (before the fix):
💚 How did you test it?
test_streaming_responses_reports_tier_from_terminal_responseand its async twin go through the wrappedresponses.create(stream=True)with the created → in_progress → completed sequence (auto,auto,default). Both fail onmain(assert 'auto' == 'default') and pass with the fix.pytest posthog/test/ai/openai: 216 passed, 1 skipped.pytest posthog/test/ai: 1927 passed, 15 skipped.ruff format --check .,ruff check ., the mypy baseline filter andpython -W error -c "import posthog"are all clean.📝 Checklist
If releasing new changes
sampo addto generate a changeset file (.sampo/changesets/responses-stream-served-service-tier.md, apypi/posthog: patchentry written by hand in the same format as the existing changesets)🤖 Agent context
Autonomy: Human-driven (agent-assisted)
@posthog/ai's Responses accumulator and with the recorded OpenAI Responses cassette. The agent wrote the failing tests first, then the fix. I read the full diff after the PR was opened.