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, transient failures are retried with the default SDK retry options
The labels identifying the cost source of the requests the client issues, either fixed or
computed on each request, so that they can name the job issuing it from the context it runs
in; merged with the config.labels of the request, which win on shared keys
Optional Readonlylabels?: Lazy<Labels>The labels identifying the cost source of the requests the client issues, either fixed or
computed on each request, so that they can name the job issuing it from the context it runs
in; merged with the config.labels of the request, which win on shared keys
A client sharing throttling and logging 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 when both forms are in use at the same time
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. The API states the request limit of a model only when rejecting a request over it, so a
model runs as fast as the throttle finds feasible until its first rejection over requests per minute, and is then
held to the limit that rejection states. 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.
Property order: a JSON response requested with a responseJsonSchema lists the properties of each object in
the order the schema declares them, nested objects included, rather than alphabetically with required ones first.
An object stating its own propertyOrdering keeps it, and the caller's schema is never modified. The order is a
strong hint the model may not strictly follow, so properties whose values are needed must still be required.
Property names made of digits alone always come first, as JavaScript lists them ahead of any other key.
A JSON response requested with tools enabled requires a Gemini 3 or later model. Earlier models reject a response
schema alongside tools: the request then fails with the API error, and no other model is ever substituted for the
one the caller named, so the response is always generated by the requested model or not at all.
The usageMetadata of a returned response accounts for every function calling turn issued to produce it, so token
budgets and accounting see what the generation actually cost. Token counts are summed across turns, while
initialPromptTokenCount is taken from the first turn and trafficType from the last: a prompt size and a billing
tier each describe a single request and do not add up across the several turns of a generation.
Every response to a content generation request, streamed or not, is logged with its model, labels and token usage, one entry per request, so a cost spike can be traced to the job causing it from the log alone. Input tokens include those spent on tool use prompts, output tokens those spent on reasoning, which are also stated on their own.
Labels are attached to content, image and video generation requests on Vertex AI alone, where they also split billing
reports. Vertex AI accepts at most 64 labels per request, with keys and values of up to 63 lowercase letters, digits,
underscores and dashes, keys opening with a letter. The client labels, merged with the config.labels of the request,
are brought within these limits before they are attached, so that a path such as /events/coimbra-university is
always sent as events-coimbra-university, and they are logged as supplied. Where they exceed the label count, client
labels are dropped first. The Gemini Developer API rejects labels altogether, so there they are only logged.
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 resolves function calls at the same pace, sending every request to the model the caller named and never to a model of the client's own choosing.