vertex: partner models (DeepSeek V4.1 Flash, GLM, gpt-oss) go to Google's OpenAI-compatible chat completions

Dani Ariyanto (Discord) asked for Vertex AI's partner/open models, such as
DeepSeek V4.1 Flash, beside Gemini. Google serves them (Model as a Service)
on an OpenAI-compatible chat completions endpoint in the same project,
https://<host>/v1/projects/<p>/locations/<loc>/endpoints/openapi/chat/completions,
with the same OAuth token. The model goes in the body as publisher/model
(deepseek-ai/deepseek-v4.1-flash-maas). Source: Google's
maas/call-open-model-apis page.

An existing Vertex provider needs no change. A model id with a slash
(VertexPartner) is a partner model, as is every publisher/model id that
models.dev lists for google-vertex as @ai-sdk/openai-compatible. It is
asked on Base(Chat) = <project base>/endpoints/openapi (ListedAPIs, so
ModelAPI can't move it). Gemini ids have no slash and stay on
streamGenerateContent. Speaks is now [chat, gemini].
- vertexEffort (Gemini's levels) no longer applies to a partner model.
  Before, a Codex xhigh was clamped to high.
- The provider's own test probes Gemini only. A partner model answers
  only after the project enables it in Model Garden, so an unenabled
  partner model would turn every Gemini user's test red. A partner model
  is tested by its own model test.
- tinyBody's chat probe uses Base(Chat), so the probe goes to the openapi
  address. That address is the only one Sign lets the token go to.
- A test as Codex is refused for Vertex, as it already is for Claude Code
  ("only of a relay").

The global list adds the three partner models that Google's docs list as
live at global on 2026-10-28:
- deepseek-ai/deepseek-v4.1-flash-maas (Preview, global only)
- zai-org/glm-5.2-maas
- openai/gpt-oss-120b-maas

Left out of the list: Gemma 4 (Experimental) and the models retired on
10-21 (v3.x, glm-4.7/5, qwen3, llama-3.3...). Gemma 4 still routes when
typed in by its full id. us/eu/regions are unchanged.

Docs: providers-accounts.md and gateway-routing.md Vertex rows;
reference.md (the global row, how a partner id routes, Model Garden
enablement, typing one in).

Run (on mote via mote-run):
- go test -tags nogui -run TestVertex ./internal/provider ./internal/gateway: ok.
- New: TestVertexPartnerModel (gateway). It covers Chat, Anthropic and
  Responses clients, streamed and whole, against a fake openapi endpoint
  answering in the shape of Google's docs. It checks the path, the Bearer
  token, the body model and the client's text, that Gemini stays on
  streamGenerateContent, and that xhigh is kept.
- New: TestVertexPartnerModels (provider). It covers Speaks/Base,
  APIs per model, the global list, no partner model at us/us-central1,
  that Test() probes Gemini alone, and TestModels on openapi with the
  minted token.
- TestVertexProviderListed now pins Speaks [chat gemini].
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., go build ./...: all ok; gofmt -l clean.
- Full suite: go test -tags nogui -count=1 -timeout 45m ./... at
  80f2bda50 (this change on cb167fcbd): SUITE-EXIT=0, 77 packages ok.
- An earlier full run at base 396e0e463 was red only in
  TestPluginStreamsPastTheBudgetWait. That is #3946, fixed in 7fd77a944
  after that base. It passed 3 of 3 alone at origin/main cb167fcbd.
- The final rebase onto b5d2858f4 (usage, a gateway test, LESSONS) was
  followed by go build and the TestVertex runs again; the suite was not
  run again.

Broken by hand:
- All nine non-test files restored to main, with VertexPartner kept so
  the tests compile: TestVertexPartnerModel red (asked
  publishers/google/models/deepseek-ai/...:streamGenerateContent with a
  Gemini body), TestVertexPartnerModels and TestVertexProviderListed red
  (speaks [gemini]).
- vertexEffort guard removed: red, "effort xhigh sent ... as high".
- Test()'s Vertex chat skip removed: TestVertexTestRequest and
  TestVertexPartnerModels red (a chat probe of the partner model).
- tinyBody back to q.Chat: TestVertexPartnerModels red ("asked only at
  Vertex AI, at its project's address").

Not tried:
- No real Vertex AI account or project here. Nothing reached Google:
  the endpoint, auth and response shapes come from Google's docs only.
- Per-model thinking controls (chat_template_kwargs: DeepSeek thinking,
  GLM enable_thinking) are not mapped. A partner model gets the generic
  chat completions reasoning_effort, and gpt-oss takes it natively.
- Claude on Vertex (publishers/anthropic rawPredict) is out of scope. It
  takes its own request shape and its ids have no slash.
- No GUI change (the API picker reads URL fields, which Vertex has
  none of), so no GUI suite was run.
This commit is contained in:
yetone
2026-10-29 00:33:50 +08:00
parent b5d2858f41
commit 40f206dff1
14 changed files with 251 additions and 14 deletions
+24 -2
View File
@@ -874,7 +874,9 @@ shows them, so magpie shows no plan usage for these keys.
Google Vertex AI (`google-vertex`), which Google's documentation now calls
Gemini Enterprise Agent Platform, serves Google's Gemini models from your own
Google Cloud project, which is billed for them. It takes no API key: each
Google Cloud project, which is billed for them. It serves the
[partner and open models](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/maas/call-open-model-apis)
too, such as DeepSeek, GLM and gpt-oss. It takes no API key: each
request is signed with a token minted from your Google credentials. First turn
on the Agent Platform API (`aiplatform.googleapis.com`) in the project (billing
has to be on there), then sign in with `gcloud auth application-default login`
@@ -910,7 +912,7 @@ so magpie gives each location the models it answered with on 2026-10-06
| Location | Models |
| --- | --- |
| `global` | `gemini-3.8-flash`, `gemini-3.7-flash`, `gemini-3.6-flash`, `gemini-3.5-flash`, `gemini-3.5-flash-lite`, `gemini-4-argon`, `gemini-3.1-pro-preview`, `gemini-3.1-pro-preview-customtools`, `gemini-3.1-flash-lite`, `gemini-3-flash-preview`, `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-2.5-flash-lite` |
| `global` | `gemini-3.8-flash`, `gemini-3.7-flash`, `gemini-3.6-flash`, `gemini-3.5-flash`, `gemini-3.5-flash-lite`, `gemini-4-argon`, `gemini-3.1-pro-preview`, `gemini-3.1-pro-preview-customtools`, `gemini-3.1-flash-lite`, `gemini-3-flash-preview`, `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-2.5-flash-lite`, `deepseek-ai/deepseek-v4.1-flash-maas`, `zai-org/glm-5.2-maas`, `openai/gpt-oss-120b-maas` |
| `us`, `eu` | `gemini-3.8-flash`, `gemini-3.7-flash`, `gemini-3.6-flash`, `gemini-3.5-flash`, `gemini-3.5-flash-lite`, `gemini-3.1-flash-lite` |
| A region | `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-2.5-flash-lite` |
@@ -925,6 +927,26 @@ magpie provider models google-vertex all # back to the location's list
`magpie provider set google-vertex location=…` keeps the models picked, so pick
again after a move.
A partner model is one whose id names its publisher before a slash, as
`deepseek-ai/deepseek-v4.1-flash-maas` does. magpie asks it on Google's
OpenAI-compatible chat completions in your project
(`…/locations/<location>/endpoints/openapi/chat/completions`) with the same
credentials, and asks a Gemini model on generateContent, with nothing to set.
The three in the `global` row are the ones Google's docs list as live there on
2026-10-28. Another partner model (one in preview, or one Google lists later,
such as `google/gemma-4-26b-a4b-it-maas`) is typed in under its full id, as
any model is:
```sh
magpie provider models google-vertex gemini-3.8-flash deepseek-ai/deepseek-v4.1-flash-maas google/gemma-4-26b-a4b-it-maas
```
Turn each partner model on for the project in Model Garden first: until then
Google refuses it. `magpie provider test google-vertex` tests Gemini, and a
partner model is tested on its own (right-click it in the app, or
`magpie provider test google-vertex <model>`). Claude on Vertex AI isn't
served: it takes a request of its own (`rawPredict`), not chat completions.
Google's [Priority PayGo](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/priority-paygo)
and [Flex PayGo](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/flex-paygo)
are asked for with request headers. The editor's **Headers** offers both,
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -32,7 +32,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi
| A provider with no key | A provider of the user's own saves, imports and is `Ready` with no key when it is a preset with `NoKey` or its host is on this computer or the user's own network (`keyOptional`, `ownNetwork`): localhost, a loopback, private, link-local or carrier-grade NAT (Tailscale's 100.64/10) address, or a `.local` name, read from the URL alone with no lookup. A company's keyless relay at a LAN address is taken as a local server is (iSnow_999 on X: a Codex relay at http://<LAN IP>:8080 was left out of a CC Switch import as "it has no API key"); a keyless address on the internet still needs its key. With no key it is asked as one on 127.0.0.1 is: a Responses request carries no `Authorization`. | [`provider.go`](../../internal/provider/provider.go), [`importapps.go`](../../internal/provider/importapps.go), [`import_lan_test.go`](../../internal/provider/import_lan_test.go) |
| A key a provider | One vendor's keys saved a provider each — an app that keeps an entry a key, as CC Switch does, imported (yuluo_yx on X: "NVIDIA #001" to "#600" at one address, "Mistral #0001"…) — are folded into one provider with those keys (`FoldCopies` at start-up, `foldAdded` after `ImportFromApps`): hundreds of copies listed every model hundreds of times in every agent's picker and found group, and 3,000 made `/api/state` 86 MB. At start-up only copies by name are folded: a base name and that name with a number after it (`copyBase`: " #12", or `freeName`'s " 2"), one at least numbered; an import folds what it added whatever their names. Either way they must be alike in all but their key (`foldShape`: the provider with its id, name, keys and on/off left out), what the settings say of their models (`modelPrefs`) and where they are named (`foldRefs`: Visible, the agents' picked, hidden and ordered models, the groups, the providers falling back to them), so one key shown to one agent and another to another stays apart. Not folded: a subscription's, a hidden one, one without a key, Vertex, one with a StepFun sign-in of its own. The first on, in the providers' order, takes the rest in; its name becomes the base and its key is named its old name. Each other is a key in order, named its name, off if it was off (all off: the provider is off, its keys on); its id goes in `Was`, so its calls count with the provider by their key (`ProviderKeyID` is the key's fingerprint, unchanged) and a model picked by the old id still reaches it. Group members, rules, weights and fallbacks naming them name the provider once; their per-model settings and fetched lists go; balance and window history kept by their id moves to their key's name (`foldHistories`). A providers.json that doesn't parse is left alone. It runs at every start and writes nothing when there is nothing to fold. `TestFoldCopies`, `TestFoldCopiesIntoOneOn`, `TestFoldCopiesUnreadable`, `TestImportFoldsAKeyAnEntry`. | [`fold.go`](../../internal/provider/fold.go), [`importapps.go`](../../internal/provider/importapps.go), [`main.go`](../../internal/cli/main.go) |
| A key's plan | A vendor whose plans take keys of their own (`PresetDef.KeyPlans`: zhipu, zai, stepfun, stepfun-cn, xiaomi, baidu-qianfan, tencent-cloud, huaweicloud, volcengine, siliconflow) lets each key say which of the preset's Regions it is for (`KeyAccount.Plan`, `Provider.KeyPlan` for the first; yckonnnn on X: a Volcengine pay-as-you-go key and an Agent Plan key in one provider). No plan, or the provider's own, is the provider's plan, as every key was before, and is stored as none (`SetKeyPlan`, the GUI's `keys/plan`). `WithKey` moves a key's copy to its plan's endpoints (`atKeyPlan`: chat, Responses, Anthropic, decide, key page, docs and catalog; a provider at a host of its own, a mirror or a test's fake vendor, keeps that host) and marks it a key's view (`keyView`), so nothing judges plans on it again. Only when the keys in use are on more than one plan (`PlansMixed`) does anything differ: the model list is each key's plan's (`fetch` goes to `fetchPerKey`; a plan with no list of its own, `planOnly`, is its preset list without a request, so Ark's Coding and Agent Plans ask nothing while pay as you go asks `/api/v3/models` with its own key); plan media (`planMedia`) are every plan's; each key serves its plan's models alone (`PlanServing`, read by the gateway's `perKeyBarred`; a model set for the key in `AccountModels` it serves); plan windows (`PlanQuotas`), Volcengine's and Tencent Cloud's access-key windows (`planViews`) and balances (`balance.go`) are read at each key's plan. Volcengine's keys carry nothing that says their plan, so none is guessed; Xiaomi's `tp-`, Tencent's `sk-tp-`, MiniMax's `sk-cp-` and Bailian's `sk-sp-` prefixes are documented in code but not used to set a plan. The editor's key row has a plan chip (`planPicker`, the app's own menu) while the provider has several keys or the key has a plan. Not done: a gateway key held to some keys of a mixed provider's video (`videoAsker`) may pick another key's plan; a mixed provider whose own plan has no balance source while a key's plan has is not read; StepFun's plan windows are a sign-in per site, unchanged. `TestKeyPlanEndpoints`, `TestKeyPlanServing`, `TestKeyPlanOldConfigsUnchanged`, `TestSetKeyPlan`, `TestKeyPlanModelList`, `TestKeyPlanViews`, `key-plan.test.cjs`. | [`key_plans.go`](../../internal/provider/key_plans.go), [`keys.go`](../../internal/provider/keys.go), [`models.go`](../../internal/provider/models.go) |
| Google Vertex AI | `google-vertex` (`VertexPreset`, `IsVertex`) is a provider of the user's own with no key. `Provider.Vertex` holds `project`, `location` (`global`, `us`, `eu` or a region; `global` when empty), `credentials` (a file; empty for Application Default Credentials) and `impersonate` (a service account's email). Save refuses a key given it, then normalizes them (`Normal`) and checks each (`check`); `normalize` clears the four URLs and any key put in `providers.json` by hand, which stands in for neither a token nor a project and leaves the provider as found savable, so the provider's one address is `vertexBase`, `https://<host>/v1/projects/<project>/locations/<location>`, its host following the location (`vertexHost`). It speaks Gemini alone (`Speaks`, `Base`). It is `Ready` once that address can be made, never from a key or an account; until then the app, `magpie providers` and the TUI say it needs a project, and `magpie provider <id>` says how to give it one. `hasEndpoint` counts it as a provider of the user's own, not a subscription's picks. An import link naming it is refused (`ParseImport`): its project and credentials are the user's own, which no link hands over. `Sign` refuses any other address and sets the bearer token before the user's `Headers`; `AuthHeaders` gives it no key header. Its models are its location's (`vertexModels`, in `planModels`): the preset has `NoList`, because Vertex AI has no list that says what a location serves. The lists are in the [reference](../reference.md#google-vertex-ai). | [`vertex.go`](../../internal/provider/vertex.go), [`provider.go`](../../internal/provider/provider.go), [`account.go`](../../internal/provider/account.go), [`rename.go`](../../internal/provider/rename.go), [`models.go`](../../internal/provider/models.go), [`importurl.go`](../../internal/provider/importurl.go) |
| Google Vertex AI | `google-vertex` (`VertexPreset`, `IsVertex`) is a provider of the user's own with no key. `Provider.Vertex` holds `project`, `location` (`global`, `us`, `eu` or a region; `global` when empty), `credentials` (a file; empty for Application Default Credentials) and `impersonate` (a service account's email). Save refuses a key given it, then normalizes them (`Normal`) and checks each (`check`); `normalize` clears the four URLs and any key put in `providers.json` by hand, which stands in for neither a token nor a project and leaves the provider as found savable, so the provider's one address is `vertexBase`, `https://<host>/v1/projects/<project>/locations/<location>`, its host following the location (`vertexHost`). It speaks chat completions and Gemini (`Speaks`, `Base`), each model one of them (`ListedAPIs`, which `ModelAPI` can't change for it): a Gemini model on generateContent at that address, and a partner model (`VertexPartner`: a `publisher/model` id, as every one models.dev lists for `google-vertex` has, such as `deepseek-ai/deepseek-v4.1-flash-maas`) on Google's OpenAI-compatible chat completions at `<address>/endpoints/openapi`. The provider's test asks Gemini alone, since a partner model answers only after the project turns it on in Model Garden. Each partner model has its own test (`TestModel`, `TestVertexPartnerModels`), and a test as Codex is refused as it is for Claude Code. It is `Ready` once that address can be made, never from a key or an account; until then the app, `magpie providers` and the TUI say it needs a project, and `magpie provider <id>` says how to give it one. `hasEndpoint` counts it as a provider of the user's own, not a subscription's picks. An import link naming it is refused (`ParseImport`): its project and credentials are the user's own, which no link hands over. `Sign` refuses any other address and sets the bearer token before the user's `Headers`; `AuthHeaders` gives it no key header. Its models are its location's (`vertexModels`, in `planModels`): the preset has `NoList`, because Vertex AI has no list that says what a location serves. The lists are in the [reference](../reference.md#google-vertex-ai). | [`vertex.go`](../../internal/provider/vertex.go), [`provider.go`](../../internal/provider/provider.go), [`account.go`](../../internal/provider/account.go), [`rename.go`](../../internal/provider/rename.go), [`models.go`](../../internal/provider/models.go), [`importurl.go`](../../internal/provider/importurl.go) |
| Vertex AI tokens | `vertexCredentialsFile` finds the credentials as Google's libraries find Application Default Credentials: the provider's `credentials`, else the file `GOOGLE_APPLICATION_CREDENTIALS` names, else `application_default_credentials.json` in gcloud's folder (`CLOUDSDK_CONFIG`, else `~/.config/gcloud`, `%APPDATA%\gcloud` on Windows); a `~/` that starts any of them is the home. `mint` reads three kinds: `authorized_user` (a refresh-token grant), `service_account` (an RS256 JWT, RFC 7523: `signed`) and gcloud's `impersonated_service_account`, whose `source_credentials` are minted and traded at IAM Credentials, along its `delegates`, for the account its `service_account_impersonation_url` names (`impersonationURL`: the token never goes to that URL's host). With `impersonate` set, the token those give is traded at IAM Credentials' `generateAccessToken` for a `cloud-platform` token of that account's, as gcloud's `--impersonate-service-account` does (`impersonateFor`); the credentials' account needs `roles/iam.serviceAccountTokenCreator` on it, which the 403 names. `vertexTokens` keeps one token per file and impersonated account, in memory only; requests made together mint it once, and those that waited through a mint that failed are given its error rather than each minting in turn (`mints`, `failed`). A mint cut short because its own request was given up on fails none of them: the next one mints. It is minted again within `vertexRefreshLead` (5 minutes) of expiry, or when the file's size or modification time has changed (gcloud signed in again). One mint, every exchange included, gets `vertexMintWait` (30 seconds). The file is only read. | [`vertex.go`](../../internal/provider/vertex.go), [`signin.go`](../../internal/provider/signin.go) |
| Amazon Bedrock Mantle | `bedrock-mantle` ("Amazon Bedrock (Mantle)", @marktoown on X) is a vendor preset beside the runtime's `bedrock`, with the same Bedrock API key and seventeen regions of its own (`mantleRegions`: the `bedrock-mantle.{region}.api.aws` hosts that answered on 2026-10-16). Chat completions and Responses are at `/v1`, Messages at `/anthropic`; unlike the runtime it lists its models (`GET /v1/models`; `NoList` stays the runtime's alone). Its OpenAI APIs serve each model under one of two prefixes: OpenAI's closed GPTs and xAI's Grok under `/openai/v1`, the rest under `/v1` (`MantleBase`, used by the gateway and the provider test's `tinyBody`). `IsBedrockMantle` is the preset or a provider added at a Mantle host (`mantleHost`), and `IsBedrock` includes it, so every Bedrock rule holds there too: Claude on Messages alone, the key as `x-api-key` alone, `max_completion_tokens`, no metadata, no Priority. A provider added at a Mantle address is given the APIs it wasn't (`mantleEndpoints`, in `normalize`), and a chat or Responses URL given at `/openai/v1` is moved to `/v1`, where the list is. | [`presets.go`](../../internal/provider/presets.go), [`provider.go`](../../internal/provider/provider.go), [`test.go`](../../internal/provider/test.go) |
| Subscription accounts | `Accounts` reads the credentials each agent keeps on disk or in the macOS Keychain; nothing is stored twice. With account discovery off (#1535, below) none of them is read. A built-in that has moved to its plugin is dropped (`Moved`), and plugin accounts are placed in its slot (`placeMoved`). `Sign` adds the account's own auth, then the user's `Headers`. | [`account.go`](../../internal/provider/account.go) |
+3 -1
View File
@@ -5453,7 +5453,9 @@ func (s *Server) forwardTranslated(ctx context.Context, p provider.Provider, to
r.Effort, req = e, &r
}
}
if p.IsVertex() {
if p.IsVertex() && !provider.VertexPartner(model) {
// Gemini's levels; a partner model on chat completions is sent
// its effort as any OpenAI-compatible vendor is
req = vertexEffort(req, p.Efforts(model))
}
// the names in force, read once however many endpoints the request is
+6
View File
@@ -16,6 +16,12 @@ import (
// at all on 2.5, is a 400 (vertexEffort, vertexThinking). A call's thought
// signature goes back as Vertex AI gave it, as on every Gemini path
// (gemini_signature.go): a call made with none on a step it signed is a 400.
//
// Its partner models (provider.VertexPartner: deepseek-ai/…, zai-org/…,
// openai/gpt-oss-…) are not Gemini: Google serves them on its
// OpenAI-compatible chat completions at the project (Base(Chat)), under
// the same token, and the gateway asks them there as it asks any chat
// completions vendor. Nothing in this file is done to them.
// buildVertex is a streamGenerateContent body for Vertex AI, which names the
// model in its path and has none in here.
+68
View File
@@ -135,6 +135,22 @@ const (
vertexMissingSig = "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Function call is missing a thought_signature in functionCall parts. This is required for tools to work correctly, and missing thought_signature may lead to degraded model performance. Additional data, function call `default_api:get_weather` , position 2. Please refer to https://ai.google.dev/gemini-api/docs/thought-signatures for more details.\",\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n"
)
// vertexPartnerStream and vertexPartnerWhole are a partner model's
// answer on Vertex AI's OpenAI-compatible chat completions, streamed and
// whole, in the shape Google's docs for its open models show
// (call-open-model-apis): chat.completion.chunk events, the last with the
// finish reason and usage, then [DONE].
const (
vertexPartnerStream = `data: {"id":"chatcmpl-v41","object":"chat.completion.chunk","created":1761609600,"model":"deepseek-ai/deepseek-v4.1-flash-maas","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello"}}]}
data: {"id":"chatcmpl-v41","object":"chat.completion.chunk","created":1761609600,"model":"deepseek-ai/deepseek-v4.1-flash-maas","choices":[{"index":0,"delta":{"content":" from DeepSeek"},"finish_reason":"stop"}],"usage":{"prompt_tokens":9,"completion_tokens":4,"total_tokens":13}}
data: [DONE]
`
vertexPartnerWhole = `{"id":"chatcmpl-v41","object":"chat.completion","created":1761609600,"model":"deepseek-ai/deepseek-v4.1-flash-maas","choices":[{"index":0,"message":{"role":"assistant","content":"Hello from DeepSeek"},"finish_reason":"stop"}],"usage":{"prompt_tokens":9,"completion_tokens":4,"total_tokens":13}}`
)
// vertexLevels are the reasoning levels models.dev gives Gemini's models.
const vertexLevels = `{"google":{"models":{
"gemini-3.8-flash":{"id":"gemini-3.8-flash","reasoning_options":[{"type":"effort","values":["low","medium","high"]}]},
@@ -177,6 +193,13 @@ func (v *vertexUp) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if strings.HasSuffix(r.URL.Path, ":generateContent") {
out, kind = vertexColours, "application/json; charset=UTF-8"
}
if strings.HasSuffix(r.URL.Path, "/endpoints/openapi/chat/completions") {
// a partner model, on Google's OpenAI-compatible chat completions
out = vertexPartnerStream
if m["stream"] != true {
out, kind = vertexPartnerWhole, "application/json"
}
}
if refused := vertexSigRefused(m); refused != "" {
code, out = http.StatusBadRequest, refused
} else if v.reply != nil {
@@ -849,3 +872,48 @@ func TestVertexRetriesOnlyForVertex(t *testing.T) {
}
}
}
// A partner model on Vertex AI (deepseek-ai/deepseek-v4.1-flash-maas) is
// asked on Google's OpenAI-compatible chat completions at the project,
// signed with the same minted token, its full id in the body, from a Chat
// client, Claude Code and Codex, streamed or not, with nothing set beyond
// the Gemini provider the user already has; a Gemini model beside it is
// still asked at streamGenerateContent. Its effort goes as the client
// asked: Gemini's levels (vertexEffort) are not put on it.
func TestVertexPartnerModel(t *testing.T) {
v := &vertexUp{}
s := vertexServe(t, v, vertexLevels)
const want = "/v1/projects/proj-1/locations/global/endpoints/openapi/chat/completions"
const model = "google-vertex/deepseek-ai/deepseek-v4.1-flash-maas"
for _, c := range []struct{ name, path, body string }{
{"chat", "/v1/chat/completions", `{"model":"` + model + `","messages":[{"role":"user","content":"hi"}]}`},
{"anthropic", "/v1/messages", `{"model":"` + model + `","max_tokens":100,"messages":[{"role":"user","content":"hi"}]}`},
{"responses", "/v1/responses", `{"model":"` + model + `","input":"hi"}`},
} {
for _, stream := range []string{"false", "true"} {
n := v.count()
body := strings.TrimSuffix(c.body, "}") + `,"stream":` + stream + `}`
out := vertexAsk(t, s, c.path, body)
a := v.last(t)
if v.count() != n+1 || a.path != want || a.auth != "Bearer ya29.vertex-test" || a.body["model"] != "deepseek-ai/deepseek-v4.1-flash-maas" {
t.Errorf("%s stream %s: asked %d times, at %s with %q, model %v", c.name, stream, v.count()-n, a.path, a.auth, a.body["model"])
}
if _, gemini := a.body["contents"]; gemini {
t.Errorf("%s stream %s: sent a Gemini body: %v", c.name, stream, a.body)
}
if !strings.Contains(out, "Hello") || !strings.Contains(out, "DeepSeek") {
t.Errorf("%s stream %s: client given %s", c.name, stream, out)
}
}
}
vertexAsk(t, s, "/v1/chat/completions", `{"model":"google-vertex/gemini-3.8-flash","messages":[{"role":"user","content":"hi"}]}`)
if a := v.last(t); a.path != "/v1/projects/proj-1/locations/global/publishers/google/models/gemini-3.8-flash:streamGenerateContent" {
t.Errorf("Gemini asked at %s", a.path)
}
// translated from Codex's Responses, where Gemini's levels (low to
// high when a model's own aren't known) would be put on it
vertexAsk(t, s, "/v1/responses", `{"model":"`+model+`","reasoning":{"effort":"xhigh"},"input":"hi"}`)
if a := v.last(t); a.path != want || a.body["reasoning_effort"] != "xhigh" {
t.Errorf("effort xhigh sent at %s as %v", a.path, a.body["reasoning_effort"])
}
}
+8
View File
@@ -159,6 +159,14 @@ func (p Provider) ListedAPIs(model string) []Protocol {
return apis
}
}
// Vertex AI serves Gemini on generateContent, and its partner models
// (publisher/model) on chat completions alone
if p.IsVertex() {
if VertexPartner(model) {
return []Protocol{Chat}
}
return []Protocol{Gemini}
}
// Factory serves each model on the one API droid sends it on
if p.ID == "factory" && p.Account != nil {
return factoryAPIs(model)
+2 -1
View File
@@ -470,7 +470,8 @@ func setModelAPI(ref, api string) (bool, error) {
// ModelAPI is the API the user said p's model is asked on, when p has a
// URL for it still.
func (p Provider) ModelAPI(model string) (Protocol, bool) {
if len(p.Speaks()) < 2 {
// Vertex AI's model id says its one API (ListedAPIs)
if len(p.Speaks()) < 2 || p.IsVertex() {
return "", false
}
proto := Protocol(heldSettings().ModelAPIs[p.ID+"/"+model])
+8 -3
View File
@@ -139,8 +139,12 @@ var presets = []PresetDef{
Website: "https://aistudio.google.com", KeysURL: "https://aistudio.google.com/apikey"},
// Google's Gemini models in the user's own Google Cloud project
// (vertex.go): generateContent, signed with their Google credentials
// rather than a key. It has no list to ask that says which models a
// location serves, so they are given: these, every one global serves;
// rather than a key; and its partner models (publisher/model ids,
// VertexPartner) on Google's OpenAI-compatible chat completions there,
// the live ones Google's docs list at global on 2026-10-28 (Gemma 4,
// Experimental, is left to be typed in). It has no list to ask that
// says which models a location serves, so they are given: these,
// every one global serves;
// vertexModels has the others'. Its Priority PayGo and Flex PayGo are
// asked for with the two headers.
{ID: VertexPreset, Name: "Google Vertex AI", Short: "Vertex AI", Icon: "vertexai-color", Kind: KindVendor,
@@ -149,7 +153,8 @@ var presets = []PresetDef{
NoList: true,
Models: []string{"gemini-3.8-flash", "gemini-3.7-flash", "gemini-3.6-flash", "gemini-3.5-flash", "gemini-3.5-flash-lite",
"gemini-4-argon", "gemini-3.1-pro-preview", "gemini-3.1-pro-preview-customtools", "gemini-3.1-flash-lite", "gemini-3-flash-preview",
"gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.5-flash-lite"},
"gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.5-flash-lite",
"deepseek-ai/deepseek-v4.1-flash-maas", "zai-org/glm-5.2-maas", "openai/gpt-oss-120b-maas"},
HeaderHints: []string{"X-Vertex-AI-LLM-Request-Type", "X-Vertex-AI-LLM-Shared-Request-Type"}},
{ID: "deepseek", Name: "DeepSeek", Icon: "deepseek-color", Kind: KindVendor, Catalog: "deepseek",
Chat: "https://api.deepseek.com/v1", Responses: "https://api.deepseek.com/v1", Anthropic: "https://api.deepseek.com/anthropic",
+11 -1
View File
@@ -1537,6 +1537,14 @@ func (p Provider) baseOf(api string) string {
func (p Provider) Base(proto Protocol) string {
switch proto {
case Chat:
// Vertex AI's partner models, on Google's OpenAI-compatible chat
// completions at the project (VertexPartner)
if p.IsVertex() {
if b := p.vertexBase(); b != "" {
return b + "/endpoints/openapi"
}
return ""
}
return p.Chat
case Responses:
return p.Responses
@@ -1579,7 +1587,9 @@ func (p Provider) Speaks() []Protocol {
// Factory's Gemini models, on generateContent. A model droid didn't
// list stays on the other three (factoryAPIs); this is not one of them.
// A custom provider's Gemini API comes after the others it has.
// Vertex AI's, on generateContent alone, at its project.
// Vertex AI's Gemini models, on generateContent at its project, after
// the chat completions its partner models are served on (ListedAPIs
// gives each model its one).
if p.IsVertex() {
if p.vertexBase() != "" {
out = append(out, Gemini)
+7 -1
View File
@@ -70,6 +70,12 @@ func (p Provider) Test(ctx context.Context) []Result {
}
var out []Result
for _, proto := range p.Speaks() {
if p.IsVertex() && proto == Chat {
// a partner model answers only once the project has turned it
// on in Model Garden: the provider is tested on Gemini, and a
// partner model by its own test (TestModel)
continue
}
q, ok := p.keyFor(proto)
model := p.testModel(q, proto)
if !ok {
@@ -192,7 +198,7 @@ func tinyBody(q Provider, proto Protocol, model string) (url, body string) {
if q.IsBedrock() || q.IsAzure() {
return q.mantleBase(q.Chat, model) + "/chat/completions", fmt.Sprintf(`{"model":%q,"messages":[{"role":"user","content":"hi"}],"max_completion_tokens":16}`, model)
}
return q.Chat + "/chat/completions", fmt.Sprintf(`{"model":%q,"messages":[{"role":"user","content":"hi"}],"max_tokens":16}`, model)
return q.Base(Chat) + "/chat/completions", fmt.Sprintf(`{"model":%q,"messages":[{"role":"user","content":"hi"}],"max_tokens":16}`, model)
case Responses:
return q.mantleBase(q.Responses, model) + "/responses", fmt.Sprintf(`{"model":%q,"input":[{"type":"message","role":"user","content":[{"type":"input_text","text":"hi"}]}],"max_output_tokens":16}`, model)
case Anthropic:
+5
View File
@@ -80,6 +80,11 @@ func (p Provider) TestsAs(client string) string {
if p.IsOpenCode() || p.IsCline() || p.IsKilo() {
return "its requests are asked as its own client already"
}
if p.IsVertex() && client == ClientCodex {
// Google's own endpoints, as Claude Code's are below: its chat
// completions serve the partner models alone
return "a test is asked as Codex only of a relay"
}
if clientProto(client, p.Speaks()) == "" {
if client == ClientClaudeCode {
return "it has no Anthropic endpoint, where Claude Code's requests go"
+12 -2
View File
@@ -174,6 +174,15 @@ func VertexPath(model string) string {
return "/publishers/google/models/" + url.PathEscape(model) + ":streamGenerateContent?alt=sse"
}
// VertexPartner is whether model is one of Vertex AI's partner or open
// models (Model as a Service: DeepSeek, GLM, gpt-oss, Gemma, Llama…),
// which Google serves on its OpenAI-compatible chat completions at the
// project (Base(Chat), …/endpoints/openapi) under a publisher/model id
// such as deepseek-ai/deepseek-v4.1-flash-maas. Every such id models.dev
// lists for google-vertex has the publisher before a slash, and no Gemini
// id on generateContent has one, so the slash is what tells them apart.
func VertexPartner(model string) bool { return strings.Contains(model, "/") }
// VertexWholePath is where a request for model answered as one JSON body
// goes.
func VertexWholePath(model string) string {
@@ -215,9 +224,10 @@ func vertexGeneration(model string) int {
return n
}
// vertexModels are the Gemini models a location serves, as each answered
// vertexModels are the models a location serves, as each answered
// on 2026-10-06: every one at global (and Gemini 4 Argon, there since
// 2026-10-13, #2155); Gemini 3's Flash models at us and
// 2026-10-13, #2155, and the partner models Google serves at global
// alone, VertexPartner); Gemini 3's Flash models at us and
// eu, which serve no Pro, preview or 2.5; Gemini 2.5 at a region, where a
// few add one more (asia-northeast1's gemini-3.5-flash), typed in by hand.
func vertexModels(loc string) []string {
+95 -1
View File
@@ -177,6 +177,10 @@ func (f *vertexGoogle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case vertex && strings.Contains(r.URL.Path, "/models/gemini-9-pro:"):
w.WriteHeader(http.StatusNotFound)
io.WriteString(w, "{\"error\":{\"code\":404,\"message\":\"Publisher Model `projects/acme-vertex/locations/global/publishers/google/models/gemini-9-pro` was not found or your project does not have access to it. Please ensure you are using a valid model version. For more information, see: https://cloud.google.com/vertex-ai/generative-ai/docs/learn/model-versions\",\"status\":\"NOT_FOUND\"}}")
case vertex && strings.HasSuffix(r.URL.Path, "/endpoints/openapi/chat/completions"):
// a partner model, on Google's OpenAI-compatible chat completions,
// answered as its docs show
io.WriteString(w, `{"id":"chatcmpl-1","object":"chat.completion","created":1761609600,"model":"deepseek-ai/deepseek-v4.1-flash-maas","choices":[{"index":0,"message":{"role":"assistant","content":"Hi"},"finish_reason":"length"}],"usage":{"prompt_tokens":1,"completion_tokens":1,"total_tokens":2}}`)
case vertex:
io.WriteString(w, `{"candidates":[{"content":{"role":"model","parts":[{"text":"Hi"}]},"finishReason":"MAX_TOKENS"}],"usageMetadata":{"promptTokenCount":1,"candidatesTokenCount":1,"totalTokenCount":2},"modelVersion":"gemini-3.8-flash"}`)
default:
@@ -502,7 +506,7 @@ func TestVertexProviderListed(t *testing.T) {
t.Fatal(err)
}
base := "https://aiplatform.googleapis.com/v1/projects/acme-vertex/locations/global"
if !p.Ready() || !p.On() || !slices.Equal(p.Speaks(), []Protocol{Gemini}) || p.Base(Gemini) != base {
if !p.Ready() || !p.On() || !slices.Equal(p.Speaks(), []Protocol{Chat, Gemini}) || p.Base(Gemini) != base || p.Base(Chat) != base+"/endpoints/openapi" {
t.Fatalf("ready %v, on %v, speaks %v at %q", p.Ready(), p.On(), p.Speaks(), p.Base(Gemini))
}
if !customIDs()["vertex-prod"] || PluginID("vertex-prod") != "vertex-prod-plugin" {
@@ -1557,3 +1561,93 @@ func TestVertexMintWaitCancelled(t *testing.T) {
stop()
<-minted
}
// Vertex AI's partner models (DeepSeek, GLM, gpt-oss: publisher/model ids)
// are served on Google's OpenAI-compatible chat completions at the
// project, …/endpoints/openapi/chat/completions, signed with the same
// Google token as Gemini, with nothing more set by the user: global lists
// them, each is tested there with its full id in the body, and a Gemini
// model is still asked on generateContent alone. The provider's own test
// asks Gemini, as a partner model answers only once the project turned it
// on in Model Garden.
func TestVertexPartnerModels(t *testing.T) {
vertexHome(t)
f := newVertexGoogle(t)
file := filepath.Join(t.TempDir(), "application_default_credentials.json")
writeFile(t, file, vertexUser("1//0g-test-refresh"))
if err := Save(vertexAt("global", file)); err != nil {
t.Fatal(err)
}
p, err := Find("vertex-prod")
if err != nil {
t.Fatal(err)
}
base := f.url + "/vertex/v1/projects/acme-vertex/locations/global"
if !slices.Equal(p.Speaks(), []Protocol{Chat, Gemini}) || p.Base(Chat) != base+"/endpoints/openapi" || p.Base(Gemini) != base {
t.Fatalf("speaks %v, chat at %q, Gemini at %q", p.Speaks(), p.Base(Chat), p.Base(Gemini))
}
partners := []string{"deepseek-ai/deepseek-v4.1-flash-maas", "zai-org/glm-5.2-maas", "openai/gpt-oss-120b-maas"}
listed := modelIDs(p.Available())
for _, m := range partners {
if !slices.Contains(listed, m) {
t.Errorf("%s not listed at global: %v", m, listed)
}
if apis := p.APIs(m); !slices.Equal(apis, []Protocol{Chat}) {
t.Errorf("%s asked on %v", m, apis)
}
if p.Native(m) != Chat {
t.Errorf("%s native %v", m, p.Native(m))
}
}
if apis := p.APIs("gemini-3.8-flash"); !slices.Equal(apis, []Protocol{Gemini}) {
t.Errorf("Gemini asked on %v", apis)
}
for _, loc := range []string{"us", "us-central1"} {
q := vertexAt(loc, file)
if err := Save(q); err != nil {
t.Fatal(err)
}
q2, _ := Find("vertex-prod")
if got := modelIDs(q2.Available()); slices.ContainsFunc(got, VertexPartner) {
t.Errorf("at %s, which serves no partner model: %v", loc, got)
}
}
if err := Save(vertexAt("global", file)); err != nil {
t.Fatal(err)
}
p, _ = Find("vertex-prod")
rs := p.Test(context.Background())
if len(rs) != 1 || !rs[0].OK || rs[0].Protocol != Gemini {
t.Fatalf("provider test: %+v", rs)
}
rs = p.TestModels(context.Background(), []string{"deepseek-ai/deepseek-v4.1-flash-maas", "gemini-3.8-flash"})
if len(rs) != 2 || !rs[0].OK || rs[0].Protocol != Chat || !rs[1].OK || rs[1].Protocol != Gemini {
t.Fatalf("models' tests: %+v", rs)
}
calls := f.vertexCalls()
if len(calls) != 3 {
t.Fatalf("Vertex AI was asked %d times, want 3: %+v", len(calls), calls)
}
// the models' tests may go out together, in either order
var chats int
for _, c := range calls {
if strings.HasSuffix(c.path, "/endpoints/openapi/chat/completions") {
chats++
var body struct {
Model string `json:"model"`
}
json.Unmarshal([]byte(c.body), &body)
if c.path != "/vertex/v1/projects/acme-vertex/locations/global/endpoints/openapi/chat/completions" ||
c.header.Get("Authorization") != "Bearer ya29.minted-1" || body.Model != "deepseek-ai/deepseek-v4.1-flash-maas" {
t.Errorf("partner model asked at %s with %q: %s", c.path, c.header.Get("Authorization"), c.body)
}
continue
}
if !strings.HasPrefix(c.path, "/vertex/v1/projects/acme-vertex/locations/global/publishers/google/models/gemini-") || !strings.HasSuffix(c.path, ":generateContent") {
t.Errorf("Gemini asked at %s", c.path)
}
}
if chats != 1 {
t.Errorf("chat completions asked %d times, want 1", chats)
}
}