Check Gemini response success before trying to parse usage metadata#124
Merged
swerner merged 3 commits intosublayerapp:mainfrom Jun 13, 2025
Merged
Conversation
804819c to
9b23db7
Compare
Contributor
Author
|
(similar issues may be present for other providers). |
Contributor
|
Thanks @andyw8! |
Contributor
Yeah probably...I had been putting this change off as I was thinking about a better way to handle logging...potentially even creating a Provider base class...but guess I'd put it off too long... |
swerner
approved these changes
Jun 13, 2025
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.
If the API key is missing, Gemini will respond with:
{ "error": { "code": 403, "message": "Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API.", "status": "PERMISSION_DENIED" } }so
response["usageMetadata"]["promptTokenCount"]will raise an exception about a method being called onnil.(there may be use cases where there is an error but
usageMetadatais still available. If so, then a check for that key's presence would be better).