Skip to content

Conversation

@what-is-thy-bidding
Copy link

@what-is-thy-bidding what-is-thy-bidding commented Dec 1, 2025

Why

When using custom endpoints (proxy servers) that implement the Vertex AI API format, users currently MUST provide Google Cloud credentials even though these credentials are never used for actual authentication. The custom endpoints (proxy servers) handle their own authentication (e.g., via Bearer tokens).

The credentials are stored on that proxy server and not on the client's machine locally.

This creates unnecessary friction:

  • Users must obtain a real GCP service account JSON file
  • Must set GOOGLE_APPLICATION_CREDENTIALS environment variable
  • Must provide valid project/location values
  • All of this just to initialize the SDK, even though the custom endpoint ignores these credentials entirely

Solution

Added a new `skipAuth` option to `HttpOptions` that allows users to:

  • Skip Google Cloud credential validation and loading
  • Skip project/location requirement checks
  • Bypass GoogleAuth initialization entirely
  • Skip prepending `projects/{project}/locations/{location}/` to URL paths

When `skipAuth: true`:

  1. node_client.ts skips reading env vars and validation
  2. _node_auth.ts skips GoogleAuth initialization
  3. No auth headers are added (custom endpoint handles auth via httpOptions.headers)
  4. _api_client.ts skips prepending `projects/{project}/locations/{location}/` to request paths

Why skip prependProjectLocation?

Normal Vertex AI URLs look like:
https://us-central1-aiplatform.googleapis.com/v1/projects/my-project/locations/us-central1/publishers/google/models/gemini:generateContent

Custom endpoint URLs should look like:
https://custom-endpoint.com/v1/publishers/google/models/gemini:generateContent

When `skipAuth` is set:

  • Custom endpoints don't expect the `projects/{project}/locations/{location}/` path prefix
  • With `skipAuth`, we likely don't have valid project/location values anyway (they'd be `undefined`)
  • The custom endpoint handles its own routing and doesn't need GCP resource paths

Changes

  • src/types.ts: Added `skipAuth?: boolean` to HttpOptions interface
  • src/node/_node_auth.ts: Skip GoogleAuth init when skipAuth is true
  • src/_api_client.ts: Skip project/location path prepending when skipAuth is true
  • src/node/node_client.ts: Conditional env var loading based on skipAuth

Example Usage

Before (requires REAL Google Cloud credentials):

// Step 1: Must have a real GCP service account JSON file
// Step 2: Set environment variable
process.env.GOOGLE_APPLICATION_CREDENTIALS = './service_account.json';

// Step 3: Initialize SDK (GoogleAuth tries to load credentials)
const ai = new GoogleGenAI({
  vertexai: true,
  project: 'my-gcp-project',      // Required even though never used
  location: 'us-central1',         // Required even though never used
  httpOptions: {
    baseUrl: 'https://custom-endpoint.example.com/v1/',
    headers: { 'Authorization': 'Bearer MY_CUSTOM_TOKEN' },
  },
});

// Without GOOGLE_APPLICATION_CREDENTIALS: Error - Could not load credentials
// URL would be: .../projects/my-gcp-project/locations/us-central1/publishers/... (won't work, because the location and project name isn't stored on the client's machine but on the proxy-server)

After (no Google Cloud setup needed):

// No service account file needed!
// No GOOGLE_APPLICATION_CREDENTIALS needed!
// No project/location needed!

const ai = new GoogleGenAI({
  vertexai: true,
  httpOptions: {
    baseUrl: 'https://custom-endpoint-proxy-server.com/v1/',
    headers: { 'Authorization': 'Bearer MY_CUSTOM_TOKEN' },
    skipAuth: true,  // Skip all Google Cloud authentication
  },
});

// URL will be: .../publishers/google/models/gemini:generateContent

This brings the TypeScript SDK in line with the Python SDK's behavior, where custom http_options automatically bypass Google Cloud authentication.

@google-cla
Copy link

google-cla bot commented Dec 1, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

…redentials

## Why
When using custom endpoints that implement the Vertex AI API format,
users currently must provide Google Cloud credentials even though
these credentials are never used for actual authentication. The custom
endpoint handles its own authentication (e.g., via Bearer tokens).

This creates unnecessary friction:
- Users must obtain a real GCP service account JSON file
- Must set GOOGLE_APPLICATION_CREDENTIALS environment variable
- Must provide valid project/location values
- All of this just to initialize the SDK, even though the custom
  endpoint ignores these credentials entirely

## Solution
Added a new `skipAuth` option to `HttpOptions` that allows users to:
- Skip Google Cloud credential validation and loading
- Skip project/location requirement checks
- Bypass GoogleAuth initialization entirely

When `skipAuth: true`:
1. node_client.ts skips reading env vars and validation
2. _node_auth.ts skips GoogleAuth initialization
3. No auth headers are added (custom endpoint handles auth via httpOptions.headers)

## Changes
- src/types.ts: Added `skipAuth?: boolean` to HttpOptions interface
- src/node/_node_auth.ts: Skip GoogleAuth init when skipAuth is true
- src/node/node_client.ts: Conditional env var loading based on skipAuth

## Example Usage

### Before (requires REAL Google Cloud credentials):
```typescript
// Step 1: Must have a real GCP service account JSON file
// Step 2: Set environment variable
process.env.GOOGLE_APPLICATION_CREDENTIALS = './service_account.json';

// Step 3: Initialize SDK (GoogleAuth tries to load credentials)
const ai = new GoogleGenAI({
  vertexai: true,
  project: 'my-gcp-project',      // Required even though never used
  location: 'us-central1',         // Required even though never used
  httpOptions: {
    baseUrl: 'https://custom-endpoint.example.com/v1/',
    headers: { 'Authorization': 'Bearer MY_CUSTOM_TOKEN' },
  },
});
// Without GOOGLE_APPLICATION_CREDENTIALS: Error - Could not load credentials
```

### After (no Google Cloud setup needed):
```typescript
// No service account file needed!
// No GOOGLE_APPLICATION_CREDENTIALS needed!
// No project/location needed!

const ai = new GoogleGenAI({
  vertexai: true,
  httpOptions: {
    baseUrl: 'https://custom-endpoint.example.com/v1/',
    headers: { 'Authorization': 'Bearer MY_CUSTOM_TOKEN' },
    skipAuth: true,  // Skip all Google Cloud authentication
  },
});
```

This brings the TypeScript SDK in line with the Python SDK's behavior,
where custom http_options automatically bypass Google Cloud authentication.
When using a custom baseUrl that is not aiplatform.googleapis.com,
the SDK should not prepend projects/{project}/locations/{location}
to the request paths.

This allows custom Vertex AI-compatible endpoints to work without
needing to provide dummy project/location values.

