kilocode icon indicating copy to clipboard operation
kilocode copied to clipboard

Gemini API requests fail with 401 Unauthorized due to incorrect Vertex AI endpoint usage

Open zemecom opened this issue 1 year ago • 4 comments

Description

When using the Kilo Code extension with the Gemini API, requests are failing with a 401 Unauthorized error. The root cause appears to be that the extension is incorrectly directing API calls to the Vertex AI endpoint instead of the standard Gemini API endpoint.

This is likely due to the isVertex parameter being hardcoded to true within the VertexHandler class, which then forces the use of Vertex AI authentication methods (OAuth2) rather than standard API keys.

Error Message

got status: 401 Unauthorized. {"error":{"message":"{\n \\"error\\": {\n \\"code\\": 401,\n \\"message\\": \\"API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal. See https://cloud.google.com/docs/authentication\\",\n \\"status\\": \\"UNAUTHENTICATED\\",\n \\"details\\": [\n {\n \\"@type\\": \\"type.googleapis.com/google.rpc.ErrorInfo\\",\n \\"reason\\": \\"CREDENTIALS_MISSING\\",\n \\"domain\\": \\"googleapis.com\\",\n \\"metadata\\": {\n \\"method\\": \\"google.cloud.aiplatform.v1beta1.PredictionService.StreamGenerateContent\\",\n \\"service\\": \\"aiplatform.googleapis.com\\"\n }\n }\n ]\n }\n}\n","code":401,"status":"Unauthorized"}}

Expected Behavior

When a user configures the extension to use the Gemini API with a standard API key, the extension should make requests to the correct Gemini API endpoint that accepts API key authentication.

Actual Behavior

The extension forces the use of the Vertex AI endpoint for Gemini API calls, causing authentication to fail when using a standard Gemini API key.

Steps to Reproduce

Configure the Kilo Code extension to use the Gemini API. Provide a valid Gemini API key. Attempt to use any feature that requires a call to the Gemini API. Observe the 401 Unauthorized error in the output or logs.

Environment

VS Code Version: 1.102.2 (Universal) Kilo Code Extension Version: 4.65.2 (529f813e) Operating System: macOS

zemecom avatar Jul 27 '25 15:07 zemecom

Can you send a screenshot of you API Provider settings?

chrarnoldus avatar Jul 31 '25 13:07 chrarnoldus

I have the same issue. I've configured my Gemini profiles with API keys from AI Studio, which worked fine. But suddenly, since a couple of days ago, I've been getting the same error. I've come to the same conclusion as OP that GOOGLE_GENAI_USE_VERTEXAI=true has probably been hardcoded in kilo code itself, since I've set my global env variable to false.

Would appreciate some guidance since not being able to use Gemini seriously hampers the effectiveness of my setup!

Image

MichaelRamirez043 avatar Aug 01 '25 08:08 MichaelRamirez043

Closing this one out since it's been inactive for a while — not because it's a bad issue, just that older items tend to lose context over time and we'd rather start fresh if this is still a problem.

Please feel free to reopen (or open a new issue) if you're still running into this. We're happy to take another look! 🙏

github-actions[bot] avatar Feb 24 '26 12:02 github-actions[bot]

Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project. { "name": "APIError", "data": { "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "statusCode": 401, "isRetryable": false, "responseHeaders": { "alt-svc": "h3=":443"; ma=2592000,h3-29=":443"; ma=2592000", "content-length": "637", "content-type": "text/event-stream", "date": "Wed, 24 Jun 2026 15:14:37 GMT", "server": "scaffolding on HTTPServer2", "server-timing": "gfet4t7; dur=66", "vary": "Origin, X-Origin, Referer", "www-authenticate": "Bearer realm="invalid_token"", "x-content-type-options": "nosniff", "x-frame-options": "SAMEORIGIN", "x-xss-protection": "0" }, "responseBody": "{\n "error": {\n "code": 401,\n "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",\n "status": "UNAUTHENTICATED",\n "details": [\n {\n "@type": "type.googleapis.com/google.rpc.ErrorInfo",\n "reason": "ACCESS_TOKEN_TYPE_UNSUPPORTED",\n "metadata": {\n "service": "generativelanguage.googleapis.com",\n "method": "google.ai.generativelanguage.v1beta.GenerativeService.StreamGenerateContent"\n }\n }\n ]\n }\n}\n", "metadata": { "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse" } } }

Same issue. New AQ. auth key format from Google AI Studio, getting 401 ACCESS_TOKEN_TYPE_UNSUPPORTED.

burak-imdat avatar Jun 24 '26 15:06 burak-imdat