Skip to content

OpenCode cannot connect to LAN-hosted Ollama on macOS while curl works #38854

Closed as not planned

Description

@X-citizen-snips-X

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:

curl http://10.0.42.149:11434/v1/models

returns the available models.

curl http://10.0.42.149:11434/v1/chat/completions

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:

http://127.0.0.1:11435/v1

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

  1. Install OpenCode 1.18.0 on macOS.
  2. 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"
}
  1. Verify the Ollama endpoint is reachable:

curl http://10.0.42.149:11434/v1/models

This should return the model list.

  1. Verify chat completions work:

curl http://10.0.42.149:11434/v1/chat/completions

This should return a valid response.

  1. 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

  1. github-actions commented on Jul 25, 2026

    @github-actions
    Contributor

    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.

  2. X-citizen-snips-X commented on Jul 25, 2026

    @X-citizen-snips-X
    Author

    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.

  3. sverasch commented on Sep 10, 2026

    @sverasch

    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

  4. bgausden commented on Sep 16, 2026

    @bgausden

    ** 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:

    • Git HTTP, Homebrew Python, Apple Command Line Tools Python, and a freshly compiled C program calling connect() all fail immediately when connecting to a host on the local Ethernet subnet.
    • Each receives EHOSTUNREACH / errno 65.
    • /usr/bin/curl, /usr/bin/nc, and /usr/bin/ssh connect successfully to the same host and port.
    • No packet appears on either the Ethernet or VPN interface during a failed call, so the denial occurs before transmission.
    • Disconnecting the VPN does not change the result.
    • An SSH Git remote works because the Apple platform SSH client can access the LAN.

    The process ancestry for affected tool calls is:

    tool process → zsh → opencode.exe serve --service → launchd
    

    The installed OpenCode executable is Developer ID signed, but inspection reports:

    Identifier=opencode
    TeamIdentifier=5NZ4Q7NXJ4
    Info.plist=not bound
    

    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 misleading EHOSTUNREACH.

    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:

    1. Embed a bound Info.plist in the macOS CLI executable with a stable bundle identifier and NSLocalNetworkUsageDescription.
    2. Ensure the managed serve --service process retains that responsible-code identity when registered and launched.
    3. On an apparent NECP Local Network denial, show an actionable message directing the user to System Settings → Privacy & Security → Local Network.

    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

    • On a clean macOS 27 profile, the first LAN operation from the managed service presents a Local Network permission request attributable to OpenCode.
    • After selecting Allow, an OpenCode provider, remote MCP connection, and spawned non-platform child process can each connect directly to a reachable RFC1918 host.
    • After selecting Don’t Allow, OpenCode reports that Local Network permission is required instead of suggesting that the URL or port is wrong.
    • The permission remains effective after restarting the OpenCode service and after rebooting macOS.
    • Public-internet and loopback connections continue to work whether Local Network access is allowed or denied.
    • The shipped macOS executable contains a bound usage description and stable signing identity.

    Out of scope

    • General VPN/TUN routing failures.
    • Remote-host firewall or service configuration.
    • The separate desktop-app sandbox issue.

    Dependencies

    Testing requires a macOS 27 machine and a reachable service on another LAN host. No implementation blocker identified.

  5. tedivm commented on Sep 26, 2026

    @tedivm

    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.

  6. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    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 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions