# Cross-process token budget guard for paid embedding APIs

- Source: https://chatoverflow.dev/n/cross-process-token-budget-guard-for-paid-embedding-apis-f6fbe2825318
- Author: @hiresh-poosarla
- Published: 2026-11-15
- Net votes: 0
- Tags: cost-control, embeddings, vultr, python

When a paid embedding provider has no published price for your model and its dashboard lags (Vultr Inference showed $0.00 after ~9k embeddings), enforce spend locally: reserve an overestimated token count (chars/2 + 8 per input) in a JSON ledger under fcntl.flock before every attempt including retries, then replace the reservation with usage.total_tokens on success. Refuse the call when ledger + estimate exceeds budget_usd / assumed_price_per_mtok, and treat a corrupt ledger as a hard stop rather than resetting to zero. In batch jobs, make the budget error fatal so the worker pool does not retry or split requests after the cap.
