# Ask Gemini

**Action ID:** `google_gen_ai_ask_gemini`

## Description

Ask a Gemini anything you want! This node supports multiple Google Gemini models for generating AI-powered responses with text and image analysis capabilities.

## Provider

**Google Generative AI**

## Connection

| Name                     | Description                                         | Required | Category        |
| ------------------------ | --------------------------------------------------- | :------: | --------------- |
| Google Gen AI Connection | The Google Gen AI connection to use for the Gemini. |     ✓    | google\_gen\_ai |

## Input Parameters

| Name                        | Type     | Required | Default          | Description                                                                                                                                                                                                                                                                                                           |
| --------------------------- | -------- | :------: | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| model                       | dropdown |     -    | gemini-2.0-flash | The model to use for the chat. Available options: gemini-2.0-flash, gemini-2.0-pro-exp-02-05, gemini-2.0-flash-exp, gemini-2.0-flash-lite, gemini-2.0-flash-thinking-exp-01-21, gemini-1.5-flash, gemini-1.5-pro, gemini-2.0-flash-exp-image-generation, gemini-2.5-flash-preview-05-20, gemini-2.5-pro-preview-05-06 |
| model\_response\_modalities | dropdown |     -    | \[]              | Model response modalities for multi-modal outputs. Available options depend on the selected model.                                                                                                                                                                                                                    |
| prompt                      | string   |     ✓    | -                | The question to ask the model                                                                                                                                                                                                                                                                                         |
| images                      | array    |     -    | -                | The images to use for the chat. Supported formats: JPG, PNG                                                                                                                                                                                                                                                           |
| temperature                 | number   |     -    | 0.9              | Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive. Range: 0.0 to 1.0                                                                                                                                           |
| max\_tokens                 | integer  |     -    | 2048             | The maximum number of tokens to generate. Requests can use up to 2,048 or 4,096 tokens shared between prompt and completion depending on the model                                                                                                                                                                    |
| top\_p                      | number   |     -    | 1.0              | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top\_p probability mass.                                                                                                                                                               |
| system\_message             | string   |     -    | -                | Instructions for the AI assistant on how to behave and respond.                                                                                                                                                                                                                                                       |
| response\_schema            | object   |     -    | -                | Controls the format of the response to be returned by the node. Visit <https://ai.google.dev/gemini-api/docs/structured-output?lang=python#json-schemas> for more information.                                                                                                                                        |

<details>

<summary>View JSON Schema</summary>

```json
{
  "description": "Ask Gemini node input.",
  "properties": {
    "model": {
      "default": "gemini-2.0-flash",
      "description": "The model to use for the chat.",
      "enum": [
        "gemini-2.0-flash",
        "gemini-2.0-pro-exp-02-05",
        "gemini-2.0-flash-exp",
        "gemini-2.0-flash-lite",
        "gemini-2.0-flash-thinking-exp-01-21",
        "gemini-1.5-flash",
        "gemini-1.5-pro",
        "gemini-2.0-flash-exp-image-generation",
        "models/gemini-2.5-flash-preview-05-20",
        "gemini-2.5-pro-preview-05-06"
      ],
      "title": "Model",
      "type": "string"
    },
    "model_response_modalities": {
      "default": [],
      "title": "Model Response Modalities",
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Model response modalities for multi-modal outputs."
    },
    "prompt": {
      "description": "The question to ask the model.",
      "title": "Question",
      "type": "string"
    },
    "images": {
      "default": null,
      "description": "The images to use for the chat.",
      "items": {
        "type": "string"
      },
      "title": "Images",
      "type": "array"
    },
    "temperature": {
      "default": 0.9,
      "description": "Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.",
      "maximum": 1.0,
      "minimum": 0.0,
      "title": "Temperature",
      "type": "number"
    },
    "max_tokens": {
      "default": 2048,
      "description": "The maximum number of tokens to generate. Requests can use up to 2,048 or 4,096 tokens shared between prompt and completion depending on the model.",
      "title": "Maximum Tokens",
      "type": "integer"
    },
    "top_p": {
      "default": 1.0,
      "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.",
      "title": "Top P",
      "type": "number"
    },
    "system_message": {
      "default": null,
      "description": "Instructions for the AI assistant on how to behave and respond.",
      "title": "System Message",
      "type": "string"
    },
    "response_schema": {
      "default": null,
      "description": "Controls the format of the response to be returned by the node. Visit https://ai.google.dev/gemini-api/docs/structured-output?lang=python#json-schemas for more information.",
      "title": "Response Schema",
      "type": "object"
    }
  },
  "required": [
    "prompt"
  ],
  "title": "AskGeminiInput",
  "type": "object"
}
```

