Overview
The Gemini AI Studio node for n8n enables you to generate content using Google's Gemini API. Specifically, with the "Default" resource and "Generate Content" operation, this node allows you to send a text prompt to a selected Gemini model and receive generated content in response. This is useful for tasks such as text generation, summarization, creative writing, code generation, or any scenario where you need AI-generated text based on your input.
Practical examples:
- Automatically drafting emails or reports from structured prompts.
- Generating product descriptions or marketing copy.
- Creating summaries of long documents.
- Producing JSON-formatted data for downstream automation.
- Enabling advanced AI features (like code execution or Google Search grounding) in workflows.
Properties
| Name | Type | Meaning |
|---|---|---|
| Model | options | The AI model to use for content generation. Different models offer various capabilities, speed, and cost profiles. |
| Prompt | string | The text prompt sent to Gemini. This is the main instruction or question for the AI to respond to. |
| Advanced Parameters | collection | A group of optional parameters to fine-tune the model's behavior (see below for details). |
| └ Temperature | number | Controls randomness in output (0 = deterministic, 2 = maximum randomness). |
| └ Top P | number | Nucleus sampling: considers tokens with top_p probability mass (e.g., 0.95 = 95% probability mass). |
| └ Top K | number | Considers only the top-k tokens for each step (1 = greedy decoding). |
| └ Maximum Output Tokens | number | Maximum number of tokens to generate in the response. |
| └ Stop Sequences | string[] | Comma-separated sequences that will cause the model to stop generating further output. |
| └ Tool Selection (Choose One) | options | Enables special capabilities: None, Structured Output (JSON), Code Execution, or Google Search. Only one can be enabled at a time. |
| └ JSON Schema Definition | string | (Shown if "Structured Output (JSON)" is selected) An OpenAPI schema object to constrain the model output format. |
| └ System Prompt | string | Optional system-level prompt to guide the model’s overall behavior. |
| └ Safety Settings | fixedCollection | Configure safety categories (Harassment, Hate Speech, Sexually Explicit, Dangerous Content) and thresholds for content moderation. |
| └ Response Format (Legacy) | options | (If no tool is selected) Desired format of the response: Auto, JSON, Text, or Markdown. |
| └ Enable Google Search Grounding (Legacy) | boolean | (If no tool is selected) Whether to enable Google Search grounding for factual responses. |
| └ Enable Code Execution (Legacy) | boolean | (If no tool is selected) Whether to enable code execution capabilities. |
Output
The node outputs an array of items, each containing:
{
// ...original input fields,
"geminiResponse": {
// The full response from the Gemini API.
// Typical structure:
"candidates": [
{
"content": {
"parts": [
{ "text": "Generated content here..." }
]
},
// ...other metadata
}
],
// If structured output or image generation is used, may include additional fields.
}
}
- The
geminiResponsefield contains the raw response from the Gemini API, which typically includes generated text undercandidates[0].content.parts[0].text. - If "Structured Output (JSON)" is enabled, the response will conform to the provided JSON schema.
- If image generation is used (with supported models), the response may also include image data (as URLs or encoded images).
Dependencies
- External Service: Requires access to the Google Gemini API.
- Credentials: You must configure a credential named
geminiApiin n8n, containing:apiKey: Your Gemini API key (required).apiEndpoint: (Optional) Custom endpoint; defaults tohttps://generativelanguage.googleapis.com/v1beta.
Troubleshooting
Common Issues:
- Missing API Key: If credentials are not set up correctly, the node will fail to authenticate.
- Invalid Model Selection: Some tools/features are only available for specific models. Using unsupported combinations may result in errors.
- Malformed JSON Schema: If the JSON Schema Definition is invalid, the node may log an error and ignore the schema constraint.
- Empty Prompt: The "Prompt" property is required; leaving it empty will cause the node to throw an error.
- API Quotas/Rate Limits: Exceeding your Gemini API quota will result in errors from the API.
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 failure, invalid request, quota exceeded).Image URL is required for image analysis: (Not relevant for Generate Content, but may appear if using other operations without providing necessary media input.)Invalid JSON schema provided: The JSON Schema Definition could not be parsed; check for syntax errors.
How to resolve:
- Double-check your API credentials and permissions.
- Ensure all required properties are filled.
- Use valid combinations of model and tool selection.
- Validate your JSON schema using an external tool before pasting it into the node.
Links and References
- Google Gemini API Documentation
- OpenAPI Specification for JSON Schema
- n8n Documentation
- Gemini Models Overview
Tip: For best results, tailor your prompt and advanced parameters to your specific use case, and consult the Gemini API documentation for model-specific capabilities and limitations.