Track OpenAI cost per agent without putting a gateway in front
When many AI agents use the same OpenAI key, the monthly bill can appear as one total number. That makes it hard to see which agent, feature, or run caused the spend. Many tools solve this by sending every through a gateway or proxy, but that can add delay, create another failure point, and expose prompts and responses to a third party.
The proposed design uses an SDK that wraps the OpenAI client while still sending directly to OpenAI. The SDK measures each call inside the app and sends only metadata to a separate control API, such as s, cost, and an agent or run tag. Prompt and response text stays inside the user’s own process.
The code change is framed as swapping the OpenAI import, reading the Spaturzu and OpenAI keys from , and tagging a call with an agent name in one line. The title also says the system supports per-agent budgets and hard caps enforced in the SDK.
Key points
- One shared OpenAI key can hide which agent or feature created the bill.
- Gateway-based tracking can add latency, another failure point, and exposure of prompts and responses.
- The SDK wraps the OpenAI client but keeps calls going directly to OpenAI.
- Only metadata such as s, cost, and agent or run tags is sent to the control API.
- The design claims per-agent budgets and hard caps are enforced inside the SDK.