Skip to content

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

@KenTandrian

Description

@KenTandrian

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:

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.

Metadata

Metadata

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions