googleapis / googleapis/python-genai

Feature request: support labels on CreateCachedContentConfig for billing attribution

Aperta
#2,263 1 commento 0 reazioni 1 assegnatario Rivendicata da @Venkaiahbabuneelam Vedi su GitHub
priority: p2 type: feature request
Lingua principale
Python
Stelle
4k
Fork
1k
Merge medio
2g 12h
PR unite (30g)
41

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.