googleapis / googleapis/python-genai

Add labels support for Vertex AI Context Caching cost tracking

Open
#1,787 3 comments 3 reactions 1 assignee Assigned to @kkorpal View on GitHub
priority: p3 type: feature request
Dominant language
Python
Stars
4k
Forks
1k
Avg merge
2d 11h
Merged PRs (30d)
40

Description

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

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.