Skip to content

feat: add openai-compatible endpoint support for google-vertex provider#10303

Merged
rekram1-node merged 18 commits intoanomalyco:devfrom
leehack:fix/vertex-glm-openapi
Feb 16, 2026
Merged

feat: add openai-compatible endpoint support for google-vertex provider#10303
rekram1-node merged 18 commits intoanomalyco:devfrom
leehack:fix/vertex-glm-openapi

Conversation

@leehack
Copy link
Contributor

@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
Contributor

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
Contributor 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
Contributor

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
Contributor

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
Contributor

@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.

Co-authored-by: BlueT - Matthew Lien - 練喆明 <BlueT@BlueT.org>
@leehack
Copy link
Contributor Author

leehack commented Feb 3, 2026

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

Thanks @bluet for the test and suggestion. I updated the url as you suggested.

@leehack
Copy link
Contributor Author

leehack commented Feb 3, 2026

Fixed the test failures and ensured compatibility with proxy servers.

@NimaAra
Copy link

NimaAra commented Feb 5, 2026

Is this ever going to be merged?

@leehack
Copy link
Contributor Author

leehack commented Feb 6, 2026

Is this ever going to be merged?

I'm also waiting; I'm currently running my own local build just for this. lol

@rekram1-node
Copy link
Collaborator

rekram1-node commented Feb 11, 2026

So this introduces a new "protocol" field which seems like it is used to set the npm package.

But we already have fields to set the npm package any model can have it's own npm package setting regardless of the provider default

@klinki
Copy link

klinki commented Feb 12, 2026

I would also love this to get merged and new version with this released. It's blocking me from using Google Vertex API as well.

@leehack
Copy link
Contributor Author

leehack commented Feb 12, 2026

So this introduces a new "protocol" field which seems like it is used to set the npm package.

But we already have fields to set the npm package any model can have it's own npm package setting regardless of the provider default

Yep. we can use provider.npm instead. I removed protocol field.

Here is the example for a model:

"google-vertex": {
	"options": {
		"project": "gcp-project-id",
		"location": "global"
	},
	"models": {
		"zai-org/glm-4.7-maas": {
			"name": "GLM-4.7",
			"provider": { "npm": "@ai-sdk/openai-compatible", "api": "" },
			"limit": { "context": 204800, "output": 131072 },
			"cost": { "input": 0.6, "output": 2.2 },
			"interleaved": {
				"field": "reasoning_content"
			},
			"attachment": false,
			"reasoning": true,
			"family": "glm",
			"temperature": true,
			"tool_call": true,
			"modalities": {
				"input": [ "text" ],
				"output": [ "text" ]
			},
			"release_date": "2025-12-22",
		}
	}
},

@leehack leehack changed the title feat: add google-vertex-openapi provider with ADC authentication feat: add openai-compatible endpoint support for google-vertex provider Feb 12, 2026
@leehack
Copy link
Contributor Author

leehack commented Feb 12, 2026

@rekram1-node cleaned up the PR. removed all useless codes, mocks, tests and comments. rebased dev branch. Hope this is good now.

@ddesmond
Copy link

merge train hype cho cho cho! thumbs up and thanks for this work! :) 🚂

@rekram1-node
Copy link
Collaborator

rekram1-node commented Feb 16, 2026

This is also gonna be combined w/ changes in models.dev we will have things like this:

"google-vertex": {
      "options": {},
      "models": {
        "zai-org/glm-5-maas": {
          "provider": {
            "npm": "@ai-sdk/openai-compatible",
            "api": "https://${GOOGLE_VERTEX_ENDPOINT}/v1/projects/${GOOGLE_CLOUD_PROJECT}/locations/${GOOGLE_VERTEX_LOCATION}/endpoints/openapi",
          },
        },
      },
    },

Note that this is existing we just have to introduce this env var resolution pattern, and this ofc could be cleaned up a bit but the idea here is that models dont have to be tied to the provider base url, models can have their own package and own api = "base url"

