Skip to content

Add labels support for Vertex AI Context Caching cost tracking #1787

@piotrgrygoruk

Description

@piotrgrygoruk

Description
The CreateCachedContentConfig does not support labels for cost tracking and billing attribution. This makes it difficult to allocate context caching costs across teams, environments, and projects.
Current Behavior
Adding labels to cache creation fails with a validation error:

config = CreateCachedContentConfig(
    system_instruction="...",
    contents=["..."],
    ttl="3600s",
    display_name="my-cache",
    labels={  # This causes an error
        "environment": "production",
        "team": "ai-team"
    }
)
client = genai.Client(vertexai=True, project=project, location=selected_location)
cache = await client.aio.caches.create(model="gemini-2.5-flash-lite", config=config)

Error:

1 validation error for CreateCachedContentConfig
labels
  Extra inputs are not permitted [type=extra_forbidden, input_value={'environment': 'production'}, input_type=dict]`

Expected Behavior

Labels should be supported for context caching, similar to other Vertex AI resources:
config = CreateCachedContentConfig(
    system_instruction="...",
    contents=["..."],
    ttl="3600s",
    display_name="my-cache",
    labels={  # Should work
        "environment": "production",
        "team": "ai-team",
        "cost-center": "engineering"
    }
)

Use Case
We need to track cache creation costs per team/environment for accurate billing and chargeback. Context caching incurs significant costs that require proper attribution for multi-tenant systems.

Environment

SDK Version: 1.52.0
Python Version: 3.12

Metadata

Metadata

Assignees

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions