googleapis / googleapis/python-genai

Feature request: support labels on CreateCachedContentConfig for billing attribution

Open
#2,263 1 comment 0 reactions 1 assignee Claimed by @Venkaiahbabuneelam View on GitHub
priority: p2 type: feature request
Dominant language
Python
Stars
4k
Forks
1k
Avg merge
2d 11h
Merged PRs (30d)
40

Description

## 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

```python
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 `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`)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.