Skip to content
Help guide the future of agentgateway — Take the survey

Gemini

Verified : Automated tests passed for: Configuration files: The configuration files on this page were checked against their schema. End-to-end run: Every step ran in a fresh test environment and the results were checked.
Page as Markdown

Route agentgateway LLM traffic to Google Gemini models.

Configure Google Gemini as an LLM provider in agentgateway.

Configuration

You can add the model in the UI or in your configuration file.

To add the model in the UI, follow these steps. The steps create the same model as the Config file tab.

  1. Set your API key in the GEMINI_API_KEY environment variable. The UI checks that the variable exists when you save the model.

    export GEMINI_API_KEY='<your-api-key>'
  2. Create a configuration file with an empty llm section, and start agentgateway in the same terminal. Without an llm section, the UI does not show the LLM > Models page.

    cat > config.yaml <<'EOF'
    # yaml-language-server: $schema=https://agentgateway.dev/schema/config
    llm:
      models: []
    EOF
    agentgateway -f config.yaml
  3. Open LLM > Models, such as http://localhost:15000/ui/llm/models, and click Add model.

  4. From the Provider dropdown, select Gemini.

  5. Keep the default gemini/* in the Incoming model match field.

  6. For the Provider API key, select Env var, and enter GEMINI_API_KEY.

  7. For Outgoing model, keep Strip gemini/. This option removes the gemini/ prefix before the request is forwarded. To send every request to one model instead, select Explicit, and enter the model name. This option sets params.model.

    Add model drawer with Gemini selected as the provider, gemini/* as the incoming model match, and GEMINI_API_KEY as the environment variable for the provider API key
    Add model drawer with Gemini selected as the provider, gemini/* as the incoming model match, and GEMINI_API_KEY as the environment variable for the provider API key
  8. Click Save model.

Whether the UI can save depends on your storage mode. For more information, see Save changes from the UI.

Reasoning effort

Set reasoning_effort in OpenAI-compatible Chat Completions requests to a Gemini model to configure Gemini thinking. For Gemini 2.5 and older models, reasoning_effort maps to thinkingConfig.thinkingBudget. For Gemini 3 and Gemini 4 models, reasoning_effort maps to thinkingConfig.thinkingLevel.

Model familyreasoning_effort behavior
Gemini 2.5 and olderminimal, low, medium, high, xhigh, and max use thinkingBudget values. none omits thinkingConfig.
Gemini 3minimal, low, medium, high, xhigh, and max use thinkingLevel. none omits thinkingConfig.
Gemini 4minimal and low use thinkingLevel: "low". medium uses thinkingLevel: "medium". high, xhigh, and max use thinkingLevel: "high". none omits thinkingConfig.

For Gemma 4 models, none, minimal, and low use thinkingLevel: "minimal", and medium, high, xhigh, and max use thinkingLevel: "high".

Use Decisions and SystemOne

Gemini decision models, such as gemini-decision-1, can answer OpenAI Decisions (/v1/decisions) and TypeSafe SystemOne (/v1/systemone) requests. Agentgateway converts both formats to the Gemini Decisions API (/v1beta/decisions) and converts the answers back to the client’s format. The conversion is best effort.

With the llm configuration, both paths are mapped automatically. Add a model entry for the decision model.

# yaml-language-server: $schema=https://agentgateway.dev/schema/config
llm:
  models:
  - name: gemini-decision-1
    provider: gemini
    params:
      apiKey: "$GEMINI_API_KEY"

Send a Decisions request.

curl "localhost:4000/v1/decisions" -H content-type:application/json -d '{
  "model": "gemini-decision-1",
  "input": [{"role": "user", "content": [{"type": "input_text", "text": "The package was left in the rain and the box is soaked through."}]}],
  "questions": [{"type": "predicate", "name": "visible_damage", "instructions": "Does the customer report visible damage to the package?"}]
}' | jq

Example output:

{
  "model": "gemini-decision-1",
  "answers": [
    {"type": "predicate", "name": "visible_damage", "probability": 0.64}
  ],
  "usage": {"input_tokens": 156, "output_tokens": 0, "total_tokens": 156, ...}
}

For the supported request content, see Decisions.

Use structured outputs

For OpenAI-compatible Chat Completions requests, set response_format.type to json_schema to request structured JSON from a Gemini model. Agentgateway sends the schema to Gemini as responseJsonSchema. Standard JSON Schema keywords, such as $defs, $ref, anyOf, and additionalProperties, pass through unchanged. Tool definitions are handled differently. For schemas in tools[].function.parameters, agentgateway inlines $defs and $ref, removes fields that Gemini does not support, such as additionalProperties, and keeps a propertyOrdering field that you set.
curl "localhost:4000/v1/chat/completions" -H content-type:application/json -d '{
  "model": "gemini/gemini-2.5-flash",
  "messages": [
    {
      "role": "user",
      "content": "Return one calendar event for tomorrow."
    }
  ],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "calendar_event",
      "strict": true,
      "schema": {
        "$defs": {
          "CalendarEvent": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "name": { "type": "string" },
              "date": { "type": "string" }
            },
            "required": ["name", "date"]
          }
        },
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "event": { "$ref": "#/$defs/CalendarEvent" }
        },
        "required": ["event"]
      }
    }
  }
}' | jq

Example output, in which content is a JSON string that matches the schema:

{
  "model": "gemini-2.5-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "{\"event\":{\"name\":\"Team sync\",\"date\":\"2026-11-25\"}}"
      },
      "finish_reason": "stop"
    }
  ],
  ...
}

Send images and files in Responses requests

For Gemini, agentgateway converts an OpenAI Responses request to Chat Completions. Gemini has no Chat Completions file part, so the conversion sends both images and files as image_url parts.

  • An input_image part must set image_url.
  • An input_file part must carry the file as a base64 data URL, such as data:application/pdf;base64,<base64>, in file_data or file_url. The filename is not sent.

The conversion rejects a file that sets only file_id, a file_data value that is not a data URL, and a remote URL in file_url. It also rejects an image or file in a system, developer, or assistant message.

Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate ↵ select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.