@rekram1-node rekram1-node merged commit f7708ef into anomalyco:dev Feb 16, 2026
6 checks passed
sergiu-svinarciuc pushed a commit to sergiu-svinarciuc/opencode that referenced this pull request Feb 16, 2026
* dev: (1474 commits)
  fixing merge issue
  fix: google vertex var priority (anomalyco#13816)
  chore: generate
  feat: add openai-compatible endpoint support for google-vertex provider (anomalyco#10303)
  fix(desktop): normalize Linux Wayland/X11 backend and decoration policy (anomalyco#13143)
  feat(opencode): Add Venice support in temperature, topP, topK and smallOption (anomalyco#13553)
  desktop: use process-wrap instead of manual job object (anomalyco#13431)
  chore: generate
  fix(website): correct zh-CN translation of proprietary terms in zen.mdx (anomalyco#13734)
  feat(opencode): add `cljfmt` formatter support for Clojure files (anomalyco#13426)
  release: v1.2.5
  feat(app): localize "free usage exceeded" error & "Add credits" clickable link (anomalyco#13652)
  fix(desktop): issue viewing new files opened from the file tree (anomalyco#13689)
  fix(app): only navigate prompt history at input boundaries (anomalyco#13690)
  fix(app): keybind [shift+tab] (anomalyco#13695)
  docs: add Ukrainian README translation (anomalyco#13697)
  fix(desktop): focus window after update/relaunch (anomalyco#13701)
  feat: Add GeistMono Nerd Font to available mono font options (anomalyco#13720)
  fix: ensure sqlite migration logs to stderr instead of stdout (anomalyco#13691)
  release: v1.2.4
  ...
@NimaAra
Copy link

NimaAra commented Feb 16, 2026

I am trying to use this in v1.2.6 with the following config:

"google-vertex": {
      "models": {
        "zai-org/glm-4.7-maas": {
            "name": "GLM-4.7",
            "provider": { 
                "npm": "@ai-sdk/openai-compatible",
                "api": "https://${GOOGLE_VERTEX_ENDPOINT}/v1/projects/${GOOGLE_VERTEX_PROJECT}/locations/${GOOGLE_VERTEX_LOCATION}/endpoints/openapi"
            },
            "limit": { "context": 204800, "output": 131072 },
            "cost": { "input": 0.6, "output": 2.2 },
            "interleaved": {
                "field": "reasoning_content"
            },
            "attachment": false,
            "reasoning": true,
            "family": "glm",
            "temperature": true,
            "tool_call": true,
            "modalities": {
                "input": [ "text" ],
                "output": [ "text" ]
            },
            "release_date": "2025-12-22",
        },

But getting the error:

Error: invalid_scope: Invalid OAuth scope or ID token audience provided.

Gemini methods under same google-vertex provider work fine (via the GOOGLE_APPLICATION_CREDENTIALS pointing to the service.account.json)

I can manually try to do this which works:

"google-vertex-custom": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Google Vertex Custom",
      "options": {
        "baseURL": "https://${GOOGLE_VERTEX_ENDPOINT}/v1/projects/${GOOGLE_VERTEX_PROJECT}/locations/${GOOGLE_VERTEX_LOCATION}/endpoints/openapi",
        "apiKey": "{file:./google-vertex-ai/api.key}"
      },

But I will have to manually refresh the key since gcloud apis are valid for 1 hour only.

What am I missing?

@leehack
Copy link
Contributor Author

leehack commented Feb 16, 2026

@NimaAra I haven't tested version 1.2.6 yet, but I have tested on the dev branch. I copy-pasted your configuration, and it worked.

I suspect that you may not have properly logged in using gcloud.

@NimaAra
Copy link

NimaAra commented Feb 16, 2026

@leehack Do you also use GOOGLE_APPLICATION_CREDENTIALS pointing to your service.account.json or do you use another method?

@leehack
Copy link
Contributor Author

leehack commented Feb 16, 2026

@NimaAra For my configuration, I am not utilizing the JSON key. Instead, it should authenticate using the account I used when logging in with gcloud. I don't see any reason why the GAC is not functioning.

@NimaAra
Copy link

NimaAra commented Feb 16, 2026

Got it, had to run gcloud auth application-default login I was running gcloud auth login instead.

Works great. Once again, thank you for the PR.

@rekram1-node
Copy link
Collaborator

Yes big thanks to @leehack this was a failure on our part. The google vertex ux through opencode is poor. We will improve.

@leehack
Copy link
Contributor Author

leehack commented Feb 17, 2026

@rekram1-node One question: are we going to consolidate the Vertex-Anthropic provider into this one as well? I can technically work on that, but I don't have Anthropic model access on my GCP account, so I can't test it myself.

schneiderlo pushed a commit to schneiderlo/opencode that referenced this pull request Feb 17, 2026
…er (anomalyco#10303)

Co-authored-by: BlueT - Matthew Lien - 練喆明 <BlueT@BlueT.org>
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
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)

7 participants