Skip to content

Advanced Billing Reports

jorsm edited this page May 31, 2026 · 3 revisions

Advanced Billing Reports

While the local dashboard provides real-time estimates, large teams often need a single source of truth for cross-user reporting and historical analysis. By using Google Cloud Billing Export to BigQuery, you can query the exact costs attributed to your VS Code sessions using SQL.

Note: Cost attribution labels are currently supported only for Gemini and Model-as-a-Service (MaaS) open-weight models. Claude models do not support custom labels due to limitations in the Anthropic SDK.

Table of Contents

Why use BigQuery for billing?

  1. Source of Truth: Unlike the local dashboard, which uses estimated pricing, BigQuery exports contain the actual invoiced costs from Google.
  2. Aggregated Reporting: Query usage across all developers in your organization who are using the extension with the same Billing Account.
  3. Custom Dashboards: Connect BigQuery to Looker Studio, Grafana, or other BI tools to visualize spend trends by project or user.
  4. Historical Depth: Local logs are stored per machine; BigQuery provides a permanent, centralized history of all API calls.

Setup: Exporting Billing to BigQuery

To use this feature, you must first enable the billing export in the Google Cloud Console:

  1. Go to the Billing Export page.
  2. Select BigQuery Export.
  3. Enable Standard usage cost (and optionally Detailed usage cost).
  4. Select or create a BigQuery dataset to store the logs.

For detailed steps, see the official Google Cloud documentation.

Querying the Data

Once your billing data is flowing into BigQuery, you can run SQL queries to filter by the custom labels sent by this extension (vscode-vertex-ai-user and vscode-vertex-ai-project).

Basic Usage Query

This query extracts the model, the operation type (input vs output), and the custom labels to show a breakdown of costs per user and project.

SELECT
  usage_start_time,
  -- Calculate net cost after credits/discounts
  (cost + IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) AS c), 0)) AS net_cost,
  -- Extract model name and operation from SKU description
  REGEXP_EXTRACT(sku.description, r'^(.*?)\s+(?:Text)') AS model,
  REGEXP_EXTRACT(sku.description, r'(Text.*)$') AS operation,
  -- Retrieve the custom labels sent by the VS Code extension
  (SELECT value FROM UNNEST(labels) WHERE key = 'vscode-vertex-ai-user' LIMIT 1) AS label_user,
  (SELECT value FROM UNNEST(labels) WHERE key = 'vscode-vertex-ai-project' LIMIT 1) AS label_project

FROM `your-billing-project.your_dataset.gcp_billing_export_v1_XXXXXX`  

WHERE
  _PARTITIONTIME >= TIMESTAMP("2026-01-01")
  AND project.id = "your-gcp-project-id"
  AND service.description = "Vertex AI"

ORDER BY usage_start_time DESC

Aggregated Spend by User

To see who is spending the most across all projects:

SELECT
  (SELECT value FROM UNNEST(labels) WHERE key = 'vscode-vertex-ai-user' LIMIT 1) AS user_email,
  SUM(cost) as total_raw_cost,
  SUM(cost + IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) AS c), 0)) AS total_net_cost
FROM `your-billing-project.your_dataset.gcp_billing_export_v1_XXXXXX`
WHERE service.description = "Vertex AI"
GROUP BY 1
ORDER BY total_net_cost DESC

Requirements for Reporting

For the queries above to return useful data, you must enable the attribution labels in your VS Code settings. See the Cost Attribution Labels page for instructions on how to opt-in.

Clone this wiki locally