Skip to content

Feature request: support labels on CreateCachedContentConfig for billing attribution #2263

@dakl

Description

@dakl

Summary

CreateCachedContentConfig and UpdateCachedContentConfig do not expose a labels field, making it impossible to attach user-defined labels to cached content resources for GCP billing attribution.

Motivation

When using Vertex AI context caching, the cached content storage cost (billed as a separate SKU, e.g. Gemini 2.5 Flash GA Input Video Caching Storage) shows up in GCP billing with no user labels. This makes it impossible to slice the cost by service, team, or use-case in billing exports or dashboards.

The underlying Vertex AI REST API does support labels on CachedContent resources. The Python SDK simply doesn't expose this field.

What I expected

from google.genai.types import CreateCachedContentConfig

cache = client.caches.create(
    model="gemini-2.5-flash",
    config=CreateCachedContentConfig(
        contents=...,
        ttl="3600s",
        labels={"team": "my-team", "use_case": "video_analysis"},
    ),
)

What actually happens

CreateCachedContentConfig has no labels field:

CreateCachedContentConfig.model_fields.keys()
# dict_keys(['http_options', 'ttl', 'expire_time', 'display_name', 'contents', 'system_instruction', 'tools', 'tool_config', 'kms_key_name'])

And _CreateCachedContentConfig_to_vertex in caches.py does not serialize any labels key to the request body even if one were present.

Proposed fix

  1. Add labels: Optional[dict[str, str]] = None to CreateCachedContentConfig (and CachedContent for reads).
  2. Add serialization in _CreateCachedContentConfig_to_vertex (and the mldev equivalent) to map labelslabels in the request body.

GenerateContentConfig already has a labels field and the serialization pattern is established — this would be a straightforward addition.

Environment

  • google-genai version: 1.69.0
  • Backend: Vertex AI (vertexai=True)

Metadata

Metadata

Labels

priority: p2Moderately-important priority. 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