anomalyco / anomalyco/opencode
[Windows] @ai-sdk/openai-compatible cannot connect to localhost:9877 — Bun fetch fails for 127.0.0.1 while Node fetch works (Unable to connect. Is the computer able to access the url?)
@Hona is already working on this.
Since Jul 21, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- Avg merge
- 7h 2m
- Merged PRs (30d)
- 384
Description
Summary
On Windows, opencode's embedded Bun runtime cannot connect to a localhost @ai-sdk/openai-compatible provider at http://127.0.0.1:9877/v1. Every request fails with AI_APICallError: Cannot connect to API: Unable to connect. Is the computer able to access the url?. The same URL is reachable from Node.js fetch(), PowerShell Invoke-WebRequest, and curl on the same machine — so this is an opencode/Bun runtime issue, not a network or proxy issue.
This appears related to #28418 (@ai-sdk/openai-compatible fails to connect to LAN addresses) and #37043 (opencode ignores NO_PROXY), but this reproduces on plain 127.0.0.1 with no HTTP_PROXY/HTTPS_PROXY env vars set.
Environment
- opencode: v1.18.4 (installed via
npm i -g opencode-ai, binary atD:\node_global\opencode.ps1) - OS: Windows 11, PowerShell 5.1
- Node: v22.19.0
- Bun: installed at
D:\node_global\bun.ps1(bundled runtime used by opencode) - Provider:
@ai-sdk/openai-compatiblepointing at a local reverse proxy (commandcode-api-proxyv0.3.0) onhttp://127.0.0.1:9877/v1
Reproduction
Config (~/.config/opencode/opencode.jsonc)
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"commandcode": {
"npm": "@ai-sdk/openai-compatible",
"name": "Command Code",
"options": {
"baseURL": "http://127.0.0.1:9877/v1",
"apiKey": "proxy-managed"
},
"models": {
"deepseek-v4-pro": { "name": "DeepSeek V4 Pro" }
}
}
}
}
Steps
- Start a local OpenAI-compatible server on
127.0.0.1:9877(any will do — I usedcommandcode-api-proxy). - Launch opencode, select the
commandcodeprovider /deepseek-v4-promodel. - Send any message.
Actual
opencode retries 3× then fails:
AI_APICallError: Cannot connect to API: Unable to connect. Is the computer able to access the url?
(cause: Error: Unable to connect. Is the computer able to access the url?)
Full log (~/.local/share/opencode/log/opencode.log):
timestamp=2026-07-21T15:34:23.959Z level=ERROR message="stream error" providerID=commandcode modelID=deepseek-v4-pro error.error="AI_APICallError: Cannot connect to API: Unable to connect. Is the computer able to access the url? (cause: Error: Unable to connect. Is the computer able to access the url?)"
timestamp=2026-07-21T15:34:29.384Z level=ERROR message="stream error" providerID=commandcode modelID=deepseek-v4-pro error.error="AI_RetryError: Failed after 3 attempts. Last error: Cannot connect to API: Unable to connect. Is the computer able to access the url?"
Notably, https://models.dev/api.json also fails with the exact same error — so the Bun runtime cannot reach any URL, not just localhost:
timestamp=2026-07-21T15:34:05.945Z level=ERROR message="Failed to fetch models.dev" cause="Cause([Fail(HttpClientError: Transport error (GET https://models.dev/api.json) (cause: Error: Unable to connect. Is the computer able to access the url?))])"
Expected
opencode connects to http://127.0.0.1:9877/v1/chat/completions and returns a response.
Proof the endpoint is reachable (same machine, same moment)
Node.js fetch() — works
const r = await fetch("http://127.0.0.1:9877/health");
console.log(r.status, await r.text());
// → 200 {"status":"ok","version":"0.1.0"}
PowerShell Invoke-WebRequest — works
Invoke-WebRequest "http://127.0.0.1:9877/health" -UseBasicParsing
# → 200 {"status":"ok","version":"0.1.0"}
$body = '{"model":"deepseek/deepseek-v4-flash","messages":[{"role":"user","content":"hi"}],"stream":false,"max_tokens":20}'
Invoke-WebRequest "http://127.0.0.1:9877/v1/chat/completions" -Method POST -Headers @{Authorization="Bearer proxy-managed";"Content-Type"="application/json"} -Body $body
# → 200, valid chat completion returned
Port is listening
Get-NetTCPConnection -LocalPort 9877
# → 127.0.0.1:9877 Listen (OwningProcess confirmed)
What I've already tried
- No proxy env vars set:
HTTP_PROXY,HTTPS_PROXY,NO_PROXYare all unset (verified viaGet-ChildItem env:). - Plugin that sets
init.proxyfor non-local URLs only: I have aproxy.tsplugin that routes non-local fetches through a local HTTP proxy at127.0.0.1:60230, but it explicitly skipslocalhost/127.0.0.1/::1. Removing the plugin entirely does not fix the issue. - Both
opencode.jsonandopencode.jsonc: consolidated to a singleopencode.jsonc— no change. - Different localhost ports: tried 8787 (got
EACCES— Windows reserved range), 9877, 9876 — all fail the same way in opencode. 127.0.0.1vslocalhost: not yet tested swapping, but #28418 reports hostname also fails.
Hypothesis
opencode's embedded Bun runtime fetch() is broken for outbound HTTP on this Windows environment — it fails for both 127.0.0.1 (local proxy) and https://models.dev (public HTTPS). Node.js fetch() on the same machine works for both. This smells like a Bun-on-Windows socket/transport bug rather than a provider config issue, possibly the same class as #28418 but broader (affects public URLs too, not just LAN).
Questions / Workarounds sought
- Is there a way to force opencode to use Node's
fetchinstead of Bun's for provider calls? - Any known Windows-specific Bun fetch workaround (env var, config flag)?
- Could this be related to the bundled Bun version? If so, is there a way to override it?
Happy to run any additional diagnostics the maintainers need.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.