Global location generates invalid request endpoint
type: bugpriority: p2
#### Environment details
- Programming language: Typescript
- OS: Mac/Linux
- Language runtime version: v20.12.2
- Package version: v1.10.0
#### Steps to reproduce
1. Use the package to make a call to generateContent() with standard config/params with the global endpoint
2. Observe 404 Not Found exception
Code Example:
```
this.vertexAi = new VertexAI({
project: <project_id>
location: 'global',
...
});
const generativeModel = this.vertexAi.getGenerativeModel({
model: 'gemini-2.5-flash-lite-preview-06-17',
generationConfig: {
...
});
const result = await generativeModel.generateContent(requestString);
```
Upon making a call to Vertex using `generateContent()` for a model only supported in `global` (for example gemini-2.5-flash-lite-preview-06-17), the call will fail due to an invalid base URL resolution.
When `apiEndpoint` is not configured when initializing `VertexAI`, the [following code](https://github.com/googleapis/nodejs-vertexai/blob/main/src/functions/post_request.ts#L58) will prepend `region` to the base path. This will resolve to `https://global-aiplatform.googleapis.com/v1/projects...` which is not a valid URL and will generate a 404 Not Found upon making the request.
Additionally, the library does not fail gracefully when hitting this issue. It throws the following exception back to the client:
```
Unexpected token '<', "<!DOCTYPE "... is not valid JSON
```
instead of an exception describing the problem, thus making debugging significantly more difficult. This is due to the [linked code](https://github.com/googleapis/nodejs-vertexai/blob/main/src/functions/post_fetch_processing.ts#L42) calling `JSON.parse()` when the response stream format is an HTML document instead of valid JSON.
0 条评论