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:
- The backend API (
generativelanguage.googleapis.com) should accept and pipe these labels to Google Cloud Billing.
- 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
- 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.
- Multi-Project Architecture: Creating a separate Google Cloud Project for every single team or use case to isolate billing. This introduces significant administrative overhead.
- 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:
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:
|
if getv(from_object, ['labels']) is not None: |
|
raise ValueError('labels parameter is not supported in Gemini API.') |
Supporting labels uniformly across both Vertex AI and Gemini API backends would greatly improve the enterprise governance and cost visibility for AI Studio customers.
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
labelsusing the new unifiedgoogle-genaiSDK 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
labelsparameter insideGenerateContentConfigto be fully supported for the Gemini API, matching the behavior currently available in Vertex AI.Specifically:
generativelanguage.googleapis.com) should accept and pipe these labels to Google Cloud Billing.google-genaiPython SDK should remove theValueErrorrestriction in the_GenerateContentConfig_to_mldevmapping function, allowing the labels to pass through.Describe alternatives you've considered
promptTokenCountandcandidatesTokenCount, 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:
The restriction is currently hardcoded here in the SDK:
python-genai/google/genai/models.py
Lines 1298 to 1299 in ba41ce5
Supporting labels uniformly across both Vertex AI and Gemini API backends would greatly improve the enterprise governance and cost visibility for AI Studio customers.