Skip to content

Gemini 호출당 토큰 사용량 로깅 - #45

Merged
m-a-king merged 1 commit into
mainfrom
feat/44-gemini-token-usage-log
Aug 16, 2026
Merged

Gemini 호출당 토큰 사용량 로깅#45
m-a-king merged 1 commit into
mainfrom
feat/44-gemini-token-usage-log

Conversation

@m-a-king

Copy link
Copy Markdown
Collaborator

Gemini 응답의 usageMetadata 를 버리고 있어 호출당 토큰이 얼마인지 관측값이 없다.

media_resolution 설정을 검토하다 드러났다. 문서상 Gemini 3 계열은 미지정 기본이 이미지 1120 토큰(MEDIA_RESOLUTION_HIGH 와 동일)이라 지금 값을 바꿀 이유가 없어 보이는데, 그 판단이 전부 문서 근거이고 실측이 아니다. 모델을 바꾸거나 해상도를 조절할 때 근거로 쓸 숫자가 없고 비용 추적도 막혀 있다.

무엇을

gemini usage model=gemini-3.5-flash-lite promptTokens=1300 candidateTokens=40 totalTokens=1340 imageTokens=1120
  • GeminiGenerateContentResponseusageMetadata 를 wire 필드로 추가 (promptTokenCount·candidatesTokenCount·totalTokenCount·promptTokensDetails)
  • promptTokensDetails 의 modality 별 내역에서 이미지 몫을 분리해 함께 남긴다. 이미지 경로와 링크 경로의 토큰 비중을 로그만으로 가를 수 있다
  • usage 가 없는 응답(구버전·부분 실패)은 usageOrEmpty 로 좁혀 호출부가 null 분기를 하지 않게 했다

메트릭이 아니라 로그로 둔 이유: 지금 필요한 건 추세가 아니라 "이 호출이 얼마였나" 의 원장이고, 라벨 축(모델 x modality)이 붙으면 카디널리티가 는다. 추세가 필요해지면 이 로그를 근거로 메트릭을 설계하면 된다.


연관 이슈

- 응답의 usageMetadata 를 버리고 있어 호출당 토큰이 얼마인지 관측값이 없었다. media_resolution 설정을 검토하다 드러났는데, "Gemini 3 계열은 기본이 이미 이미지 1120 토큰" 이라는 판단이 전부 문서 근거이고 실측이 아니었다
- promptTokensDetails 의 modality 별 내역에서 이미지 몫을 분리해 함께 남긴다. 이미지·링크 경로의 토큰 비중을 로그만으로 가를 수 있게 하려는 것이다
- 메트릭이 아니라 로그로 둔다. 지금 필요한 건 추세가 아니라 "이 호출이 얼마였나" 의 원장이고, 라벨 축(모델 x modality)이 붙으면 카디널리티가 는다
- usage 가 없는 응답(구버전·부분 실패)은 usageOrEmpty 로 좁혀 호출부가 null 분기를 하지 않게 했다
@m-a-king m-a-king added the feat 외부 가시적 새 기능 label Aug 16, 2026
@m-a-king m-a-king linked an issue Aug 16, 2026 that may be closed by this pull request
@m-a-king m-a-king self-assigned this Aug 16, 2026
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown

Important

Review available on request

  • 🔍 Trigger review

Reviews should be triggered manually for repositories with fewer than 10 stars. Select Trigger review above or comment @coderabbitai review to review the latest changes. For a full review, comment @coderabbitai full review.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 74b19594-d676-4bd8-b84d-95b4098926aa


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@m-a-king
m-a-king merged commit 54390b9 into main Aug 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat 외부 가시적 새 기능

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini 응답의 토큰 사용량을 로그로 남긴다

1 participant