You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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?) #38140
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 at D:\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-compatible pointing at a local reverse proxy (commandcode-api-proxy v0.3.0) on http://127.0.0.1:9877/v1
Start a local OpenAI-compatible server on 127.0.0.1:9877 (any will do — I used commandcode-api-proxy).
Launch opencode, select the commandcode provider / deepseek-v4-pro model.
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)
No proxy env vars set: HTTP_PROXY, HTTPS_PROXY, NO_PROXY are all unset (verified via Get-ChildItem env:).
Plugin that sets init.proxy for non-local URLs only: I have a proxy.ts plugin that routes non-local fetches through a local HTTP proxy at 127.0.0.1:60230, but it explicitly skipslocalhost/127.0.0.1/::1. Removing the plugin entirely does not fix the issue.
Both opencode.json and opencode.jsonc: consolidated to a single opencode.jsonc — no change.
Different localhost ports: tried 8787 (got EACCES — Windows reserved range), 9877, 9876 — all fail the same way in opencode.
opencode's embedded Bun runtime fetch() is broken for outbound HTTP on this Windows environment — it fails for both127.0.0.1 (local proxy) andhttps://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 fetch instead 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.
Summary
On Windows, opencode's embedded Bun runtime cannot connect to a localhost
@ai-sdk/openai-compatibleprovider athttp://127.0.0.1:9877/v1. Every request fails withAI_APICallError: Cannot connect to API: Unable to connect. Is the computer able to access the url?. The same URL is reachable from Node.jsfetch(), PowerShellInvoke-WebRequest, andcurlon 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-compatiblefails to connect to LAN addresses) and #37043 (opencode ignoresNO_PROXY), but this reproduces on plain127.0.0.1with noHTTP_PROXY/HTTPS_PROXYenv vars set.Environment
npm i -g opencode-ai, binary atD:\node_global\opencode.ps1)D:\node_global\bun.ps1(bundled runtime used by opencode)@ai-sdk/openai-compatiblepointing at a local reverse proxy (commandcode-api-proxyv0.3.0) onhttp://127.0.0.1:9877/v1Reproduction
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
127.0.0.1:9877(any will do — I usedcommandcode-api-proxy).commandcodeprovider /deepseek-v4-promodel.Actual
opencode retries 3× then fails:
Full log (
~/.local/share/opencode/log/opencode.log):Notably,
https://models.dev/api.jsonalso fails with the exact same error — so the Bun runtime cannot reach any URL, not just localhost:Expected
opencode connects to
http://127.0.0.1:9877/v1/chat/completionsand returns a response.Proof the endpoint is reachable (same machine, same moment)
Node.js
fetch()— worksPowerShell
Invoke-WebRequest— worksPort is listening
What I've already tried
HTTP_PROXY,HTTPS_PROXY,NO_PROXYare all unset (verified viaGet-ChildItem env:).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.opencode.jsonandopencode.jsonc: consolidated to a singleopencode.jsonc— no change.EACCES— Windows reserved range), 9877, 9876 — all fail the same way in opencode.127.0.0.1vslocalhost: not yet tested swapping, but @ai-sdk/openai-compatible provider fails to connect to LAN addresses — FailedToOpenSocket errno:0 #28418 reports hostname also fails.Hypothesis
opencode's embedded Bun runtime
fetch()is broken for outbound HTTP on this Windows environment — it fails for both127.0.0.1(local proxy) andhttps://models.dev(public HTTPS). Node.jsfetch()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
fetchinstead of Bun's for provider calls?Happy to run any additional diagnostics the maintainers need.