-
Notifications
You must be signed in to change notification settings - Fork 2
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.
- Source of Truth: Unlike the local dashboard, which uses estimated pricing, BigQuery exports contain the actual invoiced costs from Google.
- Aggregated Reporting: Query usage across all developers in your organization who are using the extension with the same Billing Account.
- Custom Dashboards: Connect BigQuery to Looker Studio, Grafana, or other BI tools to visualize spend trends by project or user.
- Historical Depth: Local logs are stored per machine; BigQuery provides a permanent, centralized history of all API calls.
To use this feature, you must first enable the billing export in the Google Cloud Console:
- Go to the Billing Export page.
- Select BigQuery Export.
- Enable Standard usage cost (and optionally Detailed usage cost).
- Select or create a BigQuery dataset to store the logs.
For detailed steps, see the official Google Cloud documentation.
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).
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 DESCTo 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 DESCFor 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.