Skip to content

Cost Attribution Labels

jorsm edited this page May 31, 2026 · 4 revisions

Cost Attribution Labels

The extension supports optional cost attribution labels for Vertex AI API requests, with the following limitations:

Note: Labels are currently supported only for Gemini and Model-as-a-Service (MaaS) open-weight models. The Anthropic/Claude SDK does not support custom labels, so they will not be sent when using Claude models.

Table of Contents

Why labels matter

When enabled, the extension adds labels to Vertex AI requests so your organization can track usage and cost in Google Cloud more precisely.

This is especially useful for:

  • understanding which workspace generated the request
  • connecting costs to individual developers
  • attributing spend inside shared projects

Opt-in settings

Setting Default Effect
vertexAiChat.enableUserLabel false Adds vscode-vertex-ai-user label to requests.
vertexAiChat.userLabelValue "" Custom value for the user label (optional).
vertexAiChat.enableProjectLabel false Adds vscode-vertex-ai-project label to requests.
vertexAiChat.projectLabelValue "" Custom value for the project label (optional).

Both enable settings are disabled by default to respect privacy.

How values are created

User label

If vertexAiChat.enableUserLabel is enabled, the value is determined as:

  1. Custom Value: If vertexAiChat.userLabelValue is set, it is used directly.
  2. Automatic Detection: If no custom value is set, the extension attempts to read the current Google Cloud account email using gcloud config get-value account (or the client_email from your active Service Account).

It then sanitizes the value and sends it as:

vscode-vertex-ai-user=sanitized-value

Project label

If vertexAiChat.enableProjectLabel is enabled, the value is determined as:

  1. Custom Value: If vertexAiChat.projectLabelValue is set, it is used.
  2. Workspace Detection: If no custom value is set, the extension uses the current VS Code workspace name or the name of the active workspace folder.

It sends the label as:

vscode-vertex-ai-project=sanitized-value

Label sanitation rules

Labels are transformed to meet GCP requirements:

  • converted to lowercase
  • only letters, numbers, hyphens, and underscores are allowed
  • must start with a lowercase letter
  • maximum length is 63 characters

If a value does not start with a letter, the extension prefixes it with v_.

What this means for users

  • Enable one or both settings only if your organization wants richer billing attribution.
  • The extension stores label state in memory and attaches labels to every request sent to the Vertex AI provider.
  • Labels are only sent when the corresponding setting is enabled.