You can add custom metadata to A label is a key-value pair that you can assign to The labels applied to an API call must meet the following
requirements: These limits apply to the key and value for each label, and to the
individual API call that have labels. There
is no limit on how many labels you can apply across all API calls
within a project. Here are some common use cases for labels: Team or cost center labels: Add labels based on team or
cost center to distinguish API calls owned by different
teams (for example, Component labels: For example, Environment or stage labels: For example,
Ownership labels: Used to identify the teams that are
responsible for operations, for example: We don't recommend creating large numbers of unique labels, such as for
timestamps or individual values for every API call. The problem with this
approach is that when the values change frequently or with keys that clutter the
catalog, this makes it difficult to effectively filter and report on API calls. To add a label to a
Before using any of the request data,
make the following replacements:
Click to expand a partial list of available regions To send your request, choose one of these options:
Save the request body in a file named
Then execute the following command to send your REST request:
Save the request body in a file named
Then execute the following command to send your REST request:
You should receive a JSON response similar to the following.
Before trying this sample, follow the Python setup instructions in the
Vertex AI quickstart using
client libraries.
For more information, see the
Vertex AI Python API
reference documentation.
To authenticate to Vertex AI, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Google Cloud products report usage and cost data to Cloud Billing processes
at varying intervals. As a result, you might see a delay between your use of
Google Cloud services, and the usage and costs being available to view in
Cloud Billing. Typically, your costs are available within a day, but can
sometimes take more than 24 hours.generateContent
and streamGenerateContent
API
calls by using labels. This page explains what labels are, and shows you how to
use them to break down your billed charges.What are labels?
generateContent
and
streamGenerateContent
API calls. They help you organize these calls and manage
your costs at scale, with the granularity you need. You can attach a label to
each call, then filter the calls based on their labels. Information about labels
is forwarded to the billing system that lets you break down your billed charges
by label. With built-in
billing reports,
you can filter and group costs by labels. You can also use labels to
query
billing data exports.
For information on how to use labels after creation, see an example from the
labels overview.Requirements for labels
Common uses of labels
team:research
and team:analytics
). You can use this
type of label for cost accounting or budgeting.component:redis
,
component:frontend
, component:ingest
, and component:dashboard
.environment:production
and environment:test
.team:shopping-cart
.Add a label to an API call
generateContent
or streamGenerateContent
API call, do
the following:REST
GENERATE_RESPONSE_METHOD
: The type of response that you want the model to generate.
Choose a method that generates how you want the model's response to be returned:
streamGenerateContent
: The response is streamed as it's being generated to reduce the perception of latency to a human audience.generateContent
: The response is returned after it's fully generated.LOCATION
: The region to process the request. Available
options include the following:
us-central1
us-west4
northamerica-northeast1
us-east4
us-west1
asia-northeast3
asia-southeast1
asia-northeast1
PROJECT_ID
: Your project ID.MODEL_ID
: The model ID of the model
that you want to use.ROLE
:
The role in a conversation associated with the content. Specifying a role is required even in
singleturn use cases.
Acceptable values include the following:
USER
: Specifies content that's sent by you.MODEL
: Specifies the model's response.PROMPT_TEXT
LABEL_KEY
: The label metadata that you want to
associate with this API call.LABEL_VALUE
: The value of the label.curl
request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
cat > request.json << 'EOF'
{
"contents": {
"role": "ROLE",
"parts": { "text": "PROMPT_TEXT" }
},
"labels": {
"LABEL_KEY": "LABEL_VALUE"
},
}
EOF
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATE_RESPONSE_METHOD"PowerShell
request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@'
{
"contents": {
"role": "ROLE",
"parts": { "text": "PROMPT_TEXT" }
},
"labels": {
"LABEL_KEY": "LABEL_VALUE"
},
}
'@ | Out-File -FilePath request.json -Encoding utf8
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:GENERATE_RESPONSE_METHOD" | Select-Object -Expand ContentPython
Custom metadata labels
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-21 UTC.