HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
fix(media): submit Vercel video as a job, then poll it
richard-epsilla1ba8c15e7b95
diff --git a/gateway/app.py b/gateway/app.pyindex be29d1e6..245a54ff 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -8502,10 +8502,14 @@ async def _media_job_poll(job: dict, budget: _MediaBudget) -> dict:await _media_job_save(job)return job- method, url = media_plane.build_poll(cand, prov["base_url"], str(job["provider_task_id"]))+ poll = media_plane.build_poll(cand, prov["base_url"], str(job["provider_task_id"]))try:+ # Same rule as the submit: the shape's headers go UNDER the credential, so a catalog entry+ # can name a model and a protocol version but never an `authorization`.r = await _media_client().request(- method, url, headers=media_plane.auth_headers(prov),+ poll.method, poll.url,+ headers={**poll.headers, **media_plane.auth_headers(prov)},+ json=poll.body if poll.body is not None else None,timeout=media_plane.POLL_TIMEOUT_S)status, payload, err, progress = media_plane.read_poll(cand, r.status_code,_media_doc(r, r.content))diff --git a/gateway/media_catalog.json b/gateway/media_catalog.jsonindex 5533bcc7..c6112c71 100644--- a/gateway/media_catalog.json+++ b/gateway/media_catalog.json@@ -63,9 +63,9 @@"resolution": "854x480","accepts_input_image": false,"duration_observed_s": 5.056,- "latency_s": 116.0,+ "latency_s": 144.0,"usd": 0.5182759,- "measured": "verified e2e 2026-08-16 against the live gateway on the Future HR key: asked for 5 s at 480p and got back a presigned url to a 3,617,186 byte mp4, 854x480, h264 with an aac track it was not asked for. It HONOURS duration (5 asked, 5.056 delivered), unlike the tokenrouter seedance entry. Cost is the gateway's own number from providerMetadata.gateway.cost, not an estimate: $0.5182759 for those 48,437 completion tokens. Took 116 s inside the submit, so it is synchronous and never enters the poll walk. It takes a NAMED resolution tier, not WxH, and seedance-2.5 publishes only 480p and 720p. Declaring `size` as a tunable let the chain compute an arithmetic frame for the asked aspect (896x504 for 16:9 off this entry's own numbers), which the provider refused outright \u2014 the first live run through the kit fell back to the relay because of it. Nothing was billed: a refusal is free. `size` is therefore NOT a tunable here; the shape is fixed at the one tier that was verified, and a request for another aspect skips this candidate with a reason rather than being silently reframed.",+ "measured": "verified e2e 2026-08-16 against the live gateway on the Future HR key: asked for 5 s at 480p and got back a presigned url to a 3,617,186 byte mp4, 854x480, h264 with an aac track it was not asked for. It HONOURS duration (5 asked, 5.056 delivered), unlike the tokenrouter seedance entry. Cost is the gateway's own number from providerMetadata.gateway.cost, not an estimate: $0.5182759 for those 48,437 completion tokens. Took 116 s inside the submit, so it is synchronous and never enters the poll walk. It takes a NAMED resolution tier, not WxH, and seedance-2.5 publishes only 480p and 720p. Declaring `size` as a tunable let the chain compute an arithmetic frame for the asked aspect (896x504 for 16:9 off this entry's own numbers), which the provider refused outright \u2014 the first live run through the kit fell back to the relay because of it. Nothing was billed: a refusal is free. `size` is therefore NOT a tunable here; the shape is fixed at the one tier that was verified, and a request for another aspect skips this candidate with a reason rather than being silently reframed. ASYNC, verified live 2026-08-16: POST /v4/ai/video-model/start answers in 0.5 s with {operation:{gatewayJobId}}, and POST /v4/ai/video-model/status posts that handle back until status goes pending -> completed (144 s for this clip), returning the same 854x480 h264+aac file. The synchronous endpoint renders inside the request instead, which is ~116 s and longer than a tool call waits: the first kit run reached this model and timed out at the transport with no job id, leaving a render nobody could poll or claim. latency_s is the RENDER time and is not the submit budget.","verification": "verified"},{diff --git a/gateway/media_plane.py b/gateway/media_plane.pyindex fd9a4883..67c49367 100644--- a/gateway/media_plane.py+++ b/gateway/media_plane.py@@ -627,7 +627,11 @@ def _timeout_for(cand: dict) -> float:"""A synchronous shape renders inside the submit, so its budget is its measured latency withroom — not one number for a 4-second model and a 91-second one."""lat = cand.get("latency_s")- if str(cand.get("shape")) == "video-generation" or not isinstance(lat, (int, float)):+ # The video shapes SUBMIT a job and return in about a second; their `latency_s` is how long+ # the render takes afterwards, which is not a budget for this call. Reading it as one gave the+ # Vercel start a 348 s ceiling for a request that answers immediately.+ if str(cand.get("shape")) in ("video-generation", "vercel-video") \+ or not isinstance(lat, (int, float)):return min(SUBMIT_TIMEOUT_S, 120.0)return min(SUBMIT_TIMEOUT_S, max(60.0, float(lat) * 3.0))@@ -729,7 +733,15 @@ def build_submit(cand: dict, base_url: str, params: dict) -> Submit:img = take("image", params.get("image"))if img is not None:body["image"] = img- return Submit("POST", f"{root}/v4/ai/video-model", body, tun,+ # `/start`, NOT the plain endpoint. The plain one renders inside the request and a+ # seedance render is ~116 s, which is longer than a tool call will wait: the first run+ # through the kit reached this model and then timed out at the transport with no job+ # id, leaving a render that may have been running and could not be polled or claimed.+ # The start/status pair is what every other video candidate here already does.+ # `callbackUrl` is deliberately not sent — the SDK's own source says async video jobs+ # are polling-first, and a webhook would need a public address this instance may not+ # have.+ return Submit("POST", f"{root}/v4/ai/video-model/start", body, tun,timeout=_timeout_for(cand), headers=hdr)body = {}@@ -853,10 +865,36 @@ def build_submit(cand: dict, base_url: str, params: dict) -> Submit:raise MediaError(f"No adapter for endpoint shape {shape!r}.")-def build_poll(cand: dict, base_url: str, task_id: str) -> tuple[str, str]:- if str(cand.get("shape")) != "video-generation":- raise MediaError("Only the video shape is polled; every other shape answers inline.")- return "GET", f"{(base_url or '').rstrip('/')}/video/generations/{task_id}"+class Poll:+ """One status check. A body and headers as well as a url, because not every provider answers+ a GET: Vercel's video status is a POST carrying back the opaque handle its start returned."""++ __slots__ = ("method", "url", "headers", "body")++ def __init__(self, method: str, url: str, headers: dict | None = None,+ body: dict | None = None):+ self.method, self.url = method, url+ self.headers, self.body = headers or {}, body+++def build_poll(cand: dict, base_url: str, task_id: str) -> Poll:+ shape = str(cand.get("shape"))+ base = (base_url or "").rstrip("/")+ if shape == "video-generation":+ return Poll("GET", f"{base}/video/generations/{task_id}")+ if shape == "vercel-video":+ # `task_id` here is the whole `operation` the start returned, carried as text because that+ # is what a job vertex can hold. It is the provider's handle and nothing is read out of it:+ # it goes back exactly as it came, which is the contract the SDK's doStatus implements.+ try:+ operation = json.loads(task_id)+ except Exception as e: # noqa: BLE001+ raise MediaError("the stored video job handle is not readable") from e+ return Poll("POST", f"{_api_root(base)}/v4/ai/video-model/status",+ headers={"ai-model-id": str(cand.get("model") or ""),+ "ai-gateway-protocol-version": _VERCEL_PROTOCOL},+ body={"operation": operation})+ raise MediaError("Only the video shapes are polled; every other shape answers inline.")# ── the five adapters: reading a response ─────────────────────────────────────────@@ -1025,18 +1063,13 @@ def _read_submit(cand: dict, status: int, doc) -> tuple[str, Payload | None]:# carries the finished thing. There is no task id to poll, so `_read_submit` returns the# payload and the job never enters the polling walk at all.if shape == "vercel-video":- vids = doc.get("videos")- first = vids[0] if isinstance(vids, list) and vids and isinstance(vids[0], dict) else {}- # Measured: a 5 s 480p seedance-2.5 render answered with a presigned url, not bytes, and- # the file behind it was 3.6 MB. Both are read because the shape documents `type`.- if first.get("url"):- return "", Payload(url=str(first["url"]),- mime=str(first.get("mediaType") or "video/mp4"))- if first.get("base64") or first.get("data"):- return "", Payload(data=_b64(str(first.get("base64") or first.get("data"))),- mime=str(first.get("mediaType") or "video/mp4"))+ # The start answers with an opaque `operation` and nothing else — no url, no id we could+ # shorten. It is stored whole, as text, and posted back verbatim on every poll.+ op = doc.get("operation")+ if op is not None:+ return json.dumps(op, separators=(",", ":")), Noneraise MediaEmpty(provider_message(doc, status) or- "the provider answered with no video")+ "the provider accepted the request but returned no job handle")if shape == "vercel-speech":if doc.get("audio"):@@ -1103,6 +1136,32 @@ def _read_poll(cand: dict, status: int, doc) -> tuple[str, Payload | None, str,"""if status >= 500 or not isinstance(doc, dict) or not doc:return "unknown", None, "", ""++ if str(cand.get("shape")) == "vercel-video":+ # A discriminated union on `status`, per the SDK's own schema: pending | completed, plus+ # the terminal states a job can end in. The shape is flat — `videos` sits beside `status`,+ # not under a `data` envelope like the relay's.+ st = str(doc.get("status") or "").lower()+ if st == "completed":+ vids = doc.get("videos")+ first = (vids[0] if isinstance(vids, list) and vids and isinstance(vids[0], dict)+ else {})+ if first.get("url"):+ return "succeeded", Payload(url=str(first["url"]),+ mime=str(first.get("mediaType") or "video/mp4")), "", ""+ if first.get("base64") or first.get("data"):+ return "succeeded", Payload(+ data=_b64(str(first.get("base64") or first.get("data"))),+ mime=str(first.get("mediaType") or "video/mp4")), "", ""+ # Completed with nothing in it billed and delivered nothing. Same rule as everywhere.+ return "failed", None, "the provider reported completed and returned no video", ""+ if st in ("failed", "cancelled", "canceled"):+ return "failed", None, scrub(provider_message(doc, status)+ or f"the render ended as {st}"), ""+ if st == "pending" or not st:+ return "running", None, "", ""+ return "unknown", None, "", ""+data = doc.get("data")if not isinstance(data, dict) or not data:if status >= 400:diff --git a/gateway/tests/test_media_mcp.py b/gateway/tests/test_media_mcp.pyindex 29d63a4e..de13cdf8 100644--- a/gateway/tests/test_media_mcp.py+++ b/gateway/tests/test_media_mcp.py@@ -2434,8 +2434,16 @@ def test_a_provider_chosen_task_id_cannot_move_the_poll_to_another_host(client,if c.get("shape") == "video-generation")for hostile in ("[email protected]", "../../../../evil.example/x", "..%2f..%2fevil.example","x#@evil.example", "[email protected]"):- _method, url = media_plane.build_poll(cand, TR, hostile)- assert httpx.URL(url).host == "api.tokenrouter.com", url+ poll = media_plane.build_poll(cand, TR, hostile)+ assert httpx.URL(poll.url).host == "api.tokenrouter.com", poll.url++ # The Vercel shape cannot be steered this way at all: its handle never reaches the url. It is+ # posted in the BODY, so a hostile handle is data the provider gets back, not an address.+ vc = next(c for c in media_plane.capability("text_to_video")["candidates"]+ if c.get("shape") == "vercel-video")+ poll = media_plane.build_poll(vc, "https://ai-gateway.vercel.sh/v1", '{"id":"[email protected]"}')+ assert httpx.URL(poll.url).host == "ai-gateway.vercel.sh", poll.url+ assert poll.method == "POST" and poll.body == {"operation": {"id": "[email protected]"}}def test_the_finished_file_is_fetched_without_the_credential(client, harness, session, provider):