Query Costory cost, usage, business-metric, external-metric, and budget data, including formulas and period comparisons. Use to answer a request for totals, trends, breakdowns, or comparisons. A chart is sent as inline base64 or a temporary URL. Numeric-only queries do not create an image.
MINIMUM VALID CALL:
{ "queries": [{ "type": "cost", "name": "a", "metricId": "cost", "currency": "USD" }], "datePreset": "MTD", "aggBy": "Day" }
QUERY NAMING: set type and name (use short ids like a/b/c for formulas); put human labels in alias (e.g. "Cost by environment") — never in name. Example: { type: "cost", name: "a", alias: "Cost by environment", groupBy: "cos_environment", ... }. For costs: metricId (cost column, default "cost") and currency (default "USD"). Use costMetricId and currency from get when aligning with a budget. For custom business metrics: use [{ type: "metric", name: "a", metricId: "..." }] — get IDs from list_metrics. For infra usage metrics (e.g. CPU hours, network bytes): use [{ type: "usage", name: "a", metricId: "..." }] — call suggest_usage_metrics first to discover valid metricIds for your scope. BigQuery job metrics (orgs with the BigQuery jobs integration) are usage metrics too: metricIds start with query_ (e.g. query_compute_ms, query_bytes_billed, query_count), returned by suggest_usage_metrics with their label and unit; split/scope them with the cos_query_* dimensions (e.g. cos_query_user) like any billing dimension. For live external metrics (not saved as Costory metrics): use [{ type: "externalMetric", name: "a", provider: "...", integrationId: "...", metricName: "...", aggregator: "SUM", groupByFields: [], conditions: "..." }] — discover provider, integrationId, and metricName via list_metrics with includeExternal: true and a specific search term. Tsuga: metricName is the provider metric name; groupByFields are provider metric attributes; conditions is an optional provider filter string. Datadog: same shape as Tsuga — metricName is the Datadog metric name (e.g. system.cpu.user), groupByFields are tag keys (e.g. host, service), conditions is an optional Datadog tag filter (e.g. env:prod). When query is set it is the Datadog metrics query string (pass-through); metricName / aggregator / conditions / groupByFields are ignored; .rollup is required and the interval must be ≥ 24h (daily / weekly / monthly or seconds ≥ 86400). Costory will not fill an empty weekly series. CloudWatch: set provider: "cloudwatch"; metricName is Namespace/MetricName (e.g. AWS/EC2/CPUUtilization); groupByFields are CloudWatch dimension names (e.g. InstanceId); conditions is an optional dimension filter. BigQuery: set provider: "bigquery"; metricName is the fully-qualified table id (project.dataset.table); dateColumn, metricColumn, and gapFillingMethod are required — pick dateColumn/metricColumn from list_metrics `schema` (first DATE / first NUMERIC) and default gapFillingMethod to FORWARD_FILL; groupByFields are string column names (not CEL); conditions is an optional BigQuery WHERE predicate ANDed with the date range. S3: set provider: "s3"; identical field shape to bigquery — metricName is the fully-qualified table id returned by list_metrics (a Costory-managed external table over the customer's mirrored Parquet); same schema-derived columns; conditions is the same optional WHERE predicate. Snowflake: set provider: "snowflake"; metricName is DATABASE.SCHEMA.TABLE; dateColumn, metricColumn, and gapFillingMethod are required; groupByFields are string column names; conditions is an optional Snowflake WHERE predicate ANDed with the date range (e.g. PRIMARY_PROVIDER_AND_MODEL RLIKE 'azure-.*/doctor-ai.*'). BigQuery, S3, and Snowflake conditions are appended as AND (…); statement separators, comments, and unbalanced quotes/parentheses outside string literals are rejected. Use externalMetric for exploration when no saved metric matches; use a saved metric series when one exists. PERIOD: use `datePreset` for preset ranges (same as Explore, e.g. MTD, LAST_MONTH, TRAILING_30_DAYS). Forecast (same Forecast group as the explorer date picker): CURRENT_MONTH / CURRENT_QUARTER / CURRENT_YEAR — observed *TD plus Billy to EOM/EOQ/EOY. YTD/MTD/QTD stay observed-only. Mutually exclusive with from/to. For comparison: add compare: {} (or compare: { from, to }) — omit compare dates to auto-derive the preceding period (preset-aware, e.g. LAST_MONTH → previous calendar month). For formulas: add { type: "formula", name: "c", formula: "a / b" } referencing other queries by name. Optional unitOverride forces the series unit (e.g. "EUR", "slot-h/TiB", "%"); omit to infer from inputs. Currency codes follow the widget currency. For budgets: use [{ type: "budget", name: "a", budgetId: "..." }] — despite the field name, this must be the budget version ID (same value as budgetVersionId from get); search returns the parent budget id only, so call get with that id to obtain budgetVersionId before querying. Optional groupBy is that budget's virtual dimension bqName from get and splits one series per budget line; omit for the total. For per-line formulas (e.g. variance a - b) set the same groupBy on the sibling cost/usage/metric series. groupBy is the SPLIT dimension, filterCel is the SCOPE (CEL). Before guessing CEL field names, call search with type: ["dimensions"] — empty query lists all fields; a keyword narrows to matching values. Label dimensions use cos_ (e.g. cos_service_name). Unlabelled resources have null on label dimensions; use filterCel with == null / != null (not is_null or string "null"). Custom virtual dimensions: use immutable `bqName` from list/get VDIM tools as `groupBy` / `filterCel` (not display `name`). Poll `computeStatus` until `COMPLETED` after publish. Optional analyze.changePoint (true or { ignoreWeekends }) runs change-point detection once per query after a timeseries result (incompatible with compare). Optional limit (integer 1–1000): max groups/rows per series. Do NOT set limit unless you need a different cap — when omitted, results default to 100 groups. Set limit above 100 (e.g. 250 or 500) when the user asks for a long tail or full breakdown list. For requested charts, the image is sent as inline base64 or a temporary URL. Prefer returnGraphImage "base64". Use "link" for a temporary URL. Omit for numbers only. Table-only and split comparison tables still return numbers and append a second text content block with JSON { "image": "unsupported", "message": "..." }. For a saved dashboard widget, use get_dashboard_widget_image (applies dashboard filters; do not re-specify the query).
Effects: Read-only retrieval of Costory data. Chart mode renders a temporary PNG for the response and does not create or modify any saved Costory resource or send a message. Numbers-only results do not create an image. Scope: Authorized Costory workspace data only; the chart URL is returned to the caller, not posted or sent to a recipient.
EXAMPLES:
• "What are my total costs this month?" → { queries: [{ type: "cost", name: "a", metricId: "cost", currency: "USD" }], datePreset: "MTD", aggBy: "Day" }
• "2026 spend actual + forecast to year-end" → { queries: [{ type: "cost", name: "a", metricId: "cost", currency: "USD" }], datePreset: "CURRENT_YEAR", aggBy: "Month" }
• "Break down AWS costs by service over the last 90 days" → { queries: [{ type: "cost", name: "a", alias: "AWS by service", metricId: "cost", currency: "USD", groupBy: "cos_service_name", filterCel: "cos_provider in [\"AWS\"]" }], datePreset: "TRAILING_90_DAYS", aggBy: "Week" }
• "Show me a chart of last month’s AWS cost by service" → same payload as the breakdown example, with datePreset: "LAST_MONTH" and returnGraphImage: "base64"
• "Show costs for resources without an environment label" → { queries: [{ type: "cost", name: "a", metricId: "cost", currency: "USD", filterCel: "cos_environment == null" }], datePreset: "TRAILING_30_DAYS", aggBy: "Day" }
• "How did our costs change vs last month?" → { queries: [{ type: "cost", name: "a", metricId: "cost", currency: "USD" }], datePreset: "LAST_MONTH", compare: {} }
• "Show CPU hours alongside compute costs" (call suggest_usage_metrics first to get valid metricIds) → { queries: [{ type: "cost", name: "a", metricId: "cost", currency: "USD" }, { type: "usage", name: "b", metricId: "k8s_cpu_hours" }], datePreset: "TRAILING_30_DAYS", aggBy: "Week" }
• "What is our cost per request?" → { queries: [{ type: "cost", name: "a", metricId: "cost", currency: "USD" }, { type: "metric", name: "b", metricId: "<metric-id>" }, { type: "formula", name: "c", formula: "a / b" }], datePreset: "TRAILING_30_DAYS" }
• "Usage converted to euros (force formula unit)" → { queries: [{ type: "usage", name: "b", metricId: "query_compute_ms" }, { type: "formula", name: "c", formula: "b / 3600000 * 0.055", unitOverride: "EUR" }], datePreset: "LAST_MONTH" }
• "Cost per request volume" (after list_metrics with includeExternal: true and search: "request") → { queries: [{ type: "cost", name: "a", metricId: "cost", currency: "USD" }, { type: "externalMetric", name: "b", provider: "tsuga", integrationId: "<integration-id>", metricName: "<metric-name>", aggregator: "SUM" }, { type: "formula", name: "c", formula: "a / b" }], datePreset: "TRAILING_30_DAYS", aggBy: "Week" }
• "Cost per BigQuery revenue table" (after list_metrics with includeExternal: true and search: "revenue") → { queries: [{ type: "cost", name: "a", metricId: "cost", currency: "USD" }, { type: "externalMetric", name: "b", provider: "bigquery", integrationId: "<integration-id>", metricName: "my-project.analytics.revenue", dateColumn: "event_date", metricColumn: "amount", gapFillingMethod: "ZERO", aggregator: "SUM" }, { type: "formula", name: "c", formula: "a / b" }], datePreset: "TRAILING_30_DAYS", aggBy: "Week" }
• "Cost per CPU usage from Datadog" (after list_metrics with includeExternal: true and search: "cpu") → { queries: [{ type: "cost", name: "a", metricId: "cost", currency: "USD" }, { type: "externalMetric", name: "b", provider: "datadog", integrationId: "<integration-id>", metricName: "system.cpu.user", aggregator: "AVG", groupByFields: ["host"] }, { type: "formula", name: "c", formula: "a / b" }], datePreset: "TRAILING_30_DAYS", aggBy: "Week" }
• "Cost per EC2 CPU from CloudWatch" (after list_metrics with includeExternal: true and search: "CPUUtilization") → { queries: [{ type: "cost", name: "a", metricId: "cost", currency: "USD" }, { type: "externalMetric", name: "b", provider: "cloudwatch", integrationId: "<integration-id>", metricName: "AWS/EC2/CPUUtilization", aggregator: "AVG", groupByFields: ["InstanceId"] }, { type: "formula", name: "c", formula: "a / b" }], datePreset: "TRAILING_30_DAYS", aggBy: "Week" }
• "Budget per calendar month" → { queries: [{ type: "budget", name: "a", budgetId: "<budgetVersionId>" }], datePreset: "LAST_3_MONTHS", aggBy: "Month" } (budgetVersionId from get, not the parent id from search)
• "Budget month-to-date by day (cumulative within each month — which day did we reach the budget?)" → { queries: [{ type: "budget", name: "a", budgetId: "<budgetVersionId>", rollingAggregation: { aggregator: "SUM", window: { preset: "MONTH" } } }], datePreset: "MTD", aggBy: "Day" }
• "Formula: month-to-date cost vs month-to-date budget (both rolling SUM per month, e.g. utilization a/b)" → { queries: [{ type: "cost", name: "a", metricId: "cost", currency: "USD", rollingAggregation: { aggregator: "SUM", window: { preset: "MONTH" } } }, { type: "budget", name: "b", budgetId: "<budgetVersionId>", rollingAggregation: { aggregator: "SUM", window: { preset: "MONTH" } } }, { type: "formula", name: "c", formula: "a / b" }], datePreset: "MTD", aggBy: "Day" }
• "Budget vs actual per line" (bqName from get virtualDimension.bqName) → { queries: [{ type: "cost", name: "a", alias: "Actual", metricId: "cost", currency: "USD", groupBy: "<vd bqName>" }, { type: "budget", name: "b", alias: "Budget", budgetId: "<budgetVersionId>", groupBy: "<same bqName>" }, { type: "formula", name: "c", alias: "Variance", formula: "a - b" }], datePreset: "YTD", aggBy: "Month" }
• Custom one-off range → { queries: [{ type: "cost", name: "a", metricId: "cost", currency: "USD" }], from: "2026-01-15", to: "2026-02-12", aggBy: "Day" }