Context meter
ui.context_meter(used, limit) shows how full an AI model’s context window is: a small ring and 48k / 200k. It is gray below 80%, yellow from 80% and red from 95%, and its tooltip gives the exact counts. ui.format_tokens(count) writes a count the short way: 950, 4.5k, 48k, 1.25M.
ui.context_meter · Category: AI agents · Full reference →


pz.row([ ui.context_meter(48_000, 200_000), ui.context_meter(170_000, 200_000), ui.context_meter(196_000, 200_000),], spacing=24, align="center")When to use
Section titled “When to use”- In the toolbar or the input box of an agent’s chat, so the user sees when a conversation gets long.
import pyzed as pzfrom pyzed import ui
pz.row([ ui.context_meter(48_000, 200_000), ui.context_meter(170_000, 200_000), ui.context_meter(196_000, 200_000),], spacing=24, align="center")Variants
Section titled “Variants”Drawn as the pointer shows it: tooltips only open on hover.


Code
ui.context_meter(48_000, 200_000)

Code
ui.context_meter(170_000, 200_000)

Code
ui.context_meter(196_000, 200_000)

Code
ui.context_meter(48_000, 200_000)Short counts
Section titled “Short counts”ui.format_tokens returns the text the meter shows, for your own labels.


format_tokens(950)Code
ui.label(ui.format_tokens(950), mono=True)

format_tokens(4_500)Code
ui.label(ui.format_tokens(4_500), mono=True)

format_tokens(48_000)Code
ui.label(ui.format_tokens(48_000), mono=True)

format_tokens(1_250_000)Code
ui.label(ui.format_tokens(1_250_000), mono=True)Events
Section titled “Events”Context meter has no events of its own: it shows what you give it. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.
Properties and API
Section titled “Properties and API”ui.context_meter
Section titled “ui.context_meter”context_meter(used, limit, *, theme=None)How full a model’s context window is, like Zed’s token counter: a small ring and 48k / 200k, yellow past 80% and red past 95%.
| Property | Default | Description |
|---|---|---|
used |
required | Tokens in use. |
limit |
required | The model’s window. |
theme |
None |
Theme. |
ui.format_tokens
Section titled “ui.format_tokens”format_tokens(count)A short token count: 950, 4.5k, 48k, 1.25M.
| Property | Default | Description |
|---|---|---|
count |
required | Tokens. |