Gemini 호출당 토큰 사용량 로깅 - #45
Merged
Merged
Conversation
- 응답의 usageMetadata 를 버리고 있어 호출당 토큰이 얼마인지 관측값이 없었다. media_resolution 설정을 검토하다 드러났는데, "Gemini 3 계열은 기본이 이미 이미지 1120 토큰" 이라는 판단이 전부 문서 근거이고 실측이 아니었다 - promptTokensDetails 의 modality 별 내역에서 이미지 몫을 분리해 함께 남긴다. 이미지·링크 경로의 토큰 비중을 로그만으로 가를 수 있게 하려는 것이다 - 메트릭이 아니라 로그로 둔다. 지금 필요한 건 추세가 아니라 "이 호출이 얼마였나" 의 원장이고, 라벨 축(모델 x modality)이 붙으면 카디널리티가 는다 - usage 가 없는 응답(구버전·부분 실패)은 usageOrEmpty 로 좁혀 호출부가 null 분기를 하지 않게 했다
|
Important Review available on request
Reviews should be triggered manually for repositories with fewer than 10 stars. Select Trigger review above or comment ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
왜
Gemini 응답의
usageMetadata를 버리고 있어 호출당 토큰이 얼마인지 관측값이 없다.media_resolution설정을 검토하다 드러났다. 문서상 Gemini 3 계열은 미지정 기본이 이미지 1120 토큰(MEDIA_RESOLUTION_HIGH와 동일)이라 지금 값을 바꿀 이유가 없어 보이는데, 그 판단이 전부 문서 근거이고 실측이 아니다. 모델을 바꾸거나 해상도를 조절할 때 근거로 쓸 숫자가 없고 비용 추적도 막혀 있다.무엇을
GeminiGenerateContentResponse에usageMetadata를 wire 필드로 추가 (promptTokenCount·candidatesTokenCount·totalTokenCount·promptTokensDetails)promptTokensDetails의 modality 별 내역에서 이미지 몫을 분리해 함께 남긴다. 이미지 경로와 링크 경로의 토큰 비중을 로그만으로 가를 수 있다usageOrEmpty로 좁혀 호출부가 null 분기를 하지 않게 했다메트릭이 아니라 로그로 둔 이유: 지금 필요한 건 추세가 아니라 "이 호출이 얼마였나" 의 원장이고, 라벨 축(모델 x modality)이 붙으면 카디널리티가 는다. 추세가 필요해지면 이 로그를 근거로 메트릭을 설계하면 된다.
연관 이슈