Actions2
Overview
This node integrates with Google Generative AI models via the Vercel AI SDK to generate either free-form text completions or structured objects based on a JSON schema. It supports two main operations:
- Generate Text: Create text outputs from a simple prompt or a conversation consisting of multiple messages.
- Generate Object: Produce structured data that conforms to a user-defined JSON schema, useful for extracting specific information or generating complex data structures.
Common scenarios include:
- Automating content creation such as writing articles, summaries, or replies.
- Building chatbots or conversational agents by providing multi-message conversations.
- Extracting structured insights like sentiment analysis, classification results, or custom data objects from text inputs.
- Processing and analyzing files (text or binary) by including them in conversation messages.
Practical example:
- Use "Generate Text" with a simple prompt to create marketing copy.
- Use "Generate Object" with a sentiment analysis schema to analyze customer feedback and get structured sentiment scores.
Properties
| Name | Meaning |
|---|---|
| Model Name or ID | Select which Google Generative AI model to use. Options include various Gemini models optimized for different tasks (e.g., text generation, vision). Can also specify a model ID via expression. |
| Input Type | Choose how to provide input: "Simple Prompt" (single text prompt) or "Messages" (a conversation with multiple messages). |
| System | (For Simple Prompt) System prompt guiding the model's behavior, e.g., "You are a helpful assistant." Optional but helps steer responses. |
| Prompt | (For Simple Prompt) The single text prompt to generate completion for. |
| Messages | (For Messages input) A collection of messages forming a conversation. Each message has a role (user, assistant, system), content type (text or file), and content. Files can be provided as binary data or URLs with MIME types. |
| Messages as JSON | Whether to input messages as a raw JSON array instead of using the UI. |
| Messages (JSON) | The JSON array of message objects (role, content) when "Messages as JSON" is enabled. |
| Schema Name | (For Generate Object) Optional name of the output schema to guide object generation. |
| Schema Description | (For Generate Object) Optional description of the output schema for additional guidance. |
| Schema | (For Generate Object) JSON schema defining the structure and constraints of the object to generate. |
| Options | Collection of optional parameters: - Max Tokens: Maximum tokens to generate. - Temperature: Controls randomness of output (0–2). - Include Request Body: Whether to include the request body in the output. |
| Safety Settings | Configure safety categories (e.g., Hate Speech, Dangerous Content) and thresholds to block or filter certain outputs. |
| Use Search Grounding | Enable real-time or up-to-date information if supported by the model. |
Output
The node outputs an array of items where each item contains a json field with the response data from the Google Generative AI API.
For Generate Text operation, the output JSON includes:
text: The generated text completion.toolCalls,toolResults,finishReason: Metadata about generation steps and completion status.usage: Token usage statistics (promptTokens,completionTokens,totalTokens).response: Metadata about the API response (id, modelId, timestamp, headers).steps,warnings,experimental_providerMetadata: Additional metadata.- Optionally, if enabled, the original request body under
request.body.
For Generate Object operation, the output JSON includes:
object: The generated structured object conforming to the provided JSON schema.- Similar metadata fields as in Generate Text (
finishReason,usage,response,warnings, etc.). - Optionally, the original request body if requested.
If the input messages contain binary files, these are sent to the model encoded appropriately, but the output does not directly include binary data.
Dependencies
- Requires a valid Google Generative AI API key credential configured in n8n.
- Uses the Vercel AI SDK (
@ai-sdk/google) and Google Generative Language API endpoint. - Requires internet access to call Google's generative language API at
https://generativelanguage.googleapis.com/v1beta. - Supports loading available models dynamically from the Google API or falls back to a default list.
Troubleshooting
- Missing API Key: If no API key is provided in credentials, the node throws an error. Ensure you have configured a valid Google Generative AI API key credential.
- Invalid JSON in Messages (JSON): When using JSON input for messages, invalid JSON syntax will cause an error. Validate your JSON format carefully.
- Binary Property Not Found: If a binary file is referenced in messages but the specified binary property does not exist on the input item, an error is thrown. Verify the binary property name matches the input data.
- Invalid JSON Schema: For Generate Object, if the provided JSON schema is invalid or fails validation, the node throws an error. Use a proper JSON schema validator to check your schema.
- Safety Settings Blocking Output: If configured safety settings block certain content, the output may be filtered or blocked. Adjust safety thresholds accordingly.
- Model Not Found or Unsupported: If the selected model is unavailable or unsupported, the node may fail. Refresh the model list or select a different model.