Attribute Cloud Costs to Microservices and Source Code

Written by Ishan Kamat | Sep 17, 2026, 11:11:38 PM

Cloud bills usually answer the least useful question first: what you spent. Engineering teams need the next answer immediately: which microservice, function, or code path caused that spend.

That gap matters more in modern architectures. Microservices, serverless functions, and AI-enabled features spread usage across dozens of components, while cost spikes often come from a very small number of hot paths. In one case, a single call to Google Cloud Storage was adding roughly $7,000 a month in avoidable storage-operations cost, a gap invisible in the service-level total and only visible once cost was traced to that specific function. That is exactly why we built cost attribution that reaches all the way to the code that generated it.

Why microservice-level cost attribution empowers engineers and speeds optimization

Resource-level billing views are useful for finance, but they are too coarse for remediation. If a team only sees spend by account, cluster, or provider service, the next step is still manual investigation. Engineers have to trace logs, inspect deployments, and guess which release or feature introduced the increase.

Microservice-level attribution changes that, giving ownership to the team that can actually fix the issue and narrowing the search from a broad environment to a specific component. Source-code-level attribution goes one step further by showing which function or call site created the cost, so optimization becomes an engineering task with a clear starting point.

 

What automatic billing attribution should actually do

There are two very different categories of cost tooling, and the distinction matters.

The first category organizes spend after the fact. It labels resources, groups charges, and produces cleaner reports. That helps with budgeting, but it still leaves engineers to translate infrastructure cost into application behavior.

The second category attributes cost directly to the software that produced it. That means mapping usage back to microservices, serverless functions, code modules, and the call paths behind API consumption. This is the level where developers can make a change, review impact, and merge a fix.

Here is the practical difference:

Capability

Basic billing visibility

Code-level attribution with Frugal

Unit of analysis

Account, project, resource, tag

Microservice, feature, file, function, call site

Root cause speed

Manual investigation

Immediate, engineering-ready context

AI API cost tracking

Provider-level totals

Specific code path causing token or request spend

Serverless cost tracking

Function or service summary

Business logic behind the invocation

Remediation path

Dashboard follow-up

Reviewable pull request with expected savings

From cost data to merge-ready fixes

Finding the expensive path is only half the job. Teams still need to fix it, and they need to do that inside the workflow they already use.

That is why our platform does more than surface a cost anomaly. A Frugal Fix is a ready-to-review pull request tied to the issue it resolves, with expected savings quantified before the team merges. Engineers get a concrete code change they can evaluate and merge in the same sprint the issue was found.

This shift-left model matters because expensive patterns often start in application code long before finance or platform teams notice the bill. By putting cost context into the IDE, GitHub, and coding agents, we move cloud cost control closer to the moment the decision is made. The result is less operational drag and faster savings, especially for AI API usage where spend can rise very quickly. How we attribute spend down to the code

Our attribution model connects source, billing, and observability data so spend can be tied to the specific component, service, feature, or function responsible. That matters in architectures where infrastructure is shared and cost is not obvious from resource names alone.

The call-site model is especially important for AI and serverless workloads. If application code routes a model request through a shared helper, attribution should not stop at the helper. We trace past that indirection and link cost to the business code that actually made the decision to invoke the API. That gives teams a durable, useful answer about ownership.

We also keep attribution stable over time by identifying runtime identity based on the file and function, not the line number. That means normal edits do not break historical understanding of where spend came from. In practice, this is what allows teams to track recurring hotspots instead of re-solving the same attribution problem after every refactor.

Where this matters most: serverless and AI APIs

Serverless systems are efficient because they scale with demand, but that same usage-based model can hide expensive paths until bills arrive. A low-traffic function may be irrelevant, while one heavily used function can dominate spend. The same pattern shows up in AI features, where a single prompt path, retry loop, or model-selection branch can drive a disproportionate share of API cost.

Coarse reporting can’t answer these questions on its own: teams need to know which function generated the requests, which feature triggered the behavior, and which code path should be changed first. In the Google Cloud Storage example above, a single call was responsible for roughly $7,000 a month in avoidable cost, invisible at the service level until traced down to the function. That kind of concentration is a classic Cost Trap, and it shows up constantly in serverless and AI-enabled systems, which is exactly where code-level attribution creates fast returns.

What strong cost attribution tools looks like in practice

Engineering leaders evaluating this category should focus on four questions.

How deep does the attribution go?

The useful boundary is the code module, microservice, or feature a team owns. If attribution stops at the cloud account, remediation will stay slow.

Does it produce a fix you can act on?

A dashboard can explain what happened, but it cannot merge the fix. The practical bar is whether the platform can generate a reviewable change with savings attached.

Will the attribution remain accurate as code changes?

Attribution should survive normal edits and shared abstractions. Durable mapping to file and function is much more useful than brittle line-level tracking.

Does it fit the developer workflow?

Cost controls work better when they show up where engineers already make decisions: in pull requests, source control, and coding environments.

Why teams use Frugal to close the loop

We built the platform for a simple outcome: identify the exact code behind cloud and AI spend, then help teams ship the fix.

That means deep attribution to microservices and call sites, automatic analysis across source, billing, and observability data, and remediation delivered as merge-ready pull requests with quantified savings. It also means coverage across major usage-billed environments and services, including AWS, Google Cloud, Datadog, Coralogix, Amazon S3, Google Cloud Storage, Amazon CloudWatch, OpenAI, and Anthropic Claude, with workflow integrations for GitHub, Cursor, and Claude Code.

The operational advantage is straightforward: teams can see which code owns the bill, then review a fix and merge it, without the usual escalation across engineering, finance, and platform operations.

Take control of the code behind the bill

Cloud cost optimization gets easier when attribution matches how software is built. Microservice and source-code visibility turn spend from a finance artifact into an engineering signal. Once that signal includes ownership, context, and a concrete fix, savings become part of normal delivery, sprint over sprint.

If you want precise, automated cost control, start with the code paths driving spend. Book a demo and we’ll show you what to change first.

FAQ

How does Frugal attribute AI API spend?

We analyze source, billing, and observability data together, then map spend to the file, function, and call path responsible for the usage. That makes AI API costs visible at the code-module level, not just the provider total.

Can Frugal automate code fixes for inefficient costs?

Yes. We generate ready-to-review pull requests that address identified cost issues and include the expected savings, so teams can move from detection to remediation without leaving their normal development workflow.

What cloud platforms does Frugal support?

We support major usage-billed providers and services including AWS and Google Cloud, along with related services such as S3, Google Cloud Storage, and CloudWatch. We also cover AI API providers, Datadog, Coralogix and developer workflow integrations so cost analysis and remediation happen in the same path engineers already use.