Repository navigation
fix(ai): record the HTTP status of google-genai errors - #1110
Merged
marandaneto merged 2 commits intoOct 23, 2026
Merged
Conversation
The generation and embedding wrappers read the HTTP status of a failed call from the exception's status_code, which OpenAI and Anthropic errors have. google-genai's APIError (ClientError, ServerError) carries it as code, so every failed Gemini call was captured with $ai_http_status 0. Read either attribute through a small helper; a code outside the HTTP range still counts as no status. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
pcbeingused333
force-pushed
the
fix/gemini-error-http-status
branch
from
October 23, 2026 06:52
0b5fe1e to
de6b4ba
Compare
marandaneto
approved these changes
Oct 23, 2026
marandaneto
enabled auto-merge (squash)
October 23, 2026 12:35
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
The generation wrappers (
call_llm_and_track_usageand its async twin) and the Gemini embedding outcome read the HTTP status of a failed call from the exception'sstatus_code, which OpenAI and Anthropic errors have. google-genai'sAPIError(ClientErrorandServerError) keeps the status incode, so every failed Gemini call was captured with$ai_http_status: 0, including 429 and 503 responses.A small helper,
_get_http_status, now readsstatus_codeand, when it is missing,code; acodeoutside the HTTP range (a gRPC code, for example) still counts as no status, and errors without either give 0 as before. The two wrappers and the Gemini embedding outcome use it.💚 How did you test it?
posthog/test/ai/test_http_status.py: the helper onstatus_code,code, an out-of-range or non-integercodeand a plain exception; realgoogle.genai.errors.ClientError(429) andServerError(503) through the sync wrapper, and aClientErrorthrough the async one; and an error withstatus_codethrough the sync wrapper to show it is unchanged. The three google-genai cases fail onmain(status 0) and pass with the change.posthog/test/ai/geminiandposthog/test/ai/test_capture_contract.pywith the new test: 135 passed, 5 skipped.📝 Checklist
If releasing new changes
sampo addto generate a changeset file (added.sampo/changesets/gemini-error-http-status.mdin the same format)🤖 Agent context
Autonomy: Fully autonomous