Skip to content

budget: Budget as a first-class object parsed from x-token-* headers #185

Closed

Description

@amirkhan-ak-sf

Summary

Piece 2 of 6. Every response carrying x-token-* updates a Budget on the
Donkey instance. The developer never parses a header.

donkey.budget.limit          # int, tokens per window
donkey.budget.remaining      # int, from the last response
donkey.budget.reset_at       # datetime, converted from x-token-reset (ms)
donkey.budget.observed_at    # staleness of the above
donkey.budget.fraction_used  # 0.0-1.0

Honest limitation to state in the docstring

The gateway exposes budget only in-band. There is no budget-query endpoint,
so remaining is only as fresh as the last call and a new process knows
nothing until its first request. observed_at exists so nobody mistakes stale
data for live data. This is upstream gap #2.

Why it matters — Scenario A

fraction_used per agent on a dashboard. The owner sees it climbing at 14:00
and requests an increase before the 16:00 peak instead of after the outage.

Acceptance criteria

  • x-token-reset in milliseconds converts correctly — fixture with a known
    value, assert reset_at to the second.
  • Budget is per-Donkey, not global; two instances with different
    credentials never share state.
  • observed_at is set on every parse and exposed publicly.
  • Missing x-token-* headers leave the object in a defined "unobserved"
    state rather than raising.

Cross-surface impact

Out of scope

Pacing (pace() / wait_for_reset()) — its own issue.

Activity

  1. added
    enhancementNew feature or request
    size/s~half day, one file
    area:budgetBudget object, pacing, rate-limit awareness (1.3)
    six-piece-minimumPart of the minimum set that justifies installing the SDK
    priority/p0Critical: blocks the phase
    on Sep 4, 2026
  2. self-assigned this
    on Sep 8, 2026
  3. added a commit that references this issue on Sep 8, 2026
    af50d6e
  4. tommasobolis commented on Sep 8, 2026

    @tommasobolis
    Collaborator

    Fixed by #291 (merged as af50d6e).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:budgetBudget object, pacing, rate-limit awareness (1.3)enhancementNew feature or requestpriority/p0Critical: blocks the phasesix-piece-minimumPart of the minimum set that justifies installing the SDKsize/s~half day, one file

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions