Skip to content

[FEATURE]: google-vertex to enable openai compatible models #49741

Closed

Description

@mantielero

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

I am a newbie using opencode, so maybe this is already covered somewhere and I failed to spot it. I am sorry about that if this is the case.

I was trying to use mistral models through vertexai in opencode and it fail. The reason is that mistral seems to expect openai compatible communication. The following was generated by AI:

Feature Request: Native Support for Mistral Models on Google Vertex AI

Summary

Add native support for Mistral AI models (e.g., mistral-small-2503, mistral-medium-3) available through Google Cloud Vertex AI in the @ai-sdk/google-vertex provider or as a separate provider package.

Problem Statement

Currently, OpenCode cannot use Mistral models deployed on Google Cloud Vertex AI because:

  1. Different API Endpoint: Mistral models on Vertex AI use a different endpoint structure than standard Vertex AI models:

    POST /v1/projects/{project}/locations/{location}/publishers/mistralai/models/{model}:streamRawPredict
    

    Instead of the standard generative AI endpoints.

  2. Custom Request Format: Mistral models expect the native Mistral/OpenAI-compatible format (with messages, model, stream, etc.), not the Vertex AI Gemini format.

  3. Plugin System Limitation: While OpenCode supports custom plugins that implement LanguageModelV1, the framework appears to bypass custom doStream()/doGenerate() methods and instead attempts to construct HTTP requests using baseURL + "/chat/completions", which doesn't exist for Vertex AI endpoints.

Current Workaround

To use Mistral models on Vertex AI with OpenCode, we need to run a local proxy server that:

  • Exposes an OpenAI-compatible endpoint (/v1/chat/completions)
  • Translates requests to Vertex AI's streamRawPredict format
  • Converts responses back to OpenAI format

This works but requires:

  • Running an additional service (proxy server)
  • Manual startup before each OpenCode session
  • Extra maintenance overhead

Proposed Solution

Option 1: Extend @ai-sdk/google-vertex Provider (Recommended)

Add support for Mistral models directly in the existing Google Vertex AI provider:

// Example usage
import { vertex } from '@ai-sdk/google-vertex';

const model = vertex('mistral-small-2503', {
  project: 'my-project',
  location: 'europe-west4',
  publisher: 'mistralai', // New option
});

Implementation approach:

  1. Detect publisher prefix (e.g., mistralai/*) or add explicit publisher option
  2. Route to appropriate endpoint based on publisher:
    • Standard Gemini models → /generateContent
    • Mistral models → /publishers/mistralai/models/{model}:streamRawPredict
  3. Format request body according to model type:
    • Gemini → Vertex AI format
    • Mistral → OpenAI-compatible format

Option 2: Create Separate @ai-sdk/vertex-mistral Provider

Create a dedicated provider package for Mistral models on Vertex AI:

import { vertexMistral } from '@ai-sdk/vertex-mistral';

const model = vertexMistral('mistral-small-2503', {
  project: 'my-project',
  location: 'europe-west4',
});

Option 3: Fix Custom Plugin Support

Ensure OpenCode/AI SDK properly respects custom doStream() and doGenerate() implementations in plugins without attempting to construct HTTP requests directly.

Current behavior:

  • Custom plugin implements LanguageModelV1 with doStream() and doGenerate()
  • Framework ignores custom methods and tries to call baseURL + "/chat/completions"
  • Results in "undefined/chat/completions" cannot be parsed as a URL error

Expected behavior:

  • Framework should call the plugin's doStream()/doGenerate() methods directly
  • Only fall back to HTTP client if methods are not implemented

Benefits

  1. Better User Experience: No need to run separate proxy services
  2. Enterprise Use Case: Many organizations use Google Cloud and want to leverage Mistral models through their existing Vertex AI infrastructure
  3. Cost Optimization: Vertex AI provides committed use discounts and simplified billing
  4. Compliance: Some organizations require all AI APIs to go through approved cloud platforms
  5. Consistency: Use the same authentication (ADC) and configuration as other Vertex AI models

Technical Details

Endpoint Format

POST https://{location}-aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/publishers/mistralai/models/{model}:streamRawPredict

Request Format

{
  "model": "mistral-small-2503",
  "messages": [
    {"role": "user", "content": "Hello"}
  ],
  "stream": true,
  "temperature": 0.7,
  "max_tokens": 1024,
  "tools": [...]  // Optional
}

Response Format

Server-Sent Events (SSE) with OpenAI-compatible streaming format:

data: {"id":"...","object":"chat.completion.chunk","choices":[{"delta":{"content":"Hello"}}]}
data: [DONE]

Authentication

Uses Google Cloud Application Default Credentials (ADC), same as standard Vertex AI models.

Available Models on Vertex AI

As of 2025, Mistral AI models available on Google Cloud Vertex AI include:

  • mistral-small-2503 (Mistral Small 3.1)
  • mistral-medium-3 (Mistral Medium 3)
  • Additional models as announced by Mistral AI and Google Cloud

Related Issues

This feature request is related to:

  • Supporting third-party models on cloud platforms
  • Improving custom plugin flexibility in OpenCode/AI SDK
  • Vertex AI MaaS (Model-as-a-Service) integration

Activity

  1. mantielero commented on Sep 18, 2026

    @mantielero
    Author

    Find attached the proxy that I am using and that is working with mistral-small-2503

    my_proxy.js

  2. rekram1-node commented on Oct 9, 2026

    @rekram1-node
    Collaborator

    Will be in the next opencode v2 release, which should be tmr (v2.0.27):
    https://opencode.ai/v2/docs

  3. mantielero commented on Oct 13, 2026

    @mantielero
    Author

    Do I need to set anything in particular in the configuration in order to use it?
    I tried to use it today and it failed. It says that the model was not found on my project.

    I am using opencode v2.0.27.

    I checked with python that I can access :rawPredict and :streamRawPredict.

    In my configuration file I just set:

    "npm": "@ai-sdk/google-vertex",
    "options": <with project and location info>,
    "models": {
      "mistral-small-2503": {
         "name": "Mistral"
    }
    }
    
  4. opencode-agent commented on Oct 13, 2026

    @opencode-agent
    Contributor

    Thanks for testing it! It depends on how the provider is set up.

    Built-in google-vertex provider (recommended). This should just work. The built-in provider already includes mistral-small-2503, mistral-medium-3 and codestral-2 and sends them to Vertex's streamRawPredict endpoint, so you don't need npm or a models entry. Just set a project and a regional location (Mistral isn't served from the global endpoint):

    {
      "provider": {
        "google-vertex": {
          "options": { "project": "your-project", "location": "europe-west4" }
        }
      }
    }

    Then pick google-vertex/mistral-small-2503.

    Custom provider. If you use your own provider ID with "npm": "@ai-sdk/google-vertex" (which is what your snippet looks like), every model goes through the Gemini route. That's why Vertex says the model isn't found in your project. For a fully custom provider, we recommend this config, which points the Mistral model at the Vertex Mistral route explicitly:

    {
      "providers": {
        "my-vertex": {
          "package": "@opencode/ai/providers/google-vertex",
          "settings": { "project": "your-project", "location": "europe-west4" },
          "models": {
            "mistral-small-2503": {
              "name": "Mistral Small",
              "package": "@opencode/ai/providers/google-vertex/mistral"
            }
          }
        }
      }
    }

    Auth uses your Application Default Credentials, the same as other Vertex models. Let us know if either one still fails, and include the exact error.

  5. mantielero commented on Oct 14, 2026

    @mantielero
    Author

    That worked. Thank you.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions