Skip to content

Conversation

@leehack
Copy link

@leehack leehack commented Jan 23, 2026

Summary

Adds a new google-vertex-openapi provider that enables using third-party models (like GLM-4.7) on Google Vertex AI through the OpenAPI-compatible endpoint.

Fixes #10304

Changes

Provider Implementation (src/provider/provider.ts):

  • Replaced gcloud CLI subprocess approach with Application Default Credentials (ADC) using google-auth-library
    • No subprocess overhead (performance improvement)
    • Automatic token refresh (handled by library)
    • Supports multiple credential sources (gcloud ADC, service account, etc.)
  • Added getModel function for consistency with other providers

Test Infrastructure (test/provider/provider.test.ts):

  • Mocked google-auth-library for testing support

  • Configuration:

    • Environment variables: GOOGLE_CLOUD_PROJECT, GCP_PROJECT, GCLOUD_PROJECT (project)
    • Environment variables: GOOGLE_CLOUD_LOCATION, VERTEX_LOCATION (location)
    • Config options: provider.options.project, provider.options.location
  • Authentication:

    • Works with gcloud auth application-default login (easiest for development)
    • Supports GOOGLE_APPLICATION_CREDENTIALS for service accounts (production)

Verification

  • Typecheck: Passed
  • Tests: All passing (pre-existing failures unaffected)
  • Manual testing: Can configure provider and make requests to Vertex AI OpenAPI endpoint

Usage

{
  "provider": {
    "google-vertex-openapi": {
      "name": "Google Vertex AI (OpenAPI)",
      "npm": "@ai-sdk/openai-compatible",
      "api": "https://aiplatform.googleapis.com/v1beta1",
      "options": {
        "project": "my-project-id",
        "location": "global"
      },
      "models": {
        "glm-4.7": {
          "name": "GLM-4.7",
          "tool_call": true,
          "reasoning": true,
          "limit": {"context": 128000, "output": 8192}
        }
      }
    }
  }
}

Setup

# Using gcloud ADC (recommended for development)
gcloud auth application-default login
export GOOGLE_CLOUD_PROJECT=my-project-id

# OR using service account (recommended for production)
export GOOGLE_APPLICATION_CREDENTIALS=~/.config/google/vertex-ai-service-account.json
export GOOGLE_CLOUD_PROJECT=my-project-id

@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found:

The other Google Vertex-related PRs (#9568, #6860, #5422, #5166) appear to be focused on different aspects (model resolution, token stats, cache configuration, naming conventions) rather than authentication implementation.

@NimaAra
Copy link

NimaAra commented Jan 29, 2026

Can we get this merged please?

@bluet
Copy link

bluet commented Jan 30, 2026

Hey @leehack, great work on this! I was working on a similar solution (now closed #10742) and your approach of extending the existing google-vertex provider with protocol: "openapi" is cleaner than creating a separate provider.

I've also been coordinating with @rekram1-node on models.dev PR #716 for the model definitions. He mentioned consolidating all google-vertex models under a single provider, which aligns perfectly with your implementation here.

Happy to help test this PR if needed - I have a GCP project with GLM-4.7 access via Vertex AI Model Garden.

One small observation: The baseURL uses v1beta1 - just confirming this works with the OpenAPI-compatible endpoint? In my testing, I was using v1 for partner models. Let me know if you'd like me to verify.

@leehack
Copy link
Author

leehack commented Jan 30, 2026

Hey @leehack, great work on this! I was working on a similar solution (now closed #10742) and your approach of extending the existing google-vertex provider with protocol: "openapi" is cleaner than creating a separate provider.

I've also been coordinating with @rekram1-node on models.dev PR #716 for the model definitions. He mentioned consolidating all google-vertex models under a single provider, which aligns perfectly with your implementation here.

Happy to help test this PR if needed - I have a GCP project with GLM-4.7 access via Vertex AI Model Garden.

One small observation: The baseURL uses v1beta1 - just confirming this works with the OpenAPI-compatible endpoint? In my testing, I was using v1 for partner models. Let me know if you'd like me to verify.

Awesome!
Yes, I'm testing with the glm 4.7 model with the Vertex AI model Garden. I've only tested glm 4.7 with the v1beta1 endpoint. Feel free to test and let me know if you think we should better use the v1 endpoint.

@bluet
Copy link

bluet commented Feb 2, 2026

Test Results: v1 vs v1beta1 Endpoints

I tested both API versions with GLM-4.7. Both work!

Results

Endpoint Status
/v1/.../openapi/chat/completions ✅ Works
/v1beta1/.../openapi/chat/completions ✅ Works

Conclusion

Your current implementation using v1beta1 is fine - both versions work identically for the OpenAPI-compatible endpoint. No changes needed.

The correct model ID format is <publisher>/<model-id>, e.g., zai-org/glm-4.7-maas.

Documentation Reference

@bluet
Copy link

bluet commented Feb 2, 2026

Follow-up: Recommendation to use /v1/ instead of /v1beta1/

After researching Google's API versioning policy, I'd suggest using /v1/ instead of /v1beta1/ for better production stability.

Why /v1/ is preferable:

Aspect /v1/ (Stable) /v1beta1/ (Beta)
SLA ✅ Covered ❌ No guarantees
Breaking Changes ❌ Not allowed ⚠️ Allowed after deprecation
Deprecation Notice Min 1 year ~180 days (not guaranteed)
Production Use ✅ Recommended ⚠️ Test environments

Reference: Google's Official Policy

From AIP-181 and Google Cloud Launch Stages:

  • Beta: No SLAs or technical support obligations unless specified
  • Stable (v1): Fully-supported, covered by SLA, no breaking changes

Suggested Change

In the loader's baseURL construction:

- `https://${location}-aiplatform.googleapis.com/v1beta1/projects/...`
+ `https://${location}-aiplatform.googleapis.com/v1/projects/...`

Both work identically for the OpenAPI-compatible endpoint (I tested both), but /v1/ provides stronger stability guarantees for production use.

Copy link

@bluet bluet left a comment

Choose a reason for hiding this comment

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

according to google vertex docs, /v1beta1/ url path is for beta testing purpose. better to use /v1/ for stability.

location,
baseURL:
location === "global"
? `https://aiplatform.googleapis.com/v1beta1/projects/${project}/locations/${location}/endpoints/openapi`
Copy link

Choose a reason for hiding this comment

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

Suggested change
? `https://aiplatform.googleapis.com/v1beta1/projects/${project}/locations/${location}/endpoints/openapi`
? `https://aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/endpoints/openapi`

baseURL:
location === "global"
? `https://aiplatform.googleapis.com/v1beta1/projects/${project}/locations/${location}/endpoints/openapi`
: `https://${location}-aiplatform.googleapis.com/v1beta1/projects/${project}/locations/${location}/endpoints/openapi`,
Copy link

Choose a reason for hiding this comment

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

Suggested change
: `https://${location}-aiplatform.googleapis.com/v1beta1/projects/${project}/locations/${location}/endpoints/openapi`,
: `https://${location}-aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/endpoints/openapi`,

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add google-vertex-openapi provider for third-party models (GLM)

3 participants