feat: reach the model through the AI Gateway instead of a direct provider - #78
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
I hit an error while handling your request (Model provider API error: Authentication Fails, Your api key: ****53a6 is invalid). Please try again, rephrase, or reach out if it keeps failing. Error id: b7c8dba7-d56c-4c69-98dc-99d420a9bfd5 |
|
This session could not recover from an error (Model provider API error: Authentication Fails, Your api key: ****53a6 is invalid). Start a new comment to continue. Error id: b7c8dba7-d56c-4c69-98dc-99d420a9bfd5 |
Re-checked against the live account — still blocked, and it is the only blockerThe batch merged around this one (#70 as Probed the gateway again just now with the account's So the free tier is live and the credential is valid — it is model access, not the key. Failover does not help either: the refusal is Three ways out, in the order I would rank them:
Leaving this open and unmerged: merging it as-is trades a legible 401 for a 403 and deletes the direct-provider path, which is the one a replacement key fixes today. Say which of the three you want and this is a short follow-up either way. |
…ider Computer built a direct `createOpenAICompatible` client against `api.deepseek.com` behind a single `DEEPSEEK_API_KEY`. One revoked key took the whole agent down with a 401 and there was no second path to the model. The agent now selects the AI Gateway id `deepseek/deepseek-v4.1-flash`, so provider choice and retry move out of this repo: the gateway resolves the slug to one of its upstream providers and fails the request over to another provider serving the same model when one is unavailable. The runtime credential becomes `AI_GATEWAY_API_KEY` (falling back to Vercel's injected `VERCEL_OIDC_TOKEN`), which is no longer tied to one upstream provider account. `COMPUTER_MODEL` overrides the slug. The thinking-mode pin travels as the provider option `providerOptions.deepseek.thinking` instead of a fetch middleware that rewrote the request body; `DEEPSEEK_THINKING` still selects the value, and all six roles share the pin so no role silently runs with thinking ON. Preflight now probes the gateway and names the credential-path failures a call can hit: a 401 reports an unusable key or OIDC token, and a 403 reports that the model needs purchased AI Gateway credits.
The projection's llm_config is declared by hand in agent/agent-file-declaration.json, and this branch made it stale: it still named the DeepSeek provider, endpoint, and API id, and its note pointed at lib/deepseek.ts, which this branch deletes. The committed computer.af therefore described a direct-provider agent while the runtime reaches the gateway. Declare the gateway as the endpoint and the id as the handle, restore the cross-check the projection's own header comment promises (the declared handle against lib/gateway.ts), and regenerate computer.af.
106c386 to
2c4f5c1
Compare
Rebasing done — mechanism ready, still blocked on the account reaching the modelRebased onto Rebase
Blocker is unchanged and I re-probed it today
So both lanes are closed right now: the direct path on The decision I need from you, in order of cost
Say which and I will do it. I have not merged anything to |
Filed against the recommendation on #77. The wiring is in place and verified; the model itself is not reachable on the current account, so this does not restore service on its own — see the blocker below.
What changed
agent/lib/models.tsselects the AI Gateway iddeepseek/deepseek-v4.1-flashfor all six roles;COMPUTER_MODELoverrides it.lib/deepseek.ts(thecreateOpenAICompatible+DEEPSEEK_BASE_URL+ fetch-middleware seam) is replaced bylib/gateway.ts.providerOptions.deepseek.thinking— the native AI SDK option for@ai-sdk/deepseek— instead of rewriting every request body at the fetch layer.DEEPSEEK_THINKINGstill selects the value. All six roles share the pin.provider: deepseek,model_endpoint: https://api.deepseek.com) and a note pointing atlib/deepseek.ts, which this branch deletes.agent/agent-file-declaration.jsonnow declares the gateway endpoint and id, andlib/agent-file.test.tsasserts the declared handle and endpoint againstlib/gateway.tsso the published file cannot drift from the runtime again.AI_GATEWAY_API_KEY(or Vercel's injectedVERCEL_OIDC_TOKEN);DEEPSEEK_API_KEYis no longer read.Verification
node --test lib/*.test.ts— 168 pass on this branch (mainat1835765runs 165).pnpm run typecheckclean,pnpm run build:eveclean, and bothcheck:agent-fileandcheck:data-agent-filepass, so this branch satisfieswazootech/computer#75's gate.1835765after#70and#75landed; the only conflicts were the two doc sentences about the model configuration, resolved as the gateway wording plus#70's GitHub-sign-in sentence.eve buildcompiles; the bundle carries_libs/@ai-sdk/gateway+[...].mjsand zero references toopenai-compatibleorapi.deepseek.com.deepseek/deepseek-r1→ 200,google/gemini-2.5-flash→ 200,deepseek/deepseek-v4.1-flash→ 403.{"ok":false,"id":"deepseek/deepseek-v4.1-flash","status":403,"error":"gateway refused this model for the account (HTTP 403): the model requires purchased AI Gateway credits"}.Blocker
The team is on the AI Gateway free tier, which serves "Free Tier eligible models" only.
deepseek/deepseek-v4.1-flashis not eligible:BYOK does not route around it. Per the AI Gateway docs, BYOK is paid-tier only, and on the free tier the credential is irrelevant to model access.
So the gateway lane needs purchased AI Gateway credits before this change reaches the model. Until then, the fastest restore remains a fresh provider key on the current wiring.
This should not merge before the account can reach the model. Merging it as-is trades a 401 for a 403 and removes the direct-provider path, which is the one that a replacement key would fix today.
AI_GATEWAY_API_KEYalso is not set on the Vercel project yet.Re-probed 2026-09-22 against the live gateway and
api.deepseek.com:deepseek/deepseek-v4.1-flash→ 403 (no_providers_available, free tier),deepseek/deepseek-r1→ 200,google/gemini-2.5-flash→ 200, and the directDEEPSEEK_API_KEYonmain→ 401 with the same revoked key the deployment logs. So both lanes are closed today and neither change to this branch opens either.Unblock, in order of what costs least: (1) issue a replacement provider key and set
DEEPSEEK_API_KEY— restoresmainwith no code change, and this branch is not needed for it; (2) purchase AI Gateway credits — then this branch is the right lane and needs onlyAI_GATEWAY_API_KEYon the project; (3) if neither is available today, a free-tier-eligible gateway model (deepseek/deepseek-r1andgoogle/gemini-2.5-flashboth answered 200 on the free tier) can restore service on this branch's wiring, at the cost of running a different model than the one this repository pins.Follow-up, not settled here
The pin is expressed as
providerOptions.deepseek.thinking, which only takes effect when the gateway routes to the first-party DeepSeek provider. Whether a routing decision to another upstream preserves or ignores it is unverified — it cannot be tested until the model is reachable.