anomalyco / anomalyco/opencode

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

Open
#49,741 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the @ai-sdk/google-vertex provider and the custom plugin LanguageModelV1 integration, focusing on doStream(), doGenerate(), and the /chat/completions request path. Compare those entry points with Vertex AI's publisher endpoint and Mistral's messages format. Done requires a clearly chosen scope among provider support, a separate provider, or custom plugin handling, with streaming and non-streaming behavior covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
google-cloud, typescript
Domain
ai, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.