Skip to content

Azure Cost

Azure cost and usage — actual and amortised spend by scope, date and dimension

Connector software
Free and open source
Service credentials
Required
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/azure-cost/index.md to help me query Azure Cost with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Break down daily Azure spending by resource group

Uses a fixed example date range. Set the dates to the billing period you want to analyze.

Uses your connected account. Set up the connector and credentials to run it with your data.

SELECT date, "ResourceGroup", cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', granularity := 'Daily', group_by := 'Dimension:ResourceGroup')
WHERE _row_kind IS NULL AND date >= '2026-06-01'
ORDER BY date, "ResourceGroup"

Quick start

Choose where to run Azure Cost, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'azure' AS azure (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-azure-cost'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

azure_graph credentials

Microsoft Entra app-only (client-credentials) credentials for Azure ARM / Microsoft Graph

Get these credentials →
secret.sql
CREATE SECRET azure_graph (
    TYPE azure_graph,
    tenant_id     '<tenant_id>',
    client_id     '<client_id>',
    client_secret '<AZURE_GRAPH_CLIENT_SECRET>'  -- secret
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT date, "ResourceGroup", cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', granularity := 'Daily', group_by := 'Dimension:ResourceGroup')
WHERE _row_kind IS NULL AND date >= '2026-06-01'
ORDER BY date, "ResourceGroup"
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'azure' AS azure (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Azure Cost Management (actual/amortized cost) as typed DuckDB rows over a restatement-aware date watermark — apply by OVERWRITE keyed on (scope,date,dims) — vgi-azure-cost

Catalog

Everything azure exposes once attached — read straight from the worker's released build.

azure 1 schema
main 1 view · 1 function

Azure Cost Management actual/amortized cost as typed rows over a restatement-aware date watermark.

Schema examples (5)
Examples (5)

Daily actual cost by resource group for June (data rows only; the date filter drops the 7-day restatement lookback the scan also re-pulls)

SELECT date, "ResourceGroup", cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', granularity := 'Daily', group_by := 'Dimension:ResourceGroup')
WHERE _row_kind IS NULL AND date >= '2026-06-01'
ORDER BY date, "ResourceGroup";

Monthly amortized cost totals for January–June (the date filter drops the open prior month the amortized lookback also re-pulls)

SELECT date, cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-01-01', '2026-06-30', granularity := 'Monthly', cost_type := 'AmortizedCost')
WHERE _row_kind IS NULL AND date >= '2026-01-01'
ORDER BY date;

Read the restatement watermark to persist for the next incremental scan

SELECT _watermark_next, _restated_from, _key_columns
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30')
WHERE _row_kind = 'marker';

Daily cost by service and cost-center tag for June (multi-axis grouping; restatement-lookback days filtered out)

SELECT date, "ServiceName", "costcenter", cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', granularity := 'Daily', group_by := 'Dimension:ServiceName,TagKey:costcenter')
WHERE _row_kind IS NULL AND date >= '2026-06-01'
ORDER BY date, "ServiceName", "costcenter";
1 more example

Actual vs amortized June cost per service, from two cost_query scans joined on ServiceName; amortization_shift (amortized − actual) shows where reservation/savings-plan purchases are spread out (largest absolute shift first; the date filter drops the restatement-lookback days each scan re-pulls)

WITH actual AS (SELECT "ServiceName", currency, sum(cost) AS actual_cost FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', group_by := 'Dimension:ServiceName') WHERE _row_kind IS NULL AND date BETWEEN '2026-06-01' AND '2026-06-30' GROUP BY ALL), amortized AS (SELECT "ServiceName", currency, sum(cost) AS amortized_cost FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', cost_type := 'AmortizedCost', group_by := 'Dimension:ServiceName') WHERE _row_kind IS NULL AND date BETWEEN '2026-06-01' AND '2026-06-30' GROUP BY ALL) SELECT "ServiceName", currency, round(coalesce(actual_cost, 0), 2) AS actual_cost, round(coalesce(amortized_cost, 0), 2) AS amortized_cost, round(coalesce(amortized_cost, 0) - coalesce(actual_cost, 0), 2) AS amortization_shift
FROM actual
FULL JOIN amortized USING ("ServiceName", currency)
ORDER BY abs(amortization_shift) DESC, "ServiceName";
Views
dimensions 1 example3 cols

Credential-free manifest of the group_by tokens cost_query accepts (a browsable discovery entry point).

Columns
token VARCHAR
The group_by token to pass to cost_query (e.g. Dimension:ResourceGroup or TagKey:costcenter).
kind VARCHAR
Whether the token groups by a built-in cost Dimension or by a resource TagKey.
description VARCHAR
A one-line summary of what grouping by this token produces.
Example

List the Dimension group_by tokens cost_query accepts

SELECT token, description
FROM azure.main.dimensions
WHERE kind = 'Dimension'
ORDER BY token;
Link
Table functions
cost_query (scope VARCHAR, from VARCHAR, to VARCHAR, cost_type := VARCHAR, granularity := VARCHAR, group_by := VARCHAR, restatement_lookback_days := BIGINT) 5 examples

Azure Cost Management actual/amortized cost over a trailing RESTATEMENT window, as typed DuckDB rows (date, grouping dims, Float64 cost, currency). Costs are restated retroactively, so each scan re-pulls [from−lookback, to] and the caller MUST apply by OVERWRITE keyed on (scope, date, grouping dims) — never a blind INSERT (that double-counts, SPEC §2 #2). The new high-water to rides back on a marker row as _watermark_next (persist only after the rows are durable); _restated_from is the low edge to overwrite; _key_columns guards the group_by key shape — a change is a full reload, not an incremental resume (§2 #3). Continuation pages re-POST the ORIGINAL query body (the $skiptoken is in the nextLink URL). AUDIENCE: arm.

Positional arguments
scope VARCHAR
The ARM scope to query, e.g. `subscriptions/{id}`, `providers/Microsoft.Billing/billingAccounts/{id}`, `managementGroups/{id}`, or `subscriptions/{id}/resourceGroups/{name}`. Required (positional). The service principal in the azure_graph secret must have Cost Management reader access on this scope.
from VARCHAR
Low edge of the requested window (ISO date or instant, e.g. `2026-06-01`). This IS the caller-held watermark: on an incremental scan pass back the prior scan's `_watermark_next`. The function re-pulls a trailing restatement window starting `from − restatement_lookback_days` (open-period-clamped for AmortizedCost). Required (positional).
to VARCHAR
High edge of the requested window (ISO date or instant), typically today (UTC). Rides back on the marker row as `_watermark_next`, the new high-water watermark to persist. Required (positional).
Named arguments
cost_type := VARCHAR
`ActualCost` (billed cost as incurred) or `AmortizedCost` (reservation/savings-plan purchases spread across the benefit period). AmortizedCost auto-widens the trailing lookback toward the open, still-restating billing period (capped). Named (name:=value). Defaults to `ActualCost`. · default "ActualCost"
granularity := VARCHAR
Time bucketing of the returned rows: `Daily`, `Monthly`, or `None` (a single total over the window). Named (name:=value). Defaults to `Daily`. · default "Daily"
group_by := VARCHAR
Comma-separated grouping list, each token `Dimension:Name` or `TagKey:Name` (e.g. `Dimension:ResourceGroup,TagKey:costcenter`; a bare token defaults to a Dimension). Each becomes an extra result column and part of the overwrite key. Empty (the default) returns an ungrouped total. CHANGING this between scans changes the overwrite-key shape → full reload, not incremental. Named (name:=value). · default ""
restatement_lookback_days := BIGINT
Size in days of the trailing ActualCost restatement window re-pulled on each scan (effFrom = from − this). Guards against retroactive restatement of recently-reported costs. Named (name:=value). Defaults to 7. (AmortizedCost instead uses an open-period clamp.) · default 7
Returns columns
date VARCHAR
ISO date of the cost bucket (per `granularity`). NULL on the marker row.
cost DOUBLE
Cost for the bucket (Float64). NULL on the marker row.
currency VARCHAR
Billing currency code (e.g. USD). NULL on the marker row.
_row_kind VARCHAR
NULL for data rows; `marker` for the single trailing cursor row.
_watermark_next VARCHAR
On the marker row, the new high-water `to` to persist and pass back as the next `from`; NULL on data rows.
_restated_from VARCHAR
On the marker row, the low edge of the overwritten (restated) window; NULL on data rows.
_key_columns VARCHAR
On the marker row, the ordered grouping-key column set (comma-joined) guarding the group_by key shape; NULL on data rows.
date VARCHAR
ISO date of the cost bucket (per `granularity`). NULL on the marker row.
ResourceGroup VARCHAR
The grouping-dimension value (one such column per `group_by` token); part of the overwrite key. NULL on the marker row.
cost DOUBLE
Cost for the bucket (Float64). NULL on the marker row.
currency VARCHAR
Billing currency code (e.g. USD). NULL on the marker row.
_row_kind VARCHAR
NULL for data rows; `marker` for the single trailing cursor row.
_watermark_next VARCHAR
On the marker row, the new high-water `to` to persist and pass back as the next `from`; NULL on data rows.
_restated_from VARCHAR
On the marker row, the low edge of the overwritten (restated) window; NULL on data rows.
_key_columns VARCHAR
On the marker row, the ordered grouping-key column set (comma-joined) guarding the group_by key shape; NULL on data rows.
Returns columns · depends on the arguments
Default (empty `group_by`) — no dimension columns
date VARCHAR
ISO date of the cost bucket (per `granularity`). NULL on the marker row.
cost DOUBLE
Cost for the bucket (Float64). NULL on the marker row.
currency VARCHAR
Billing currency code (e.g. USD). NULL on the marker row.
_row_kind VARCHAR
NULL for data rows; `marker` for the single trailing cursor row.
_watermark_next VARCHAR
On the marker row, the new high-water `to` to persist and pass back as the next `from`; NULL on data rows.
_restated_from VARCHAR
On the marker row, the low edge of the overwritten (restated) window; NULL on data rows.
_key_columns VARCHAR
On the marker row, the ordered grouping-key column set (comma-joined) guarding the group_by key shape; NULL on data rows.
Grouped (e.g. `group_by := 'Dimension:ResourceGroup'`) — one extra dimension column
date VARCHAR
ISO date of the cost bucket (per `granularity`). NULL on the marker row.
ResourceGroup VARCHAR
The grouping-dimension value (one such column per `group_by` token); part of the overwrite key. NULL on the marker row.
cost DOUBLE
Cost for the bucket (Float64). NULL on the marker row.
currency VARCHAR
Billing currency code (e.g. USD). NULL on the marker row.
_row_kind VARCHAR
NULL for data rows; `marker` for the single trailing cursor row.
_watermark_next VARCHAR
On the marker row, the new high-water `to` to persist and pass back as the next `from`; NULL on data rows.
_restated_from VARCHAR
On the marker row, the low edge of the overwritten (restated) window; NULL on data rows.
_key_columns VARCHAR
On the marker row, the ordered grouping-key column set (comma-joined) guarding the group_by key shape; NULL on data rows.
Examples (5)

Daily actual cost by resource group for June (data rows only; the date filter drops the 7-day restatement lookback the scan also re-pulls)

SELECT date, "ResourceGroup", cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', granularity := 'Daily', group_by := 'Dimension:ResourceGroup')
WHERE _row_kind IS NULL AND date >= '2026-06-01'
ORDER BY date, "ResourceGroup";

Monthly amortized cost totals for January–June (the date filter drops the open prior month the amortized lookback also re-pulls)

SELECT date, cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-01-01', '2026-06-30', granularity := 'Monthly', cost_type := 'AmortizedCost')
WHERE _row_kind IS NULL AND date >= '2026-01-01'
ORDER BY date;

Read the restatement watermark to persist for the next incremental scan

SELECT _watermark_next, _restated_from, _key_columns
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30')
WHERE _row_kind = 'marker';
2 more examples

Daily cost by service and cost-center tag for June (multi-axis grouping; restatement-lookback days filtered out)

SELECT date, "ServiceName", "costcenter", cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', granularity := 'Daily', group_by := 'Dimension:ServiceName,TagKey:costcenter')
WHERE _row_kind IS NULL AND date >= '2026-06-01'
ORDER BY date, "ServiceName", "costcenter";

Actual vs amortized June cost per service, from two cost_query scans joined on ServiceName; amortization_shift (amortized − actual) shows where reservation/savings-plan purchases are spread out (largest absolute shift first; the date filter drops the restatement-lookback days each scan re-pulls)

WITH actual AS (SELECT "ServiceName", currency, sum(cost) AS actual_cost FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', group_by := 'Dimension:ServiceName') WHERE _row_kind IS NULL AND date BETWEEN '2026-06-01' AND '2026-06-30' GROUP BY ALL), amortized AS (SELECT "ServiceName", currency, sum(cost) AS amortized_cost FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', cost_type := 'AmortizedCost', group_by := 'Dimension:ServiceName') WHERE _row_kind IS NULL AND date BETWEEN '2026-06-01' AND '2026-06-30' GROUP BY ALL) SELECT "ServiceName", currency, round(coalesce(actual_cost, 0), 2) AS actual_cost, round(coalesce(amortized_cost, 0), 2) AS amortized_cost, round(coalesce(amortized_cost, 0) - coalesce(actual_cost, 0), 2) AS amortization_shift
FROM actual
FULL JOIN amortized USING ("ServiceName", currency)
ORDER BY abs(amortization_shift) DESC, "ServiceName";
Link

Credentials

The secret type azure declares, as reported by the worker itself.

azure_graph

How to get these credentials

Microsoft Entra app-only (client-credentials) credentials for Azure ARM / Microsoft Graph

secret.sql
CREATE SECRET azure_graph (
    TYPE azure_graph,
    tenant_id     '<tenant_id>',
    client_id     '<client_id>',
    client_secret '<AZURE_GRAPH_CLIENT_SECRET>'  -- secret
);
Key Type Required Description
tenant_id VARCHAR — Directory (tenant) ID from the app registration's Overview page in Microsoft Entra ID
client_id VARCHAR — Application (client) ID from the app registration's Overview page
client_secret secret VARCHAR — Client secret value created under the app registration's Certificates & secrets page

The worker doesn't mark which keys are required.

Needed by cost_query

Create the secret in the same session, after attaching azure — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

cost_bind_probe — Bind cost_query and expose its result columns (credential-free; drop LIMIT 0 and attach an azure_graph secret to pull real daily cost)

SELECT date, cost, currency
FROM azure.main.cost_query('subscriptions/00000000-0000-0000-0000-000000000000', '2026-01-01', '2026-01-31')
LIMIT 0;

Uses cost_query

cost_grouped_bind_probe — Bind cost_query grouped by resource group and expose its result columns, including the ResourceGroup dimension column (credential-free)

SELECT date, "ResourceGroup", cost, currency
FROM azure.main.cost_query('subscriptions/00000000-0000-0000-0000-000000000000', '2026-01-01', '2026-01-31', group_by := 'Dimension:ResourceGroup')
LIMIT 0;

Uses cost_query

list_group_by_dimensions — Browse the credential-free dimensions manifest to discover the group_by tokens cost_query accepts (runs with no secret)

SELECT token, kind FROM azure.main.dimensions ORDER BY kind, token;

Uses dimensions

Monthly amortized cost totals for January–June (the date filter drops the open prior month the amortized lookback also re-pulls)

SELECT date, cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-01-01', '2026-06-30', granularity := 'Monthly', cost_type := 'AmortizedCost')
WHERE _row_kind IS NULL AND date >= '2026-01-01'
ORDER BY date

Uses cost_query

Read the restatement watermark to persist for the next incremental scan

SELECT _watermark_next, _restated_from, _key_columns
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30')
WHERE _row_kind = 'marker'

Uses cost_query

Daily cost by service and cost-center tag for June (multi-axis grouping; restatement-lookback days filtered out)

SELECT date, "ServiceName", "costcenter", cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', granularity := 'Daily', group_by := 'Dimension:ServiceName,TagKey:costcenter')
WHERE _row_kind IS NULL AND date >= '2026-06-01'
ORDER BY date, "ServiceName", "costcenter"

Uses cost_query

2 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Show the daily Azure cost for subscription 00000000-0000-0000-0000-000000000000 during January 2026, broken down by resource group.
  • Which values can I pass to cost_query's group_by argument to break the cost down?
  • After pulling cost, how do I get the value to pass as `from` on the next incremental scan?
  • How should I apply each cost_query scan into my warehouse table so totals do not double-count?

Azure Cost is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.