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.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
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>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 EOFCreate 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 EOFReview the following table to understand this configuration. For more information, see the API reference.
Setting Description ai.provider.geminiDefine the Gemini provider. gemini.modelThe model to use to generate responses. In this example, you use the gemini-2.5-flash-litemodel. 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. 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 EOFSend 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."} ] }' | jqLocalhost:
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."} ] }' | jqExample 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 family | reasoning_effort behavior |
|---|---|
| Gemini 2.5 and older | minimal, low, medium, high, xhigh, and max use thinkingBudget values. none omits thinkingConfig. |
| Gemini 3 | minimal, low, medium, high, xhigh, and max use thinkingLevel. none omits thinkingConfig. |
| Gemini 4 | minimal 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.
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" EOFReview the following table to understand this configuration.
Setting Description gemini.modelA Gemini decision model, such as gemini-decision-1. Chat models do not answer Decisions requests. Agentgateway sends this name upstream and replaces themodelvalue 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/decisionsuse the Decisions format, and requests to/v1/systemoneuse the SystemOne format.Create an HTTPRoute that sends both request paths to the AgentgatewayBackend. The exact path matches take precedence over the prefix match of the
googleHTTPRoute, 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 EOFSend 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?"}] }' | jqLocalhost:
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?"}] }' | jqExample 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.
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"] } } } } EOFSend 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/completionsor/gemini.Cloud Provider LoadBalancer:
curl "$INGRESS_GW_ADDRESS/v1beta/openai/chat/completions" -H content-type:application/json -d @structured-request.json | jqLocalhost:
curl "localhost:8080/v1beta/openai/chat/completions" -H content-type:application/json -d @structured-request.json | jqExample output, in which
contentis 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_imagepart must setimage_url. - An
input_filepart must carry the file as a base64 data URL, such asdata:application/pdf;base64,<base64>, infile_dataorfile_url. Thefilenameis 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.