Gemini Search icon

Gemini Search

Perform searches and generate content using Google Gemini API

Overview

This node integrates with the Google Gemini API to perform two main operations: Web Search and Content Generation. It allows users to send prompts to various Gemini language models, optionally guiding the model's behavior with system instructions and controlling output randomness and length.

  • Web Search: Performs a web search using Gemini, optionally restricting results to specific URLs or providing an organization context.
  • Generate Content: Generates text content based on a prompt without performing a web search.

Use cases include:

  • Automating information retrieval from the web with contextual filtering.
  • Generating creative or structured text content such as articles, summaries, or responses.
  • Enhancing workflows that require AI-driven search or content generation within n8n.

Properties

Name Meaning
Model The Gemini model to use. Options: Gemini 1.0 Pro, Gemini 1.5 Pro, Gemini 2.0 Flash, Gemini 2.5 Pro Preview, Gemini 2.5 Flash Preview
Prompt The input text prompt sent to the Gemini model (required).
Organization Context Optional organization name to provide context for the web search operation.
Restrict Search to URLs Optional comma-separated list of URLs to restrict the web search results to.
System Instruction Optional instruction to guide the model’s behavior during generation or search.
Options Collection of advanced parameters:
- Temperature Controls randomness in the response (range 0 to 1). Default is 0.6.
- Max Output Tokens Maximum number of tokens to generate in the response. Default is 2048.
- Top P Nucleus sampling parameter controlling diversity. Default is 1.
- Top K Limits sampling to top K tokens. Default is 1.
- Extract Source URL Boolean flag to extract the source URL from the web search response. Default is false.

Output

The node outputs JSON data containing:

  • response: The main textual response generated by the Gemini model.
  • fullResponse: The complete raw response object returned by the Gemini API, including metadata.
  • For Web Search operation:
    • restrictedUrls: If URL restriction was applied, echoes the list of restricted URLs.
    • sourceUrl: The extracted source URL from the search result if enabled.
    • redirectedSourceUrl: The final resolved URL after following HTTP redirects (if extraction succeeded).
    • redirectError: Error message if redirect resolution failed.

If the option to extract the source URL is enabled, the node attempts to resolve any HTTP redirects to provide the final destination URL.

Dependencies

  • Requires an API key credential for authenticating with the Google Gemini API.
  • Uses the axios library internally to perform HTTP HEAD requests for URL redirection resolution.
  • No additional environment variables are explicitly required beyond the API credential.

Troubleshooting

  • Common issues:

    • Invalid or missing API credentials will cause authentication failures.
    • Network timeouts or connectivity issues may prevent successful API calls or URL resolution.
    • Providing invalid or empty prompts will likely result in errors or empty responses.
    • Restricting search URLs incorrectly (e.g., malformed URLs) may lead to no results.
  • Error messages:

    • Errors thrown by the Gemini API are propagated; ensure your API key has proper permissions.
    • Redirect resolution errors are caught and logged but do not fail the node execution; check logs for details.
    • If the node fails and "Continue On Fail" is disabled, the workflow will stop on error.

Links and References

Discussion