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

Gemini

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

Configure Google Gemini as an LLM provider for agentgateway.

Configure Google Gemini as an LLM provider in agentgateway.

Before you begin

Install and set up an agentgateway proxy.

Set up access to Gemini

  1. Save your Gemini API key as an environment variable. To retrieve your API key, log in to the Google AI Studio and select API Keys.

    export GOOGLE_KEY=<your-api-key>
  2. Create a secret to authenticate to Google.

    kubectl apply -f - <<EOF
    apiVersion: v1
    kind: Secret
    metadata:
      name: google-secret
      namespace: agentgateway-system
    type: Opaque
    stringData:
      Authorization: $GOOGLE_KEY
    EOF
  3. Create an AgentgatewayBackend resource to configure an LLM provider that references the AI API key secret.

    kubectl apply -f- <<EOF
    apiVersion: agentgateway.dev/v1alpha1
    kind: AgentgatewayBackend
    metadata:
      name: google
      namespace: agentgateway-system
    spec:
      ai:
        provider:
          gemini:
            model: gemini-2.5-flash-lite
      policies:
        auth:
          secretRef:
            name: google-secret
    EOF

    Review the following table to understand this configuration. For more information, see the API reference.

    SettingDescription
    ai.provider.geminiDefine the Gemini provider.
    gemini.modelThe model to use to generate responses. In this example, you use the gemini-2.5-flash-lite model. For more models, see the Google AI docs.
    policies.authThe authentication token to use to authenticate to the LLM provider. The example refers to the secret that you created in the previous step.
  4. Create an HTTPRoute resource that routes incoming traffic to the AgentgatewayBackend. The following example sets up a route. Note that agentgateway automatically rewrites the endpoint to the appropriate chat completion endpoint of the LLM provider for you, based on the LLM provider that you set up in the AgentgatewayBackend resource.

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: google
      namespace: agentgateway-system
    spec:
      parentRefs:
        - name: agentgateway-proxy
          namespace: agentgateway-system
      rules:
      - backendRefs:
        - name: google
          namespace: agentgateway-system
          group: agentgateway.dev
          kind: AgentgatewayBackend
    EOF
  5. Send a request to the LLM provider API along the route that you previously created. Verify that the request succeeds and that you get back a response from the API.

    Cloud Provider LoadBalancer:

    curl "$INGRESS_GW_ADDRESS/v1beta/openai/chat/completions" -H content-type:application/json  -d '{
      "model": "",
      "messages": [
       {"role": "user", "content": "Explain how AI works in simple terms."}
     ]
    }' | jq

    Localhost:

    curl "localhost:8080/v1beta/openai/chat/completions" -H content-type:application/json  -d '{
      "model": "",
      "messages": [
       {"role": "user", "content": "Explain how AI works in simple terms."}
     ]
    }' | jq

    Example output:

    {"id":"aGLEaMjbLp6p_uMPopeAoAc",
    "choices":
      [{"index":0,"message":{
          "content":"Imagine teaching a dog a trick.  You show it what to do, reward it when it's right, and correct it when it's wrong.  Eventually, the dog learns.\n\nAI is similar.  We \"teach\" computers by showing them lots of examples.  For example, to recognize cats in pictures, we show it thousands of pictures of cats, labeling each one \"cat.\"  The AI learns patterns in these pictures – things like pointy ears, whiskers, and furry bodies – and eventually, it can identify a cat in a new picture it's never seen before.\n\nThis learning process uses math and algorithms (like a secret code of instructions) to find patterns and make predictions.  Some AI is more like a dog learning tricks (learning from examples), and some is more like following a very detailed recipe (following pre-programmed rules).\n\nSo, in short: AI is about teaching computers to learn from data and make decisions or predictions, just like we teach dogs tricks.\n",
          "role":"assistant"
          },
       "finish_reason":"stop"
       }],
     "created":1757700714,
     "model":"gemini-1.5-flash-latest",
     "object":"chat.completion",
     "usage":{
         "prompt_tokens":8,
         "completion_tokens":205,
         "total_tokens":213
         }
    }

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. For the supported request content, see Decisions.

Create a separate AgentgatewayBackend and HTTPRoute for decision models, so that the google AgentgatewayBackend and route that you created earlier keep serving chat requests.

  1. Create a AgentgatewayBackend for the decision model.

    kubectl apply -f- <<EOF
    apiVersion: agentgateway.dev/v1alpha1
    kind: AgentgatewayBackend
    metadata:
      name: google-decisions
      namespace: agentgateway-system
    spec:
      ai:
        provider:
          gemini:
            model: gemini-decision-1
      policies:
        auth:
          secretRef:
            name: google-secret
        ai:
          routes:
            "/v1/decisions": "Decisions"
            "/v1/systemone": "SystemOne"
    EOF

    Review the following table to understand this configuration.

    SettingDescription
    gemini.modelA Gemini decision model, such as gemini-decision-1. Chat models do not answer Decisions requests. Agentgateway sends this name upstream and replaces the model value in the client request.
    policies.auth.secretRefThe Secret with your Gemini API key that you created earlier.
    policies.ai.routesMaps each request path to a request format. Requests to /v1/decisions use the Decisions format, and requests to /v1/systemone use the SystemOne format.
  2. Create an HTTPRoute that sends both request paths to the AgentgatewayBackend. The exact path matches take precedence over the prefix match of the google HTTPRoute, whichever tab you used to create it.

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: google-decisions
      namespace: agentgateway-system
    spec:
      parentRefs:
      - name: agentgateway-proxy
      rules:
      - backendRefs:
        - group: agentgateway.dev
          kind: AgentgatewayBackend
          name: google-decisions
        matches:
        - method: POST
          path:
            type: Exact
            value: /v1/decisions
        - method: POST
          path:
            type: Exact
            value: /v1/systemone
    EOF
  3. Send a Decisions request.

    Cloud Provider LoadBalancer:

    curl "$INGRESS_GW_ADDRESS/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

    Localhost:

    curl "localhost:8080/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, ...}
    }

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.

  1. Save the request body to a file.

    cat > structured-request.json <<'EOF'
    {
      "model": "",
      "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"]
          }
        }
      }
    }
    EOF
  2. Send the request. This example uses the path from the Gemini default tab. If you used another tab, change the path to match your HTTPRoute, such as /v1/chat/completions or /gemini.

    Cloud Provider LoadBalancer:

    curl "$INGRESS_GW_ADDRESS/v1beta/openai/chat/completions" -H content-type:application/json -d @structured-request.json | jq

    Localhost:

    curl "localhost:8080/v1beta/openai/chat/completions" -H content-type:application/json -d @structured-request.json | 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.

Next steps

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/.