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
- Add
labels: Optional[dict[str, str]] = None to CreateCachedContentConfig (and CachedContent for reads).
- Add serialization in
_CreateCachedContentConfig_to_vertex (and the mldev equivalent) to map labels → labels 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)
Summary
CreateCachedContentConfigandUpdateCachedContentConfigdo not expose alabelsfield, 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
labelsonCachedContentresources. The Python SDK simply doesn't expose this field.What I expected
What actually happens
CreateCachedContentConfighas nolabelsfield:And
_CreateCachedContentConfig_to_vertexincaches.pydoes not serialize anylabelskey to the request body even if one were present.Proposed fix
labels: Optional[dict[str, str]] = NonetoCreateCachedContentConfig(andCachedContentfor reads)._CreateCachedContentConfig_to_vertex(and the mldev equivalent) to maplabels→labelsin the request body.GenerateContentConfigalready has alabelsfield and the serialization pattern is established — this would be a straightforward addition.Environment
google-genaiversion: 1.69.0vertexai=True)