Bug: googleAI model configuration ignores custom baseUrl for Cloud Run deployed models
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
- Deploy a generative model (e.g., Gemma) to Google Cloud Run. This will provide a unique
baseUrland anapiKey. - In a Genkit project, configure a model using
@genkit-ai/googleaiand provide thebaseUrlandapiKeyfrom the Cloud Run deployment. - Attempt to generate content using the configured model.
- 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