Evolution of AI Budgeting at Pinterest
Pinterest's journey in budgeting AI tool usage illustrates common challenges in resource allocation within a large engineering organization. Initial attempts using daily request quotas in a network proxy (V0) proved insufficient due to varying costs per request and lack of granular control. This led to the realization that cost needed to be measured in dollars and enforced by a dedicated service rather than a generic proxy.
V1: Personal Budgets and Their Limitations
- Architecture: An entitlements system was built, recording model, token, cache usage, and cost against authenticated employees. It reserved a monthly budget for each engineer based on a spending tier.
- Pros: Provided visibility into individual spend and managerial control over budget assignments. Finance gained data for reporting and forecasting.
- Cons: Significant waste due to unused reserved budget, as money committed to one person could not be easily reallocated. Coarse tier sizes led to over-provisioning. The 'use-it-or-lose-it' incentive encouraged wasteful spending at month-end. Managerial overhead for budget reassignments was high.
V2: Shared Pools with Individual Guardrails
To address V1's shortcomings, V2 introduced two key changes: shared team pools for budget allocation and a rolling 28-day window for spend tracking instead of calendar months. This design aims to balance collective flexibility with individual accountability.
- Shared Team Pools: Money is held in pools owned by directors/VPs, who can allocate budget to their own pool and sub-pools. This allows for natural rebalancing within a team as individual needs fluctuate.
- Individual Guardrails: While budget is shared, individual limits prevent a single user from disproportionately consuming the pool. These guardrails are dynamic and do not reserve funds, allowing total guardrails in a pool to exceed its funding.
- Rolling Window: A 28-day rolling window smooths out spending patterns, eliminating the end-of-month budget rushes and escalations common with fixed monthly resets. This provides engineers more flexibility to burst as needed.
- Emergency Access: A critical feature allowing engineers to temporarily bypass limits for 24 hours for urgent work, with audit trails and pool owner notifications. This prioritizes engineering velocity over strict budget enforcement in critical situations.
- Fail Open Design: The authorization service fails open, meaning if it's unavailable, the gateway continues to admit requests. This prevents a budget dependency from halting engineering work, accepting potential overspend during outages as a trade-off.
System Design for Budget Authorization
The core of the system involves a shared model gateway and a spend authorization service.
- Model Gateway: Sits between AI coding tools and model providers. Requires configured prices for each model, routes requests, and prices requests based on token usage and finance-set rates.
- Spend Authorization Service: Compares an employee's and pool's recorded spend against their respective limits before admitting a request. Reads aggregate usage from the spend database.
- Usage Logging: Retains raw records for investigation and updates aggregate values for fast querying. Usage is recorded *after* a response completes, allowing for small in-flight overruns rather than per-request budget reservation to avoid performance slowdowns.
💡Trade-offs in Budget Enforcement
The design decision to allow "fail open" for the authorization service and accept "in-flight overruns" demonstrates a practical trade-off: prioritizing developer productivity and system resilience over strict, real-time budget enforcement. This approach acknowledges that the cost of halting work or adding latency might outweigh the cost of minor overspending.