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

Vertex AI

Verified : Automated tests passed for: Kubernetes resources: The Kubernetes resources on this page were checked against their API schemas.
Page as Markdown

Configure Google Vertex AI as an LLM provider for agentgateway.

Configure Vertex AI as an LLM provider in agentgateway.

Before you begin

Install and set up an agentgateway proxy.

Set up access to Vertex AI

  1. Set up authentication for Vertex AI. Make sure to have your:

    • Google Cloud Project ID
    • Project location, such as us-central1 (defaults to global if not specified)
    • API key or service account credentials
  2. Save your Vertex AI API key as an environment variable.

    export VERTEX_AI_API_KEY=<insert your API key>
  3. Create a Kubernetes secret to store your Vertex AI API key.

    kubectl apply -f- <<EOF
    apiVersion: v1
    kind: Secret
    metadata:
      name: vertex-ai-secret
      namespace: agentgateway-system
    type: Opaque
    stringData:
      Authorization: $VERTEX_AI_API_KEY
    EOF
  4. 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: vertex-ai
      namespace: agentgateway-system
    spec:
      ai:
        provider:
          vertexai:
            model: gemini-pro
            projectId: "my-gcp-project"
            region: "us-central1"
      policies:
        auth:
          secretRef:
            name: vertex-ai-secret
    EOF
  5. 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: vertex-ai
      namespace: agentgateway-system
    spec:
      parentRefs:
        - name: agentgateway-proxy
          namespace: agentgateway-system
      rules:
      - backendRefs:
        - name: vertex-ai
          namespace: agentgateway-system
          group: agentgateway.dev
          kind: AgentgatewayBackend
    EOF
  6. 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/v1/chat/completions" -H content-type:application/json  -d '{
       "model": "",
       "messages": [
         {
           "role": "user",
           "content": "Write me a short poem about Kubernetes and clouds."
         }
       ]
     }' | jq

    Localhost:

    curl "localhost:8080/v1/chat/completions" -H content-type:application/json  -d '{
       "model": "",
       "messages": [
         {
           "role": "user",
           "content": "Write me a short poem about Kubernetes and clouds."
         }
       ]
     }' | jq

    Example output:

    {
      "id": "chatcmpl-vertex-12345",
      "object": "chat.completion",
      "created": 1727967462,
      "model": "gemini-pro",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "In the cloud, Kubernetes reigns,\nOrchestrating pods with great care,\nContainers float like clouds,\nScaling up and down,\nAutomation everywhere."
          },
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 12,
        "completion_tokens": 28,
        "total_tokens": 40
      }
    }

Send file content by URI

In an OpenAI-compatible Chat Completions request, you can put a gs://, http://, or https:// URI in a file content part’s file_data or file_id. The request to Vertex AI uses fileData.

For HTTP(S) signed URLs, MIME type detection uses the extension before the query string or fragment. If the URI does not have a recognized extension, set filename, mime_type, or content_type on the file object.

Use the following request body with the route that you created.

{
  "model": "",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "Compare these documents." },
        {
          "type": "file",
          "file": {
            "file_id": "https://storage.googleapis.com/my-bucket/report.pdf?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Signature=abc"
          }
        },
        {
          "type": "file",
          "file": {
            "filename": "summary.pdf",
            "file_data": "https://example.com/download/123"
          }
        }
      ]
    }
  ]
}

Send images and files in Responses requests

For models other than Claude, agentgateway converts an OpenAI Responses request for Vertex AI to Chat Completions. Vertex AI 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. Vertex AI does not accept the original image detail, so the conversion changes detail: "original" to high.
  • 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. To send a file by gs:// or HTTPS URI, use a Chat Completions request instead, as described in Send file content by URI.

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. If you used the Custom route tab, change the path to /vertex.

    Cloud Provider LoadBalancer:

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

    Localhost:

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

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.

Filter Anthropic beta headers

Vertex AI rejects a Claude request if the anthropic-beta header contains a value that Vertex AI does not support. Clients such as Claude Code send several of these values. When a /v1/messages or /v1/messages/count_tokens request reaches a Claude model on Vertex AI, agentgateway removes the anthropic-beta values that are not on a built-in allowlist. The allowlist has the beta values that Vertex AI accepts, such as context-1m-2025-08-07 and interleaved-thinking-2025-05-14.

To change the allowlist, set the AGENTGATEWAY_VERTEX_ANTHROPIC_BETA_HEADERS environment variable on the proxy to a comma-separated list of beta values. The list replaces the built-in allowlist. Include the default value to keep the built-in allowlist and add to it.

The following steps create an AgentgatewayParameters resource and attach it to the gateway. If the gateway already refers to an AgentgatewayParameters resource, add the env entry from step 1 to that resource instead, and skip to step 3.

  1. Create an AgentgatewayParameters resource that sets the environment variable. The following example keeps the built-in allowlist and adds one beta value.

    kubectl apply -f- <<EOF
    apiVersion: agentgateway.dev/v1alpha1
    kind: AgentgatewayParameters
    metadata:
      name: vertex-anthropic-beta
      namespace: agentgateway-system
    spec:
      env:
      - name: AGENTGATEWAY_VERTEX_ANTHROPIC_BETA_HEADERS
        value: "default,my-new-beta-2026-12-01"
    EOF
  2. Attach the AgentgatewayParameters resource to the gateway. The proxy reads the variable when it starts, so the change takes effect when the proxy pods restart with the new setting.

    kubectl patch gateway agentgateway-proxy \
      --namespace agentgateway-system \
      --type merge \
      --patch '{"spec":{"infrastructure":{"parametersRef":{"group":"agentgateway.dev","kind":"AgentgatewayParameters","name":"vertex-anthropic-beta"}}}}'

    Example output:

    gateway.gateway.networking.k8s.io/agentgateway-proxy patched
  3. Confirm that the proxy deployment sets the variable.

    kubectl get deployment agentgateway-proxy \
      --namespace agentgateway-system \
      -o jsonpath='{.spec.template.spec.containers[?(@.name=="agentgateway")].env[?(@.name=="AGENTGATEWAY_VERTEX_ANTHROPIC_BETA_HEADERS")].value}'

    Example output:

    default,my-new-beta-2026-12-01

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