The client options, as accepted by the GoogleGenAI constructor; if omitted, the SDK defaults
apply, reading the API key for the Gemini API from the environment. Vertex AI is reached instead by
setting vertexai, project and location, with Google Cloud project credentials. Unless
httpOptions.retryOptions is set, a request failing transiently is attempted up to 5 times in total
A client sharing throttling, logging and structured output support among requests to the same model;
models are told apart by their exact id, so the bare and models/-prefixed forms of an id are paced
separately, even though both draw on the same project quota and may overrun it together
A client is meant to be configured once by the consumer binding it, so that credentials and endpoint are settled for a whole execution rather than repeated by each job that draws on the same models.
The client takes over three concerns the API and the SDK leave to the caller:
Quota control: every request is paced against a per-model adaptive throttle. A request rejected over the rate
quota is resumed after the RetryInfo delay the API advertises, so a long run keeps within the quota instead of
failing on 429 errors. Other transient failures, such as an overloaded model, are retried as stated by options,
so a run survives a spike in demand on the model rather than aborting on the first one.
Function calling: when a request declares tools, the client resolves function calls itself, issuing one
throttled request per turn. Turns are unlimited unless automaticFunctionCalling.maximumRemoteCalls bounds them,
and only CallableTool tools are invoked. A request disabling automatic function calling is submitted once, and
its function calls are returned to the caller. The request fails with an Error if a response
carries no model content, if the model calls a function while no callable tool is declared, or if the turn limit
runs out before a final response; in every case the error carries no partial conversation.
Structured output: a requested response schema is honoured on every model. The API accepts a response schema
alongside tools only from the Gemini 3 generation onwards. Earlier models reply in prose, and an extra request
to gemini-2.5-flash-lite converts the reply into JSON conforming to the schema, at the cost of one additional
generation. A model rejecting the schema is switched to the conversion route for the lifetime of the client.
Creates a Gemini API client that works around known API limitations.
The client exposes the full GoogleGenAI surface. Model methods issuing requests are paced against the published rate quotas, and content generation honours a requested response schema on every model, even when function calling is involved and the model itself rejects a schema alongside tools.