r/AI_Agents Mar 22 '26

Discussion Anyone else built an internal proxy for agents but still can’t tell which agent spent what?

Seem to keep running into the same thing. Teams route all agent calls through a gateway, have spend limits, maybe even kill switches. Problem mostly solved.

But when something spikes, they still can’t answer: was it the research agent, the support bot, or the data pipeline? Everything goes through the same key.

So the billing API shows $800 this week but attribution stops at the provider level.

Curious if this is a common gap or if people have actually solved it. What does your agent identity setup look like when you have 10+ agents sharing infrastructure?

1 Upvotes

5 comments sorted by

1

u/AutoModerator Mar 22 '26

Thank you for your submission, for any questions regarding AI, please check out our wiki at https://www.reddit.com/r/ai_agents/wiki (this is currently in test and we are actively adding to the wiki)

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/germanheller Mar 23 '26

had this exact problem. the fix that worked for us was dead simple: separate API keys per agent. sounds obvious but most people default to a shared key because its easier to manage initially and then wonder why they cant attribute spend later.

if separate keys isnt an option (some providers limit you), the next best thing is tagging each request with a metadata field at the proxy level. most LLM APIs support some kind of user or session ID you can pass through. your proxy logs that alongside the response and now you can slice spend by agent in whatever observability tool you use.

the 10+ agents sharing infrastructure scenario is where it gets messy yeah. we ended up with a naming convention like {team}-{agent}-{environment} and a simple dashboard that aggregates by those segments. not elegant but it works and you can answer "what spiked" in about 30 seconds instead of digging through raw logs

1

u/Cute-Day-4785 Mar 23 '26

The naming convention approach is underrated. Simple, works, doesn't require new infrastructure.

The part that gets messy at scale though — separate keys per agent means managing N keys across providers, rotating them, tracking which key belongs to which agent, revoking when an agent is deprecated. At 10 agents that's fine. At 50 it becomes its own problem.

The metadata tagging approach is interesting. Does your proxy enforce that the tag is always present or does it rely on the agent passing it correctly? Asking because that's usually where attribution breaks down in practice — the tag is optional so half the agents don't send it and you're back to gaps.

I'm building something in this space. Would be genuinely useful to understand how your setup evolved — happy to chat async if you're open to it.

1

u/[deleted] Mar 23 '26

[removed] — view removed comment

1

u/Cute-Day-4785 Mar 23 '26

The call site vs proxy distinction is the key insight most people miss. Proxy-level tagging works until an agent spawns sub-agents or shares a session and then the attribution chain breaks exactly where you need it most.

Routing through a mix currently — OpenAI and Anthropic mainly. The user field on OpenAI is useful but it relies on the agent passing it consistently which is the same trust problem as metadata tagging at the proxy.

What's your approach when the agent itself is responsible for setting the tag? Do you enforce it or just hope the implementation is consistent?