Skip to content

Conversation

@bluet
Copy link

@bluet bluet commented Jan 26, 2026

Summary

Adds custom loader for google-vertex-openai provider to enable Vertex AI partner models (GLM, Llama, Qwen, DeepSeek) via the OpenAI-compatible Chat Completions API endpoint.

Problem

The @ai-sdk/google-vertex SDK only supports Google's Gemini models because it:

  • Hardcodes publishers/google in URL construction
  • Uses v1beta1 API version
  • Expects Gemini-specific API format

Partner models like GLM-4.7, Llama 4, Qwen3, and DeepSeek use a different endpoint:

https://{location}-aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/endpoints/openapi/chat/completions

Solution

Created custom loader for google-vertex-openai provider that:

  • Uses @ai-sdk/openai-compatible (already bundled in OpenCode)
  • Injects Google OAuth tokens via custom fetch wrapper
  • Uses google-auth-library for auto-refreshing tokens (transitive dep of @ai-sdk/google-vertex)
  • Supports both global and regional endpoints
  • Auto-loads when GOOGLE_CLOUD_PROJECT env var is set and credentials are available

Technical Details

Auth Method: Google Application Default Credentials (ADC)

  • Uses GoogleAuth from google-auth-library
  • Scope: https://www.googleapis.com/auth/cloud-platform
  • Tokens auto-refresh 5 minutes before expiry

Endpoint Construction:

  • Global: https://aiplatform.googleapis.com/v1/projects/{project}/locations/global/endpoints/openapi
  • Regional: https://{location}-aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/endpoints/openapi

Implementation Pattern:
Follows the same pattern as google-vertex-anthropic loader - custom SDK with OAuth injection.

Models Supported

Models are defined in companion PR: anomalyco/models.dev#716

  • GLM-4.7 (zai-org)
  • Llama 4 Maverick 17B-128E (meta)
  • Llama 3.3 70B (meta)
  • Qwen3 235B Instruct (qwen)
  • DeepSeek V3.1 (deepseek-ai)

Testing

Requires:

  • GOOGLE_CLOUD_PROJECT environment variable
  • Google Application Default Credentials: gcloud auth application-default login
  • Models enabled in Google Cloud Console (Model Garden)

Test command:

export GOOGLE_CLOUD_PROJECT=your-project-id
export GOOGLE_CLOUD_LOCATION=global  # or regional like us-central1
opencode
# Select: google-vertex-openai/glm-4.7-maas

Related PRs

References

…dels

Add custom loader for google-vertex-openai provider that enables
Vertex AI partner models (GLM, Llama, Qwen, DeepSeek) via the
OpenAI-compatible Chat Completions API endpoint.

Implementation:
- Uses @ai-sdk/openai-compatible (already bundled)
- Injects Google OAuth via custom fetch wrapper
- Uses google-auth-library for auto-refreshing tokens (transitive dep)
- Supports both global and regional endpoints
- Auto-loads when GOOGLE_CLOUD_PROJECT is set and credentials available

Endpoint pattern:
https://{location}-aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/endpoints/openapi

Companion PR in anomalyco/models.dev adds model definitions.
@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:

PR #10303: feat: add google-vertex-openapi provider with ADC authentication
#10303

Why it's related:

  • Both PRs are adding Google Vertex AI provider support with Application Default Credentials (ADC) authentication
  • Both use OpenAI-compatible endpoints for partner models
  • Both implement custom loaders with OAuth token injection
  • The naming is nearly identical (google-vertex-openai vs google-vertex-openapi)

Recommendation: Check PR #10303 to see if it's addressing the same feature or if there's overlap in implementation. They may need to be consolidated or one may supersede the other.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant