googleapis / googleapis/python-genai

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

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

Description

**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.

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.