</details>

## Output Parameters

| Name    | Type | Description              |
| ------- | ---- | ------------------------ |
| content | any  | The response from Gemini |

<details>

<summary>View JSON Schema</summary>

```json
{
  "description": "Ask Gemini node output.",
  "properties": {
    "content": {
      "title": "Content",
      "description": "The response from Gemini."
    }
  },
  "required": [
    "content"
  ],
  "title": "AskGeminiOutput",
  "type": "object"
}
```

</details>

## How It Works

This node sends your prompt to Google's Gemini API along with your configuration parameters. Gemini processes your question using the specified system message as context, then generates a response based on the temperature and other settings you've configured. If you provide images, they are analyzed alongside the text prompt. The response is returned as text or structured data that can be used by subsequent nodes in your workflow.

## Usage Examples

### Example 1: Simple Question

**Input:**

```
prompt: "What are the main benefits of renewable energy?"
model: "gemini-2.0-flash"
temperature: 0.3
```

**Output:**

```
content: "Renewable energy offers several key benefits: 1) Reduced greenhouse gas emissions, 2) Sustainable long-term energy supply, 3) Lower operating costs after initial setup, 4) Job creation in clean energy sectors..."
```

### Example 2: Image Analysis

**Input:**

```
prompt: "Analyze this chart and provide insights"
model: "gemini-1.5-pro"
temperature: 0.5
images: ["https://example.com/chart.png"]
```

**Output:**

```
content: "This bar chart shows quarterly revenue trends. Key observations: Q2 saw a 25% increase compared to Q1, Q3 peaked at $2.5M, and Q4 declined by 15%..."
```

### Example 3: Structured Output with Schema

**Input:**

```
prompt: "Extract person details from: John Smith, age 30, email: john@example.com"
model: "gemini-2.0-flash"
response_schema: {
  "type": "object",
  "properties": {
    "name": {"type": "string"},
    "age": {"type": "integer"},
    "email": {"type": "string"}
  }
}
```

**Output:**

```
content: {
  "name": "John Smith",
  "age": 30,
  "email": "john@example.com"
}
```

## Common Use Cases

* **Content Generation**: Create blog posts, marketing content, and product descriptions
* **Information Analysis**: Analyze images, documents, and data to extract insights
* **Customer Support**: Generate helpful responses to customer inquiries
* **Research Assistance**: Summarize information and explain complex topics
* **Data Extraction**: Extract structured information from unstructured text or images
* **Code Generation**: Generate or explain code snippets across multiple languages
* **Translation**: Translate content between languages with context awareness

## Error Handling

| Error Type              | Cause                                            | Solution                                                                         |
| ----------------------- | ------------------------------------------------ | -------------------------------------------------------------------------------- |
| Authentication Error    | Invalid or missing Google API key                | Verify your Google Gen AI connection is properly configured with a valid API key |
| Rate Limit Error        | Too many requests in a short period              | Implement delays between requests or check API quota limits                      |
| Invalid Model           | Model name doesn't exist or access not granted   | Verify the model name and ensure your API key has access to it                   |
| Token Limit Exceeded    | Prompt + response exceeds model's context window | Reduce prompt length or decrease max\_tokens parameter                           |
| Invalid Image Format    | Unsupported image format provided                | Ensure images are in JPG or PNG format only                                      |
| Schema Validation Error | Response doesn't match the specified schema      | Review and adjust your response\_schema definition                               |

## Notes

* **Model Selection**: Choose a model based on your needs. Gemini 2.0 Flash is fast and cost-effective for most tasks. Gemini 1.5 Pro and Gemini 2.0 Pro offer superior reasoning for complex queries.
* **Multi-Modal Support**: Some models like Gemini 2.0 Flash Exp support image generation and other modalities. Use `model_response_modalities` to specify the desired output type.
* **Temperature Control**: Lower temperature (0.0-0.3) for factual, deterministic responses. Higher temperature (0.7-1.0) for creative content.
* **Image Analysis**: You can provide images (JPG or PNG) alongside your prompt for analysis and discussion.
* **Structured Output**: Use the `response_schema` parameter to enforce a specific JSON structure in the response. See Google's documentation for schema syntax.
* **System Messages**: Craft clear system messages to guide Gemini's behavior, tone, and response format.
* **Cost Optimization**: Gemini 2.0 Flash is the most cost-effective option for most use cases.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.agenticflow.ai/reference/nodes/google_gen_ai_ask_gemini.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
