genkit icon indicating copy to clipboard operation
genkit copied to clipboard

Bug: googleAI model configuration ignores custom baseUrl for Cloud Run deployed models

Open Gopinathp opened this issue 7 months ago • 0 comments

Description

When using a model deployed on Google Cloud Run with genkit, the googleAI provider seems to ignore the custom baseUrl provided in the model configuration. Instead of sending requests to the specified Cloud Run endpoint, it defaults to generativelanguage.googleapis.com.

This causes an authentication failure because the API key is valid for the custom Cloud Run service, not the standard Google Generative AI API.

This issue prevents the use of custom models deployed via Cloud Run with Genkit.

Steps to Reproduce

  1. Deploy a generative model (e.g., Gemma) to Google Cloud Run. This will provide a unique baseUrl and an apiKey.
  2. In a Genkit project, configure a model using @genkit-ai/googleai and provide the baseUrl and apiKey from the Cloud Run deployment.
  3. Attempt to generate content using the configured model.
  4. Observe the error in the console.

Expected Behavior

Genkit should make the API request to the baseUrl specified in the model's configuration.

Actual Behavior

Genkit ignores the baseUrl and sends the request to the default Google AI endpoint (https://generativelanguage.googleapis.com/v1beta/models/gemma-3-27b-it:generateContent). This results in a 400 Bad Request error with the message "API key not valid".

Error Log:

[genkit] Error[generate, Error] [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemma-3-27b-it:generateContent: [400 Bad Request] API key not valid. Please pass a valid API key. [{"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"API_KEY_INVALID","domain":"googleapis.com","metadata":{"service":"generativelanguage.googleapis.com"}},{"@type":"type.googleapis.com/google.rpc.LocalizedMessage","locale":"en-US","message":"API key not valid. Please pass a valid API key."}] Error: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemma-3-27b-it:generateContent: [400 Bad Request] API key not valid. Please pass a valid API key. [{"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"API_KEY_INVALID","domain":"googleapis.com","metadata":{"service":"generativelanguage.googleapis.com"}},{"@type":"type.googleapis.com/google.rpc.LocalizedMessage","locale":"en-US","message":"API key not valid. Please pass a valid API key."}]
    at handleResponseNotOk (/workspace/node_modules/@google/generative-ai/dist/index.js:434:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async makeRequest (/workspace/node_modules/@google/generative-ai/dist/index.js:403:9)
    at async generateContent (/workspace/node_modules/@google/generative-ai/dist/index.js:867:22)
    at async ChatSession.sendMessage (/workspace/node_modules/@google/generative-ai/dist/index.js:1210:9)
    at async callGemini (/workspace/node_modules/@genkit-ai/googleai/lib/gemini.js:932:26)
    at async /workspace/node_modules/@genkit-ai/googleai/lib/gemini.js:974:28
    at async /workspace/node_modules/@genkit-ai/core/lib/tracing/instrumentation.js:88:24
    at async runInNewSpan (/workspace/node_modules/@genkit-ai/core/lib/tracing/instrumentation.js:77:10)
    at async /workspace/node_modules/@genkit-ai/googleai/lib/gemini.js:958:28

Environment

  • @genkit-ai/core
  • @genkit-ai/googleai

Gopinathp avatar Jun 16 '25 02:06 Gopinathp