gateway: /v1/magpie/native/<provider>/<path> passes Ark's own images and video-task API on

axelburks on Discord asked for a way to reach what the OpenAI-shaped
routes can't carry: Ark's image stream, its task list and cancel, a
field newer than magpie. A coordinator asked for it to stay behind the
gateway's key and auth like every route, and for the design to be said.

Decided:
- One route, /v1/magpie/native/{provider}/{path...} (POST, GET, DELETE),
  for Volcengine Ark only (isArk, not a remote magpie), at the paths it
  makes images and videos at: POST images/generations; POST/GET
  contents/generations/tasks (with Ark's query); GET/DELETE
  contents/generations/tasks/<id> (nativeArkPath). Never Ark's chat,
  whose routing, usage and masking are the chat routes'. Another
  provider or path is a 404 that says what is served.
- Behind every guard a /v1 route has (a key beyond loopback, corsGuard,
  the key's rate), and refused to a read-only key (readOnlyRefused).
- Refused (403) to a key held to models, accounts or a spend limit, or
  issued by one (nativeHeld): a poll or a cancel can't be tied to a
  model, and magpie prices no answer it doesn't read, so it couldn't
  hold such a key to them. Such keys use /v1/images/generations and
  /v1/videos, which now pass the vendor's own fields on.
- A model the user switched off is refused. The body's strings are
  masked (fails closed) and put back in the answer (restoring); numbers
  go exact (UseNumber, a 17-digit seed is kept).
- Signed with the provider's key and magpie's User-Agent; no caller
  header goes on but Accept. The answer comes back as it came, an event
  stream flushed as it arrives.
- Each request is a Requests row and a usage record (Operation
  "native", no tokens).

Tests: TestNativeArkRoute (the stream, the task list's query and a
cancel reach Ark signed with the provider's key, the body as sent; chat,
a wrong method, a deeper path, another provider, an unknown one and
every held key are refused without Ark being asked),
TestNativeArkStreamsAsItComes (the first event reaches the caller while
Ark holds the rest), TestReadOnlyKeyEveryRoute (the three patterns in
readOnlyRefused). Docs: gateway-routing.md's native route section.

Run on mote at the head of this stack (the Ark video fields, the native
route and the Ark image fields, three commits on af9ac3d25):
- go test -count=1 -timeout 45m ./internal/gateway ./internal/gui
  ./internal/access: gateway and access ok; gui red only in
  TestMainWindowCorners/macOS_26_SDK (#3949, red on main).
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./...: clean. gofmt -l: nothing.
- No GUI file or script changes in this stack, so no GUI run.
The commits between were not run on their own at this base.

Broken by hand, each red, then put back:
- nativeHeld skipped: TestNativeArkRoute red
- an issuer's hold not read: TestNativeArkRoute red
- nativeArkPath skipped: TestNativeArkRoute red
- isArk not checked: TestNativeArkRoute red
- no flush: TestNativeArkStreamsAsItComes red (its 30s bound)
- the DELETE pattern out of readOnlyRefused: TestReadOnlyKeyEveryRoute red

Not tried: no real Ark request through the route (it would spend money);
Ark's answers are a fake shaped from its docs.

Credit: axelburks on Discord.
This commit is contained in:
yetone
2026-11-03 18:46:54 +08:00
parent b2034c1bcf
commit db87e014f2
5 changed files with 408 additions and 1 deletions
+23
View File
@@ -695,6 +695,7 @@ the MCP and an HTTP caller go through one translation and one set of holds.
| `POST /v1/videos` | JSON or OpenAI's multipart: `model`, `prompt`, `seconds`, `size`, `input_reference` (first frame), plus `last_frame` and `reference_images` | OpenAI's video object, `status: "queued"`, an id that names the provider, the vendor's task and the key or account |
| `GET /v1/videos/{id}` | | the video object: `queued`, `in_progress` (`progress`), `completed` or `failed` (`error`) |
| `GET /v1/videos/{id}/content` | | the video (`video/mp4`, or `video/quicktime` for a MOV: `videoType`), or 409 while it isn't made |
| `POST`, `GET`, `DELETE /v1/magpie/native/{provider}/{path...}` | the vendor's own request | the vendor's own answer, a stream as it comes (`native.go`, below) |
Each vendor is sent its own request:
@@ -782,6 +783,28 @@ that URL (`vendorClient`) and serves a MOV as `video/quicktime`
`TestOnlyArkTakesItsOwnVideoAsks`, `TestArkVideoSize`,
`TestArkVideoAnswersItsOwnFields`, `TestVideoType`.
#### The native route
`/v1/magpie/native/{provider}/{path...}` ([`native.go`](../../internal/gateway/native.go))
passes a request to the provider's own API as it is, and its answer back
as it came, an event stream flushed as it arrives: for what the OpenAI
shape can't carry (Ark's image stream, its task list and cancel, a field
newer than magpie). It is served for Volcengine Ark only (`isArk`, not a
remote magpie), at `images/generations` (POST),
`contents/generations/tasks` (POST, GET with Ark's query) and
`contents/generations/tasks/<id>` (GET, DELETE) under the key's base
(`nativeArkPath`); any other provider or path is a 404 that says what is
served. It is behind the gateway's guards as every route is (a key beyond
loopback, corsGuard, the key's rate), refused to a read-only key
(`readOnlyRefused`), and refused (403, `nativeHeld`) to a key held to
models, accounts or a spend limit, or issued by one: magpie can't tell
which model a poll or a cancel is of, and prices no answer it doesn't
read, so the OpenAI routes serve such a key. A model the user switched off
is refused. The body's strings are masked (fails closed) and put back in
the answer (`restoring`), numbers kept exact (`UseNumber`). It is signed
with the provider's key and magpie's User-Agent, never the caller's
headers, and each request is a Requests row and a usage record
(`Operation: "native"`, no tokens). `TestNativeArkRoute`, `TestNativeArkStreamsAsItComes`.
A MiniMax API key (no account, a Chat, Anthropic or Responses base on
api.minimax.io, api.minimaxi.com or api.minimax.cn: `filmsMiniMax`,