googleapis / googleapis/python-genai

Feature Request: Support labels in GenerateContentConfig for Gemini API (Developer API)

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

Descrizione

**Is your feature request related to a problem? Please describe.**
Currently, users leveraging the Gemini API (via Google AI Studio / Developer API) cannot perform granular cost attribution or token usage tracking by team or project. In Google Cloud, the standard way to do this is via request-level resource labeling.

However, when trying to pass `labels` using the new unified `google-genai` SDK against the Gemini API, the SDK throws a hardcoded error:
`ValueError: labels parameter is not supported in Gemini API.`

This forces organizations that rely on the Gemini API to either fly blind on internal cost allocations or build complex multi-project architectures just to separate billing per API key.

**Describe the solution you'd like**
I would like the `labels` parameter inside `GenerateContentConfig` to be fully supported for the Gemini API, matching the behavior currently available in Vertex AI.

Specifically:
1. The backend API (`generativelanguage.googleapis.com`) should accept and pipe these labels to Google Cloud Billing.
2. The `google-genai` Python SDK should remove the `ValueError` restriction in the `_GenerateContentConfig_to_mldev` mapping function, allowing the labels to pass through.

**Describe alternatives you've considered**
1. **Migrating workloads to Vertex AI:** This is the current workaround, as Vertex AI natively supports labels. However, some customers prefer or are constrained to the Gemini API (AI Studio) due to specific pricing tiers, early model access, or simplicity of API keys.
2. **Multi-Project Architecture:** Creating a separate Google Cloud Project for every single team or use case to isolate billing. This introduces significant administrative overhead.
3. **Application-Level Tracking:** Building a custom API gateway to intercept responses, parse `promptTokenCount` and `candidatesTokenCount`, and manually log/calculate costs in external databases.

**Additional context**
Customer testing resulted in the following traceback when attempting to use standard FinOps practices on the Gemini API:

```python
import os
from google import genai
from google.genai import types

client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])

response = client.models.generate_content(
model="gemini-2.0-flash",
contents="Who is Linus Torvalds?",
config=types.GenerateContentConfig(
labels={
"purpose": "exploration",
"environment": "development",
}
),
)
# Raises: ValueError: labels parameter is not supported in Gemini API.
```

The restriction is currently hardcoded here in the SDK:
https://github.com/googleapis/python-genai/blob/ba41ce578b905bbd7e8da8d9e203d4e9d6b330de/google/genai/models.py#L1298-L1299

Supporting labels uniformly across both Vertex AI and Gemini API backends would greatly improve the enterprise governance and cost visibility for AI Studio customers.

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.