Skip to content

fix: harden token cost refresh script - #918

Open
Ghraven wants to merge 1 commit into
apache:mainfrom
Ghraven:raven-harden-token-costs
Open

fix: harden token cost refresh script#918
Ghraven wants to merge 1 commit into
apache:mainfrom
Ghraven:raven-harden-token-costs

Conversation

@Ghraven

@Ghraven Ghraven commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Problem

telemetry/ui/scripts/token_costs.py refreshes pricing metadata from LiteLLM using an unbounded requests.get() call. If the remote endpoint stalls, the script can hang indefinitely. It also writes the generated JSON without an explicit text encoding, which makes the output depend on the platform default encoding.

Before / after

Before:

  • remote fetches had no timeout
  • HTTP error responses were passed to response.json()
  • model_costs.json was written with the process default text encoding

After:

  • the fetch is bounded with a 30 second timeout
  • HTTP failures are surfaced via raise_for_status() before parsing JSON
  • the generated JSON is written with encoding="utf-8"

Verification

  • python -m py_compile telemetry/ui/scripts/token_costs.py
  • git diff --check
  • Ran the script from a temp working directory and confirmed it generated model_costs.json

@github-actions github-actions Bot added the area/ui Burr UI (telemetry frontend) label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ui Burr UI (telemetry frontend)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant