diff --git a/services/www/src/docs/content/build/plugins/gui/index.mdx b/services/www/src/docs/content/build/plugins/gui/index.mdx index fa1dab4a623..2b40b1063c5 100644 --- a/services/www/src/docs/content/build/plugins/gui/index.mdx +++ b/services/www/src/docs/content/build/plugins/gui/index.mdx @@ -2312,6 +2312,28 @@ interface NotifyResult { } ``` +### Usage data + +A session's token, cost and plan figures are in its server's data, the same reactive store the app reads for the +header's "28k ยท $0.28". Read them there rather than from opencode's database. + +```ts +import { lastAssistantWithUsage } from "@opencode/client/solid" + +const data = session.server.data +const info = () => data.session.get(session.id) + +const tokens = () => info()?.tokens // this session's tokens by kind +const cost = () => data.session.cost(session.id) // USD, with subagent sessions +const step = () => lastAssistantWithUsage(data.session.message.list(session.id), info()?.revert?.messageID) +const limits = () => (session.location ? data.location.usage.limits(session.location) : undefined) +``` + +- `step()` is the assistant step whose tokens fill the context window now, as the app's context ring uses. Compare its + `tokens` with the model's `limit.context` from `data.location.model.list`. +- `limits()` holds the OpenCode Console budgets and Go plan allowance once `data.location.usage.sync(location)` has + loaded them. It is `null` when the server reports none. + ### Tabs `ctx.tabs` reads and changes the shell's tab strip: the sessions and drafts open as tabs. This moves a session's tab to