Skip to content

[Security] Budget tracking runs after API response is returned, not before the request #79

Description

@anshul23102

Summary

In src/interceptors/fetchInterceptor.ts, the original fetch call is made and the response returned before budget tracking runs. If the budget is exceeded, the error is thrown after the LLM call has already been completed and billed.

Affected File

src/interceptors/fetchInterceptor.ts

const response = await originalFetch(input, init); // call made first
// ...
await budgetManager.track(cost.totalCost); // budget checked too late

Suggested Fix

For estimated-cost enforcement, estimate the token count from the request body before making the API call, check the budget pre-flight, and block the request if it would exceed the limit.

Severity

High

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions