-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
google-vertexai model authentication error - throw new Error("APIs that require a project ID cannot use an API key") #5000
Comments
The error message you're encountering suggests that the authentication method being used is not correctly providing a project ID in a manner expected by Google Cloud services, specifically Vertex AI. The error message implies that an API key is being used or the system believes one is being used, which is not supported for the APIs requiring a project ID. Given the context of the
To resolve the authentication error, ensure the following:
If after these steps the issue persists, it might be helpful to explicitly log or inspect the authentication configuration at runtime to ensure that the expected values are being used and that the Regarding the I hope this helps! If you have any further questions or if the issue persists, please provide more details about your setup and the steps you've taken so far. Sources
|
How about comment out GOOGLE_API_KEY in your env file? |
What @sessycode said - Are you using or setting (That said, it might make sense for the library to ignore API key completely if we're in Vertex AI mode. But I thought it did.) |
Note of thanks to this thread... I had the same error because I had |
definitely it makes a huge sense for the library to ignore API key completely if we're in Vertex AI mode... |
Coincidentally, I have a fix for this in progress. |
Great! I hope it'll merged soon |
Checked other resources
Example Code
I'm using the following version of the libraries on node version V21.7.2
just trying to initialize the VertexAI and invoke the model, and getting the following error message.
`import { VertexAI } from "@langchain/google-vertexai";
const model = new VertexAI({
authOptions: {
credentials: {
type: "service_account",
project_id: "",
private_key_id: "",
private_key: "",
client_email: "",
client_id: "",
auth_uri: "",
token_uri: "",
auth_provider_x509_cert_url: "",
client_x509_cert_url: "",
universe_domain: "",
},
},
});
const res = await model.invoke(
"What does google gemini do?"
);
console.log({ res });
`
Up that i get the following error node_modules/@langchain/google-common/dist/auth.js:51
throw new Error("APIs that require a project ID cannot use an API key");
also, when i traced to implementation it seems like getProjectId() is implemented to throw this error
Question: I tried all the 4 ways to initilize the model to provide the auth details listed at https://js.langchain.com/docs/integrations/llms/google_vertex_ai but all of them resolved the same error
Please advice
export class ApiKeyGoogleAuth extends GoogleAbstractedFetchClient {
constructor(apiKey) {
super();
Object.defineProperty(this, "apiKey", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.apiKey = apiKey;
}
get clientType() {
return "apiKey";
}
getProjectId() {
throw new Error("APIs that require a project ID cannot use an API key");
// Perhaps we could implement this if needed:
// https://cloud.google.com/docs/authentication/api-keys#get-info
}
request(opts) {
const authHeader = {
"X-Goog-Api-Key": this.apiKey,
};
return this._request(opts.url, opts, authHeader);
}
}
Error Message and Stack Trace (if applicable)
Error: APIs that require a project ID cannot use an API key
at ApiKeyGoogleAuth.getProjectId (file:///Users/mohanganesh/projects/ai/mono-ai-vertex/ping-vertex/node_modules/@langchain/google-common/dist/auth.js:51:15)
at ChatConnection.buildUrlVertex (file:///Users/mohanganesh/projects/ai/mono-ai-vertex/ping-vertex/node_modules/@langchain/google-common/dist/connection.js:166:45)
at ChatConnection.buildUrl (file:///Users/mohanganesh/projects/ai/mono-ai-vertex/ping-vertex/node_modules/@langchain/google-common/dist/connection.js:176:29)
at ChatConnection._request (file:///Users/mohanganesh/projects/ai/mono-ai-vertex/ping-vertex/node_modules/@langchain/google-common/dist/connection.js:48:32)
at ChatConnection.request (file:///Users/mohanganesh/projects/ai/mono-ai-vertex/ping-vertex/node_modules/@langchain/google-common/dist/connection.js:181:37)
at ProxyChatGoogle._streamResponseChunks (file:///Users/mohanganesh/projects/ai/mono-ai-vertex/ping-vertex/node_modules/@langchain/google-common/dist/chat_models.js:144:56)
at _streamResponseChunks.next ()
at ProxyChatGoogle._streamIterator (file:///Users/mohanganesh/projects/ai/mono-ai-vertex/ping-vertex/node_modules/@langchain/core/dist/language_models/chat_models.js:78:34)
at async VertexAI._streamIterator (file:///Users/mohanganesh/projects/ai/mono-ai-vertex/ping-vertex/node_modules/@langchain/google-common/dist/llms.js:180:30)
at async VertexAI.invoke (file:///Users/mohanganesh/projects/ai/mono-ai-vertex/ping-vertex/node_modules/@langchain/google-common/dist/llms.js:220:26)
Description
System Info
I have tried on mac, also in a container and results were same.
The text was updated successfully, but these errors were encountered: