Skip to content

Commit e81ff69

Browse files
authored
Fix error when parsing usage details for video without audio track in Google models (#2507)
1 parent d6d7f37 commit e81ff69

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

pydantic_ai_slim/pydantic_ai/models/gemini.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ def _metadata_as_usage(response: _GeminiResponse) -> usage.Usage:
878878
metadata_details = cast(list[_GeminiModalityTokenCount], metadata_details)
879879
suffix = key.removesuffix('_details')
880880
for detail in metadata_details:
881-
details[f'{detail["modality"].lower()}_{suffix}'] = detail['token_count']
881+
details[f'{detail["modality"].lower()}_{suffix}'] = detail.get('token_count', 0)
882882

883883
return usage.Usage(
884884
request_tokens=metadata.get('prompt_token_count', 0),

pydantic_ai_slim/pydantic_ai/models/google.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ def _metadata_as_usage(response: GenerateContentResponse) -> usage.Usage:
603603
if key.endswith('_details') and metadata_details:
604604
suffix = key.removesuffix('_details')
605605
for detail in metadata_details:
606-
details[f'{detail["modality"].lower()}_{suffix}'] = detail['token_count']
606+
details[f'{detail["modality"].lower()}_{suffix}'] = detail.get('token_count', 0)
607607

608608
return usage.Usage(
609609
request_tokens=metadata.get('prompt_token_count', 0),

0 commit comments

Comments
 (0)