Skip to content

Commit 9b8a92d

Browse files
committed
Fix potential division by zero in cache percentage calculation
Add guard to ensure denominator is non-zero before calculating the cache percentage. This prevents NaN when both input_tokens and cache_read_input_tokens are 0.
1 parent 7a98de2 commit 9b8a92d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

web/app/routes/_index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,8 @@ export default function Index() {
711711
<span className="font-mono text-gray-600">
712712
<span className="font-medium text-gray-900">{(request.response.body.usage.output_tokens || 0).toLocaleString()}</span> out
713713
</span>
714-
{request.response.body.usage.cache_read_input_tokens && (
714+
{request.response.body.usage.cache_read_input_tokens &&
715+
((request.response.body.usage.input_tokens || 0) + (request.response.body.usage.cache_read_input_tokens || 0)) > 0 && (
715716
<span className="font-mono bg-green-50 text-green-700 px-1.5 py-0.5 rounded">
716717
{Math.round((request.response.body.usage.cache_read_input_tokens / ((request.response.body.usage.input_tokens || 0) + (request.response.body.usage.cache_read_input_tokens || 0))) * 100)}% cached
717718
</span>

0 commit comments

Comments
 (0)