Skip to main content
Glama

query_unit_costs

Read-onlyIdempotent

Compute one of this account's saved unit-economics metrics (see list_unit_metrics) over a date range — the cost of a slice of spend divided by the business units it produced. Each row carries cost (the numerator, in the USD base like every other figure this server returns), quantity (the denominator, a raw count with no currency), and unit_cost.

CRITICAL: unit_cost is null whenever it could not be computed, and null does NOT mean zero. It means one half of the fraction is missing for that period — either no usage was ingested (a telemetry gap) or no cost data has landed yet. Do not describe a null unit cost as a cost of zero, and do not average nulls in as zeroes; the coverage block reports how many rows are affected and why. Always read unit_cost together with denominator_label (e.g. "per 1k requests"), which names what it is quoted against — a per-1k figure reported as a per-request figure is wrong by three orders of magnitude.

The series stops at coverage.complete_through rather than at the requested end_date whenever cost data for the newest periods has not arrived yet (it lands hours-to-a-day after the period it covers, while usage telemetry is pushed live). A short series is therefore normal and is NOT evidence that spend or usage stopped — say what it is complete through instead. coverage.lagging_sources, when non-empty, is the opposite case: a cost source that is behind or has stopped reporting, so recent periods are missing its spend and their unit costs read lower than the truth.

If numerator_status.available is false, the cost source this metric measured has been removed from the account and rows is empty. That is a broken definition, not a period of zero spend — never report it as costs having fallen.

Amounts are billed cost unless cost_metric is "amortized", which spreads prepaid commitments across the term they cover (see query_costs). Budgets and the target_unit_cost alert stay billed either way. A tag-scoped metric inherits that tag_key's allocation policy, so its numerator may include a redistributed share of shared spend (see list_cost_tags' redistribute_bucket) and will not match a raw dimension total.

A metric whose denominator_mode is "per_customer" returns one row per (period, customer) and a customers block splitting them into matched, cost_without_usage (spend attributed to a customer who is not sending telemetry) and usage_without_cost (telemetry from a customer whose spend is not being allocated). Those two lists are the honest caveat on any per-customer figure and are worth mentioning when either is non-empty. When the metric has a denominator_dimension_key (e.g. "feature") the "customer" in those rows is that dimension's value, matched against the tag values of the numerator's tag key.

A metric with revenue_source_ids also returns revenue (billed revenue in the USD base, from connected revenue streams only) and gross_margin_pct on every row. Both are null when the period has no revenue rows; that is missing data, not a margin of zero.

Input Schema

NameRequiredDescriptionDefault
end_dateNoISO-8601 end of the date range (exclusive)
group_byNoTime bucket size (default: day)
start_dateNoISO-8601 start of the date range (inclusive)
cost_metricNoWhich cost figure feeds the numerator (default: "billed"). Same meaning as on query_costs.
unit_metric_idYesid of a metric returned by list_unit_metrics

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • addedInput schema / properties / cost_metric
      Added value: +{
      +  "description": "Which cost figure feeds the numerator (default: \"billed\"). Same meaning as on query_costs.",
      +  "enum": [
      +    "billed",
      +    "amortized"
      +  ],
      +  "type": "string"
      +}
  2. First observed

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Far beyond the readOnly/idempotent annotations, the description discloses null-vs-zero semantics, truncation at coverage.complete_through, lagging_sources, numerator_status.available meaning a removed source with empty rows, per-customer split blocks, and null revenue/margin semantics. These are exactly the traps an agent would otherwise misreport, and none of it is available in structured fields.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The purpose and the critical null/coverage warnings are front-loaded, and each subsequent paragraph maps to a distinct output condition. It is long, but with no output schema the density is largely earned; a few sentences (e.g. the restatement of 'null does NOT mean zero') could be tightened.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With five parameters, no output schema, and non-obvious failure modes (telemetry gaps, lagging cost sources, removed sources, per-customer mismatches, revenue joins), the description covers every case an agent must handle to report results honestly. Nothing material is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3, but the description genuinely adds meaning for cost_metric by explaining that amortized spreads prepaid commitments across the term while budgets and target_unit_cost alerts stay billed, and warns that a tag-scoped metric's numerator may include redistributed shared spend. It adds nothing for group_by or the dates, keeping it short of a 5.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening sentence gives a specific verb ('Compute'), a specific resource ('saved unit-economics metrics'), and the actual arithmetic definition (cost of a slice of spend divided by business units produced). It names list_unit_metrics as the source of the id, so an agent can distinguish this from query_costs or query_usage without opening a schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Usage context is clear and alternatives are referenced explicitly: list_unit_metrics for obtaining unit_metric_id, query_costs for amortized detail, list_cost_tags for redistribution policy. It does not spell out a negative case (e.g. 'use query_costs instead when you want raw spend'), but the routing is unambiguous for the intended task.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources