Gemini AI Studio icon

Gemini AI Studio

Generate content using Google Gemini API

Overview

The Gemini AI Studio node (Resource: Default, Operation: Chat) enables multi-turn conversational interactions with Google's Gemini family of large language models. It is designed for scenarios where you want to build chatbots, virtual assistants, or any workflow that requires context-aware dialogue with an advanced AI model. The node supports including previous conversation history, customizing the model's behavior, and fine-tuning generation parameters.

Practical examples:

  • Building a customer support chatbot that remembers previous messages in a session.
  • Creating an internal assistant that can answer questions based on ongoing conversation context.
  • Automating helpdesk workflows where the AI needs to reference earlier user queries.

Properties

Name Type Meaning
Model options Selects which Gemini or Gemma model to use for the chat. Each model offers different capabilities, speed, and cost profiles.
Prompt string The main text prompt or message to send to the Gemini model as the latest user input.
Include Previous Messages boolean If enabled, includes prior conversation messages from the input data to provide context for the current turn.
Previous Messages Field string Specifies the field name in the input JSON that contains an array of previous messages (used only if "Include Previous Messages" is true).
Advanced Parameters collection A group of optional settings to control model output, such as randomness, output length, response format, tool usage, system prompt, safety settings, etc. See below for details.

Advanced Parameters sub-properties:

Name Type Meaning
Temperature number Controls randomness in responses (0 = deterministic, 2 = maximum randomness).
Top P number Nucleus sampling; considers tokens with top_p probability mass (e.g., 0.95 = 95%).
Top K number Considers only the top-k most likely tokens (1 = greedy decoding).
Maximum Output Tokens number Maximum number of tokens the model can generate in its response.
Stop Sequences string[] Comma-separated sequences that will cause the model to stop generating further output.
Tool Selection (Choose One) options Enables special model tools: None, Structured Output (JSON), Code Execution, or Google Search grounding. Only one at a time.
JSON Schema Definition string OpenAPI schema to constrain the model output (only shown if "Structured Output" is selected).
System Prompt string An additional instruction to set the overall behavior or persona of the model.
Safety Settings collection Fine-grained controls to block certain categories of harmful content at various thresholds.
Response Format (Legacy) options Sets the desired response MIME type (auto, JSON, plain text, markdown).
Enable Google Search Grounding (Legacy) boolean Enables Google Search grounding for factual accuracy (legacy option, not combinable with other tools).
Enable Code Execution (Legacy) boolean Enables code execution capabilities (legacy option, not combinable with other tools).

Output

The node outputs a single item per input, with the following structure in the json field:

{
  ... // All original input fields
  "geminiResponse": {
    // The full Gemini API response object, typically containing:
    "candidates": [
      {
        "content": {
          "parts": [
            { "text": "..." }
          ],
          "role": "model"
        },
        ...
      }
    ],
    // Additional metadata fields may be present depending on the model and configuration
  }
}
  • The key field of interest is geminiResponse, which contains the raw response from the Gemini API, including generated text and possibly other metadata.
  • If "Structured Output (JSON)" is used, the model will attempt to return valid JSON according to your schema.
  • If binary/image output is requested (not typical for chat), the response may include references to images or other modalities.

Dependencies

  • External Service: Requires access to the Google Gemini API.
  • Credentials: You must configure n8n credentials named geminiApi with:
    • apiKey: Your Google Gemini API key (required)
    • apiEndpoint: (optional) Custom endpoint, defaults to https://generativelanguage.googleapis.com/v1beta
  • n8n Configuration: No special environment variables required beyond the credential setup.
  • Dependencies: Uses the axios library for HTTP requests (bundled).

Troubleshooting

Common Issues:

  • Missing API Key: If the geminiApi credential is not configured or the API key is missing/invalid, the node will fail to connect.
  • Model Restrictions: Some features (like code execution or Google Search) are only available for specific models. Using them with unsupported models will have no effect.
  • Invalid JSON Schema: If you provide an invalid JSON schema for structured output, the node logs an error and may not constrain the output as expected.
  • Input Data Issues: If "Include Previous Messages" is enabled but the specified field does not contain a valid array of messages, the conversation context may be ignored or malformed.

Error Messages:

  • Gemini API Error: <status> - <message>: Indicates an error returned by the Gemini API. Check the status code and message for details (e.g., authentication errors, quota exceeded, invalid parameters).
  • Image URL is required for image analysis: (Not relevant for chat operation.)
  • Error: <message>: General error, often due to misconfiguration or network issues.

How to resolve:

  • Double-check your API credentials and permissions.
  • Ensure all required properties are set and valid.
  • For structured output, validate your JSON schema before use.
  • Review the model/tool compatibility matrix in the documentation.

Links and References


Discussion