48-Hour Field Notes: I Built a Token Ledger Before Trusting Any Free Tier
Описание и применение
Создан локальный журнал токенов и скрипт сводки для точного учёта использования бесплатного уровня MonkeyCode, а также тест для проверки отказов и задержек на бесплатном сервере.
Задача
Determine accurate token usage and failure handling for a free-tier AI service before deploying an agent loop.
Результат
Accurate token accounting and failure detection enabled safe use of the free tier; retries and server changes were identified and mitigated.
Рабочий процесс
- 1. Implement meter.py to append a row per model call with provider, model, prompt_tokens, completion_tokens, total_tokens, and note.
- 2. Wrap each API call to log an "attempt" row before sending and an "outcome" row after receiving a response or error.
- 3. Run the loop with retry on 429 and read timeouts, ensuring all attempts are logged regardless of success.
- 4. Execute summary.py to compute calls, p50 tokens, null counts, span, and burn rate from the ledger.
- 5. Perform a smoke test using curl against the current base URL and model ID to check for truncation and latency issues on the free server.
Доказательства
"The ledger lives locally, and it records what each call reported about itself."
"I ran a loop that retried on 429 and on read timeouts, and the ledger showed 41 calls while the client had issued 58."
"Moving a worker onto a remote free server felt like a speed decision, and it was really a lifecycle decision."
- Дата записи: 2026-10-18T08:41:26.611Z