Skip to content

[BUG] kagent does not use api key when using api key auth enabled Agentgateway #2129

Description

@Conor-Behard333

📋 Prerequisites

  • I have searched the existing issues to avoid creating a duplicate
  • By submitting this issue, you agree to follow our Code of Conduct
  • I am using the latest version of the software
  • I have tried to clear cache/cookies or used incognito mode (if ui-related)
  • I can consistently reproduce this issue

🎯 Affected Service(s)

Not Sure

🚦 Impact/Severity

Blocker

🐛 Bug Description

I have deployed agentgateway to act as a proxy between azure openai and kagent.

when there is no virtual key policies on the agent gateway it is able to talk to the azure openAI without any issues.

Once I add a agentgateway policy to force an api key to access the llm via the gateway kagent is unable to find the api key and use it in the request to the gateway.

🔄 Steps To Reproduce

  1. Deploy agentgateway
  2. Connect agentgateway to azure openai (https://agentgateway.dev/docs/kubernetes/latest/setup/gateway/)
  3. Add an api key via agentgateway policy (https://agentgateway.dev/docs/kubernetes/latest/llm/virtual-keys/)
  4. configure the model in kagent to use the agentgateway gateway
{
  "azureEndpoint": "https://agentgateway.local/",
  "apiVersion": "v1",
  "azureDeployment": "gpt-4.1-mini"
}
  1. add the api key from the agentgateway policy to the model config
  2. send a prompt to the llm via an agent using the model config

🤔 Expected Behavior

prompt should pass through the gateway and you should receive a response from the llm

📱 Actual Behavior

Agent responds with "api key authentication failure: no API Key found."

💻 Environment

  • kubernetes version: 1.35.0
  • provider: azure
  • app version: v0.9.11

🔧 CLI Bug Report

POST https://DOMAIN/openai/deployments/gpt-4.1-mini/chat/completions?api-version=v1 "HTTP/1.1 401 Unauthorized"

🔍 Additional Context

  • If I remove the auth policy on the agentgateway backend it will begin to work again
  • We have used other applications like gitlab duo and we have not had the same issue which indicates it is specifically an issue with kagent
  • I have shelled into the agent pod and ran:
env | grep AZURE

and the output of the base url and the api key are correct.

📋 Logs

📷 Screenshots

No response

🙋 Are you willing to contribute?

  • I am willing to submit a PR to fix this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions