Vertex AI icon

Vertex AI

Google Vertex AI Gemini API

Chat

AI-generated

Summary

Execute multi-turn Gemini chat with configurable generation parameters and optional structured output.

Inputs

  • model — Gemini model to use. Preview models require global region. Default: gemini-2.5-flash. Options include gemini-3-pro-preview, gemini-3-flash-preview, gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite, gemini-2.0-flash-001, gemini-2.0-flash-lite-001, gemini-1.5-pro-002, gemini-1.5-flash-002.
  • messages (required) — Conversation messages as a fixed collection with multipleValues. Each message has a role (user/model, default: user) and content string. These form the conversation history passed to the model.
  • options — Generation configuration collection. Optional parameters: maxOutputTokens (number, default 2048), temperature (number, 0-2, default 1), topP (number, 0-1, default 0.95), topK (number, default 40), systemInstruction (string, default ''), thinkingLevel (options: none/low/high, default none, enables Gemini 3 internal reasoning when set), timeout (number ms, default 60000), enableDebug (boolean, default false).
  • responseFormat — Output format options: text/plain (default), application/json, text/x.enum. When application/json or text/x.enum is selected, schemaMode and related schema settings become active.
  • schemaMode — Schema input method: simple (UI-defined schema properties, default) or advanced (raw JSON schema input). Only shows when responseFormat is application/json or text/x.enum.
  • enumValues — Comma-separated enum values for text/x.enum format. Only visible when responseFormat is text/x.enum and schemaMode is simple. Example: positive, negative, neutral.
  • schemaProperties — JSON response properties definition as a fixed collection (multiple values). Only visible when responseFormat is application/json and schemaMode is simple. Each property defines name, type (string/number/integer/boolean/array_string/array_number/object), description, required flag, and nullable/allowed values.
  • responseSchema — Raw JSON schema string for structured output. Only visible when schemaMode is advanced. Provided as a JSON object defining response structure (e.g., {type: 'OBJECT', properties: {...}, required: [...]}.

Output shape

Array of items, each containing a json object with the following fields: text (string, the generated text response), json (object|null, parsed JSON when responseFormat is application/json and parsing succeeds, otherwise null), model (string, selected model name), operation (string, always 'chat'), usage (object, API usageMetadata from response), safetyRatings (array, from response candidates[0].safetyRatings), finishReason (string, from response candidates[0].finishReason). When options.enableDebug is true, the item also includes a _debug object with requestDuration (ms), timestamp (ISO string), model, and itemIndex.

Timeout is enforced via Promise.race against the API call using the timeout parameter (default 60000ms). Rate-limit, timeout, and service-unavailable errors are classified and either returned as paired items when continueOnFail is true, or thrown. System instruction, if provided, is sent as a system message part. Multimodal (image) operations are not supported in this chat resource; only text conversation messages are consumed.

Examples

Example 1: Simple text chat with Gemini 2.5 Flash

model: gemini-2.5-flash; messages: [{role: user, content: 'Hello'}]; options: {}; responseFormat: text/plain

Example 2: Structured JSON output with schema properties

model: gemini-1.5-flash-002; messages: [{role: user, content: 'Extract user info'}]; options: {maxOutputTokens: 512}; responseFormat: application/json; schemaMode: simple; schemaProperties: [{name: name, type: string, required: true}, {name: email, type: string}]}

Links

Discussion