**Usage & cost always renders USD.** The spend panel hardcodes a dollar sign, so every… #3

Closed
opened 2026-11-03 08:51:34 +00:00 by luke · 0 comments
Owner

Reported from the pi-chat app.

Usage & cost always renders USD. The spend panel hardcodes a dollar sign, so every figure stays in US dollars even though the account's profile currency is GBP — web/src/lib/profile.ts already stores currency: 'GBP' and feeds "Currency: GBP" into the agent's profile context, so the app knows the currency it is ignoring here.

Where: web/src/lib/components/UsagePanel.svelte, fmtCost():

return n >= 0.01 ? `$${n.toFixed(2)}` : `$${n.toFixed(4)}`;

It is the only place in the app that formats a cost (grep fmtCost in web/src returns just this file), so a currency change is a three-file job.

Important: the values really are USD. src/usage.ts rolls up the SDK's per-message cost.total, priced in USD, so relabelling the number as £ would overstate spend by roughly a quarter. It needs a conversion, not a symbol swap — and a fixed rate drifts silently, so the panel should say which rate it used.

What I patched locally on this install (uncommitted, so it will be lost on the next pull) to read my own spend in pounds:

  1. src/usage.ts — add UsageCurrency { code, symbol, rate } to UsageReport; displayCurrency() returns { code: 'GBP', symbol: '£', rate } where the rate comes from PI_CHAT_USD_GBP_RATE (default 0.746, snapshot checked 2026-11-03); computeUsage() returns it alongside the existing fields.
  2. web/src/lib/types.ts — mirror the same shape.
  3. UsagePanel.svelte — fmtCost multiplies by report.currency.rate and prefixes report.currency.symbol (falling back to $/1 when the field is absent), and the Total spend tooltip shows the raw USD figure and the rate used.

Suggested upstream shape: take the symbol from the profile currency, get the rate from an env override or a small server-side daily FX fetch, and fall back to USD when the currency is unknown.


Aside — how this looked unfixed after a deploy. The new build was served and /api/usage returned the currency field, but an open tab went on rendering the previous bundle: web/static/sw.js deliberately keeps a long-lived page's route chunks in the unversioned pi-chat-assets cache, and the auto-reload only fires within 5 s of the tab regaining visibility (web/src/routes/+layout.svelte). That is defensible, but nothing in the UI says which build is running, so a stale client is indistinguishable from a failed deploy. A build id in the UI, or an "update ready" pill, would remove the ambiguity.

What I expected

Spend and per-model/per-session costs should be shown in the profile currency (£ GBP for me), converted from the USD cost that the providers actually bill — not hard-coded to $.

Severity Annoying — it works, but badly
Area Usage & cost
Reported from ian-pi (5fde841d) · dev
Filed 2026-11-03 08:51 UTC
Version local build 2026-11-03
Browser web (SvelteKit client)
Locale en-GB

Attachments, if any, are attached to this issue by the app.

**Reported from the pi-chat app.** **Usage & cost always renders USD.** The spend panel hardcodes a dollar sign, so every figure stays in US dollars even though the account's profile currency is GBP — `web/src/lib/profile.ts` already stores `currency: 'GBP'` and feeds "Currency: GBP" into the agent's profile context, so the app knows the currency it is ignoring here. Where: `web/src/lib/components/UsagePanel.svelte`, `fmtCost()`: ```js return n >= 0.01 ? `$${n.toFixed(2)}` : `$${n.toFixed(4)}`; ``` It is the only place in the app that formats a cost (grep `fmtCost` in web/src returns just this file), so a currency change is a three-file job. Important: the values really are USD. `src/usage.ts` rolls up the SDK's per-message `cost.total`, priced in USD, so relabelling the number as £ would overstate spend by roughly a quarter. It needs a conversion, not a symbol swap — and a fixed rate drifts silently, so the panel should say which rate it used. What I patched locally on this install (uncommitted, so it will be lost on the next pull) to read my own spend in pounds: 1. `src/usage.ts` — add `UsageCurrency { code, symbol, rate }` to `UsageReport`; `displayCurrency()` returns `{ code: 'GBP', symbol: '£', rate }` where the rate comes from `PI_CHAT_USD_GBP_RATE` (default 0.746, snapshot checked 2026-11-03); `computeUsage()` returns it alongside the existing fields. 2. `web/src/lib/types.ts` — mirror the same shape. 3. `UsagePanel.svelte` — `fmtCost` multiplies by `report.currency.rate` and prefixes `report.currency.symbol` (falling back to `$`/1 when the field is absent), and the Total spend tooltip shows the raw USD figure and the rate used. Suggested upstream shape: take the symbol from the profile currency, get the rate from an env override or a small server-side daily FX fetch, and fall back to USD when the currency is unknown. --- **Aside — how this looked unfixed after a deploy.** The new build was served and `/api/usage` returned the currency field, but an open tab went on rendering the previous bundle: `web/static/sw.js` deliberately keeps a long-lived page's route chunks in the unversioned `pi-chat-assets` cache, and the auto-reload only fires within 5 s of the tab regaining visibility (`web/src/routes/+layout.svelte`). That is defensible, but nothing in the UI says which build is running, so a stale client is indistinguishable from a failed deploy. A build id in the UI, or an "update ready" pill, would remove the ambiguity. **What I expected** Spend and per-model/per-session costs should be shown in the profile currency (£ GBP for me), converted from the USD cost that the providers actually bill — not hard-coded to $. | | | | --- | --- | | Severity | Annoying — it works, but badly | | Area | Usage & cost | | Reported from | ian-pi (5fde841d) · dev | | Filed | 2026-11-03 08:51 UTC | | Version | local build 2026-11-03 | | Browser | web (SvelteKit client) | | Locale | en-GB | _Attachments, if any, are attached to this issue by the app._
luke closed this issue 2026-11-03 10:33:22 +00:00
Sign in to join this conversation.
No labels
bug
from-app
upstream
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gsylabsgg/pi-chat#3
No description provided.