Skip to content

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

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

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