Changes:
- src/_api_client.ts: Check for custom baseUrl in shouldPrependVertexProjectPath
- api-report/*.md: Updated API signatures for skipAuth feature

This complements the skipAuth feature to provide a complete solution
for using custom endpoints without Google Cloud configuration.
@what-is-thy-bidding what-is-thy-bidding marked this pull request as draft December 1, 2025 22:02
Merged two separate if (!skipAuth) blocks into one for better
code organization and readability. All validation and env var
loading now happens in a single conditional block.

No functional changes - all 435 unit tests still passing.
Added validation to ensure skipAuth can only be used with a custom
baseUrl. Using skipAuth without baseUrl would be invalid since it
would attempt to call Google's servers without authentication.
Added skipAuth check to shouldPrependVertexProjectPath() to ensure
project/location path is not prepended when using skipAuth mode.
dist-temp was accidentally committed. Removed from tracking and
added to .gitignore to prevent future accidental commits.
Handle the simple skipAuth case first, then proceed with the
more complex validation and env var loading logic.
- Removed duplicate assignments by using conditional env var loading
- env vars are undefined when skipAuth, so single ?? assignment works for both cases
- Flattened nested if/else structure
Validation should happen first - fail fast before setting any state.
Removed the baseUrl.includes('aiplatform.googleapis.com') check.
Users with custom URLs are expected to set skipAuth explicitly.
## Why

When using custom endpoints (proxy servers) that implement the Vertex AI API format, users currently MUST provide Google Cloud credentials even though these credentials are never used for actual authentication. The custom endpoints (proxy servers) handle their own authentication (e.g., via Bearer tokens).

The credentials are stored on that proxy server and not on the client's machine locally.

This creates unnecessary friction:

- Users must obtain a real GCP service account JSON file
- Must set GOOGLE_APPLICATION_CREDENTIALS environment variable
- Must provide valid project/location values
- All of this just to initialize the SDK, even though the custom endpoint ignores these credentials entirely

## Solution

Added a new `skipAuth` option to `HttpOptions` that allows users to:

- Skip Google Cloud credential validation and loading
- Skip project/location requirement checks
- Bypass GoogleAuth initialization entirely
- Skip prepending `projects/{project}/locations/{location}/` to URL paths

When `skipAuth: true`:

1. node_client.ts skips reading env vars and validation
2. _node_auth.ts skips GoogleAuth initialization
3. No auth headers are added (custom endpoint handles auth via httpOptions.headers)
4. _api_client.ts skips prepending `projects/{project}/locations/{location}/` to request paths

### Why skip prependProjectLocation?

Normal Vertex AI URLs look like:
```
https://us-central1-aiplatform.googleapis.com/v1beta1/projects/my-project/locations/us-central1/publishers/google/models/gemini:generateContent
```

Custom endpoint URLs should look like:
```
https://custom-endpoint.com/v1/publishers/google/models/gemini:generateContent
```

When `skipAuth` is set:
- Custom endpoints don't expect the `projects/{project}/locations/{location}/` path prefix
- With `skipAuth`, we likely don't have valid project/location values anyway (they'd be `undefined`)
- The custom endpoint handles its own routing and doesn't need GCP resource paths

## Changes

- src/types.ts: Added `skipAuth?: boolean` to HttpOptions interface
- src/node/_node_auth.ts: Skip GoogleAuth init when skipAuth is true
- src/node/node_client.ts: Conditional env var loading based on skipAuth
- src/_api_client.ts: Skip project/location path prepending when skipAuth is true

## Example Usage

### Before (requires REAL Google Cloud credentials):

```typescript
// Step 1: Must have a real GCP service account JSON file
// Step 2: Set environment variable
process.env.GOOGLE_APPLICATION_CREDENTIALS = './service_account.json';

// Step 3: Initialize SDK (GoogleAuth tries to load credentials)
const ai = new GoogleGenAI({
  vertexai: true,
  project: 'my-gcp-project',      // Required even though never used
  location: 'us-central1',         // Required even though never used
  httpOptions: {
    baseUrl: 'https://custom-endpoint.example.com/v1/',
    headers: { 'Authorization': 'Bearer MY_CUSTOM_TOKEN' },
  },
});

// Without GOOGLE_APPLICATION_CREDENTIALS: Error - Could not load credentials
// URL would be: .../projects/my-gcp-project/locations/us-central1/publishers/... (wrong!)
```

### After (no Google Cloud setup needed):

```typescript
// No service account file needed!
// No GOOGLE_APPLICATION_CREDENTIALS needed!
// No project/location needed!

const ai = new GoogleGenAI({
  vertexai: true,
  httpOptions: {
    baseUrl: 'https://custom-endpoint-proxy-server.com/v1/',
    apiVersion: '',  // Empty if baseUrl already includes version
    headers: { 'Authorization': 'Bearer MY_CUSTOM_TOKEN' },
    skipAuth: true,  // Skip all Google Cloud authentication
  },
});

// URL will be: .../publishers/google/models/gemini:generateContent (correct!)
```

This brings the TypeScript SDK in line with the Python SDK's behavior, where custom http_options automatically bypass Google Cloud authentication.
@what-is-thy-bidding what-is-thy-bidding marked this pull request as ready for review December 2, 2025 17:31
Comment on lines +319 to +322
// If skipAuth is set, don't prepend project/location path
if (this.clientOptions.httpOptions?.skipAuth) {
return false;
}
Copy link
Author

@what-is-thy-bidding what-is-thy-bidding Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project name and the location shouldn't be available on the client's local machine when using a proxy server. Those details are stored in the proxy server

Hence shouldn't be prepended to the final url

Comment on lines +92 to +96
if (skipAuth && !options.httpOptions?.baseUrl) {
throw new Error(
'skipAuth requires a baseUrl to be provided in httpOptions.',
);
}
Copy link
Author

@what-is-thy-bidding what-is-thy-bidding Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will force skipAuth to ONLY be used when using a baseUrl set by the client and not the default base url set by the SDK

Added tests for:
- node_client.ts: skipAuth validation, env var skipping, value handling
- _node_auth.ts: skipAuth header behavior, googleAuth initialization skip
- _api_client.ts: shouldPrependVertexProjectPath with skipAuth

10 new tests, all passing (445 total specs)
@shmishra99 shmishra99 self-assigned this Dec 3, 2025
@shmishra99 shmishra99 added api: vertex-ai Issues related to the Vertex AI API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Dec 3, 2025
@what-is-thy-bidding
Copy link
Author

@shmishra99 : is there an update on this feature request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: vertex-ai Issues related to the Vertex AI API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants