Repository navigation
Description
Description
OpenCode 1.18.0 and 1.18.5 on macOS cannot connect directly to an Ollama server hosted on another machine on the same LAN.
The Ollama server itself is working correctly:
returns the available models.
returns a valid completion.
Basic connectivity also works:
ping 10.0.42.149
nc -vz 10.0.42.149 11434
However, OpenCode fails with:
AI_APICallError: Cannot connect to API:
Was there a typo in the url or port?
or hangs at:
build · ornith:9b
The same failure occurs with direct Node and Bun socket tests:
Node: EHOSTUNREACH
Bun: FailedToOpenSocket
The only workaround was to create an SSH tunnel:
ssh -L 127.0.0.1:11435:127.0.0.1:11434 [email protected]
and change the OpenCode provider URL to:
OpenCode then worked immediately:
build · ornith:9b
hello
This appears to be a LAN socket connectivity issue affecting OpenCode’s runtime on macOS. The current error message is also misleading because the URL, port, provider configuration, and Ollama server are all valid.
Plugins
"plugin": []
OpenCode version
1.18.0
Steps to reproduce
Steps to Reproduce
- Install OpenCode 1.18.0 on macOS.
- Configure an OpenAI-compatible provider that points to an Ollama server hosted on another machine on the local network.
Example:
{
"provider": {
"littlered": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "http://10.0.42.149:11434/v1"
}
}
},
"model": "littlered/ornith:9b"
}- Verify the Ollama endpoint is reachable:
This should return the model list.
- Verify chat completions work:
This should return a valid response.
- Run OpenCode:
opencode run --model littlered/ornith:9b "Reply with exactly: hello"
Actual Result
OpenCode either hangs indefinitely at:
build · ornith:9b
or reports:
AI_APICallError: Cannot connect to API:
Was there a typo in the url or port?
Expected Result
OpenCode should connect to the LAN-hosted Ollama server and return:
hello
Additional Notes
As a workaround, creating an SSH tunnel to localhost and changing the provider URL from:
http://10.0.42.149:11434/v1 to http://127.0.0.1:11435/v1
allowed OpenCode to work immediately with no other configuration changes.
Screenshot and/or share link
No OpenCode share link is available because the failure occurs before the model can return a response. Attached terminal output shows:
The Ollama API responding successfully through curl
OpenCode failing to connect directly to the same LAN endpoint
Bun and Node returning socket connection errors
OpenCode working immediately when the identical endpoint is forwarded through an SSH tunnel to 127.0.0.1
Troubleshooting logs -
https://drive.google.com/file/d/1PwhpxSa_3Ncc02Eea0Ujov02t-oarz6J/view?usp=drive_link
Debug Log
OpenCode failure
$ opencode --print-logs --log-level DEBUG run \
--model littlered/ornith:9b \
"Reply with exactly: hello"
timestamp=2026-07-25T04:24:31.912Z level=INFO message="creating instance" directory=<PROJECT_PATH>
timestamp=2026-07-25T04:24:31.968Z level=INFO message=loading path=<HOME>/.config/opencode/opencode.json
timestamp=2026-07-25T04:24:32.062Z level=INFO message=created version=1.18.0 directory=<PROJECT_PATH>
> build · ornith:9b
timestamp=2026-07-25T04:24:32.244Z level=INFO message=stream providerID=littlered modelID=ornith:9b small=true agent=title
timestamp=2026-07-25T04:24:32.251Z level=INFO message="llm runtime selected" llm.runtime=ai-sdk llm.provider=littlered llm.model=ornith:9b
timestamp=2026-07-25T04:24:33.037Z level=INFO message=stream providerID=littlered modelID=ornith:9b small=false agent=build
timestamp=2026-07-25T04:24:33.038Z level=INFO message="llm runtime selected" llm.runtime=ai-sdk llm.provider=littlered llm.model=ornith:9b
timestamp=2026-07-25T04:24:33.040Z level=ERROR message="stream error" error.error="AI_APICallError: Cannot connect to API: Was there a typo in the url or port? (cause: Error: Was there a typo in the url or port?)"
timestamp=2026-07-25T04:24:35.053Z level=ERROR message="stream error" error.error="AI_APICallError: Cannot connect to API: Was there a typo in the url or port?"
timestamp=2026-07-25T04:24:38.270Z level=ERROR message="stream error" small=true agent=title error.error="AI_RetryError: Failed after 3 attempts. Last error: Cannot connect to API: Was there a typo in the url or port?"
Direct Bun reproduction
const response = await fetch(
"http://<OLLAMA_LAN_IP>:11434/v1/chat/completions",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer not-needed"
},
body: JSON.stringify({
model: "ornith:9b",
messages: [
{
role: "user",
content: "Reply with exactly: hello"
}
],
stream: false
})
}
);
console.log(response.status);
console.log(await response.text());Result:
error: Was there a typo in the url or port?
path: "http://<OLLAMA_LAN_IP>:11434/v1/chat/completions"
errno: 0
code: "FailedToOpenSocket"
Bun v1.3.14 (macOS arm64)
Bun can reach public internet addresses:
$ bun -e 'console.log((await fetch("https://www.google.com")).status)'
200
Direct Node reproduction
$ node -e '
fetch("http://<OLLAMA_LAN_IP>:11434/v1/models")
.then(r => r.text())
.then(console.log)
.catch(console.error)
'
Result:
TypeError: fetch failed
[cause]: Error: connect EHOSTUNREACH <OLLAMA_LAN_IP>:11434
- Local (<MAC_LAN_IP>:<EPHEMERAL_PORT>)
errno: -65
code: "EHOSTUNREACH"
syscall: "connect"
address: "<OLLAMA_LAN_IP>"
port: 11434
Environment:
Node: v26.5.0
Bun: 1.3.14
macOS: 26.5.2
OpenCode: 1.18.0
Network connectivity succeeds
$ ping -c 2 <OLLAMA_LAN_IP>
2 packets transmitted, 2 packets received, 0.0% packet loss
$ nc -vz <OLLAMA_LAN_IP> 11434
Connection to <OLLAMA_LAN_IP> port 11434 succeeded
Ollama API succeeds with curl
$ curl -s http://<OLLAMA_LAN_IP>:11434/v1/models
Result:
{
"object": "list",
"data": [
{
"id": "ornith:35b",
"object": "model"
},
{
"id": "ornith:9b",
"object": "model"
}
]
}Chat completions also succeed:
$ curl -s http://<OLLAMA_LAN_IP>:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer not-needed" \
-d '{
"model": "ornith:9b",
"messages": [
{
"role": "user",
"content": "Reply with exactly: hello"
}
],
"stream": false
}'
Result:
{
"model": "ornith:9b",
"choices": [
{
"message": {
"role": "assistant",
"content": "hello"
},
"finish_reason": "stop"
}
]
}SSH tunnel workaround
A local SSH tunnel was created:
$ ssh -N \
-L 127.0.0.1:11435:127.0.0.1:11434 \
<USER>@<OLLAMA_LAN_IP>
The OpenCode provider URL was changed from:
http://<OLLAMA_LAN_IP>:11434/v1
to:
http://127.0.0.1:11435/v1
Bun then reached the endpoint successfully:
$ bun -e '
const response = await fetch("http://127.0.0.1:11435/v1/models");
console.log(response.status);
'
200
OpenCode also worked immediately:
$ opencode run \
--model littlered/ornith:9b \
"Reply with exactly: hello"
> build · ornith:9b
hello
No provider, model, or Ollama configuration changes were required beyond replacing the direct LAN URL with the localhost SSH tunnel.
Operating System
MacOS 26.5.2
Terminal
iTerm2
Activity
github-actions commentedon Jul 25, 2026
This issue might be a duplicate of existing issues. Please check:
The root cause appears to be Bun's embedded runtime failing to open TCP sockets to non-localhost LAN addresses on macOS, which is tracked in #37432 and #28418.
X-citizen-snips-X commentedon Jul 25, 2026
I agree this appears to be related to #28418 and possibly #37432. I intentionally included additional diagnostics because I was able to narrow the failure further.
In my case:
curl to the Ollama endpoint succeeds.
ping and nc succeed.
OpenCode selects the correct provider and model.
Standalone Bun and Node both fail to open the socket to the LAN host.
Forwarding the identical endpoint through an SSH tunnel to 127.0.0.1 allows OpenCode to work immediately with no other configuration changes.
If this is the same underlying issue, I'm happy for this to be closed as a duplicate, but hopefully the additional diagnostics help identify where the failure is occurring.
sverasch commentedon Sep 10, 2026
I had this exact issue and found that I had an iterm2 update and didn't close my terminal so the System > Privacy & Security > Local Network settings transferred to the new binary and removed from the active running binary
bgausden commentedon Sep 16, 2026
** Agent Generated **
Additional diagnostic evidence
This also reproduces with OpenCode v2.0.4 on macOS 27.0 (Darwin 27.0.0, arm64), using the managed background service.
The failure is below Bun, Node, Git, and HTTP:
connect()all fail immediately when connecting to a host on the local Ethernet subnet.EHOSTUNREACH/errno 65./usr/bin/curl,/usr/bin/nc, and/usr/bin/sshconnect successfully to the same host and port.The process ancestry for affected tool calls is:
The installed OpenCode executable is Developer ID signed, but inspection reports:
It has no embedded
NSLocalNetworkUsageDescription. This matches macOS Local Network Privacy/NECP behavior described in Apple TN3179: macOS cannot associate the detached background service with responsible code that can receive Local Network approval, and returns the misleadingEHOSTUNREACH.This evidence rules out the earlier suspected causes in this reproduction: DNS, provider configuration, Bun/Undici specifically, VPN routing, remote firewall, and an unreachable server.
Proposed change
Give the macOS CLI/service a stable identity that Local Network Privacy can authorize:
Info.plistin the macOS CLI executable with a stable bundle identifier andNSLocalNetworkUsageDescription.serve --serviceprocess retains that responsible-code identity when registered and launched.A curl fallback or SSH tunnel would only fix OpenCode-owned HTTP calls; it would not fix local MCP servers, plugins, or shell tools spawned by the background service. A system-wide CIDR exception is too broad to be the product-level fix.
Acceptance criteria
Out of scope
Dependencies
Testing requires a macOS 27 machine and a reachable service on another LAN host. No implementation blocker identified.
tedivm commentedon Sep 26, 2026
I can confirm this is an issue with OpenCode 2.0.18 as well, and is extremely frustrating. There are a lot of people who use OpenCode because they want to use local models.
thdxr commentedon Oct 11, 2026
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (
opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