Package (Required)
Checked other resources
Feature Description
Google recently introduced the Flex inference tier for the Gemini API, which offers a 50% cost reduction in exchange for variable latency. This is highly desirable for latency-tolerant workloads like asynchronous data cataloging or batch processing.
In the official google-genai SDK, this is implemented by passing config={'service_tier': 'flex'} to the generate_content request.
Currently, in langchain-google-genai, there seems to be no native way to propagate the service_tier parameter down to the underlying GenerateContentConfig.
Use Case
I am building a batch data cataloging project using gemini-3-flash-preview with structured outputs. Since this runs in the background and doesn't require real-time latency, the 50% cost savings from the Flex tier is vital for optimizing the budget.
Proposed Solution
Allow service_tier to be defined during ChatGoogleGenerativeAI initialization or captured via .bind(), and ensure it gets properly mapped to the GenerateContentConfig object inside the _build_request_config method.
Alternatives Considered
The only current workaround is to bypass LangChain entirely and use the official google-genai SDK directly. However, this is not ideal as it breaks existing LCEL chains, callback handlers, and the highly convenient .with_structured_output() abstraction, requiring a significant rewrite of the application logic.
Code Example of Attempted Usage
Here is how I intuitively tried to implement it using LangChain, but the configuration isn't passed down to the Google API:
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.callbacks.base import AsyncCallbackHandler
class VerboseCallbackHandler(AsyncCallbackHandler):
async def on_llm_error(self, error, **kwargs):
print(f" [x] [LangChain] Gemini Request Failed: {type(error).__name__}: {error}", flush=True)
# Initialize the model
llm = ChatGoogleGenerativeAI(
model="gemini-3-flash-preview",
temperature=0,
callbacks=[VerboseCallbackHandler()],
timeout=1800,
max_retries=3
)
# Attempt to bind the Flex service tier
llm_flex = llm.bind(service_tier="flex") # or "FLEX"
# Use with structured output
structured_llm = llm_flex.with_structured_output(pydantic_schema, include_raw=True)
Additional Context
A similar issue was recently opened for the JS ecosystem: langchain-ai/langchainjs#10655
Link for the Google page that talks about Flex: https://ai.google.dev/gemini-api/docs/flex-inference
Package (Required)
Checked other resources
Feature Description
Google recently introduced the Flex inference tier for the Gemini API, which offers a 50% cost reduction in exchange for variable latency. This is highly desirable for latency-tolerant workloads like asynchronous data cataloging or batch processing.
In the official
google-genaiSDK, this is implemented by passingconfig={'service_tier': 'flex'}to thegenerate_contentrequest.Currently, in
langchain-google-genai, there seems to be no native way to propagate theservice_tierparameter down to the underlyingGenerateContentConfig.Use Case
I am building a batch data cataloging project using
gemini-3-flash-previewwith structured outputs. Since this runs in the background and doesn't require real-time latency, the 50% cost savings from the Flex tier is vital for optimizing the budget.Proposed Solution
Alternatives Considered
The only current workaround is to bypass LangChain entirely and use the official
google-genaiSDK directly. However, this is not ideal as it breaks existing LCEL chains, callback handlers, and the highly convenient.with_structured_output()abstraction, requiring a significant rewrite of the application logic.Code Example of Attempted Usage
Here is how I intuitively tried to implement it using LangChain, but the configuration isn't passed down to the Google API:
Additional Context
A similar issue was recently opened for the JS ecosystem: langchain-ai/langchainjs#10655
Link for the Google page that talks about Flex: https://ai.google.dev/gemini-api/docs/flex-inference