Repository navigation
Cannot connect to API: The socket connection was closed unexpectedly #23123
Description
Activity
- addedcoreAnything pertaining to core functionality of the application (opencode server stuff)Anything pertaining to core functionality of the application (opencode server stuff)
on Apr 17, 2026 github-actions commented
on Apr 17, 2026 on Apr 17, 2026 – with GitHub ActionsContributorMore actionsThis issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
- No issue template was used — please use one of the three required templates: Bug Report, Feature Request, or Question
- The Bug Report template requires a proper Description field, reproduction steps, and system information (OS, version, etc.)
Please edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
- Cannot connect to API: The socket connection was closed unexpectedly. For more information, pass
verbose: truein the second argument to fetch() #21643: Same error message — "Cannot connect to API: The socket connection was closed unexpectedly" - Streaming ECONNRESET / "socket connection was closed unexpectedly" with SGLang OpenAI-compatible provider during tool-using agent runs (Qwen3.5 + reasoning content) #22803: Same "socket connection was closed unexpectedly" symptom during streaming with an OpenAI-compatible provider
If you believe this was flagged incorrectly, please let a maintainer know.
- addedneeds:complianceThis means the issue will auto-close after 2 hours.This means the issue will auto-close after 2 hours.
on Apr 17, 2026 - removedneeds:complianceThis means the issue will auto-close after 2 hours.This means the issue will auto-close after 2 hours.
on Apr 17, 2026 github-actions commented
on Apr 17, 2026 on Apr 17, 2026 – with GitHub ActionsContributorMore actionsThank you for updating the issue! It now meets our contributing guidelines and includes all the required information. We appreciate you taking the time to provide the reproduction context, version, and system details.
I face the same problem now. I has worked for a couple of hours and now the cannot connect to API Error. Installed version is 2.3.8 in Home Assistant. Any help is much appreciated.
So what's the solutions fir this issue?
So what's the solutions fir this issue?
Try uninstalling and installing, i did it with npm uninstall -g opencode-ai
Then npm install -g opencode-ai
If that doesnt work try deleting the .local folder in C:\Users\DELL if you're on windows. This would delete any configurations you set i believe. Api keys and everything. It used to work for me a few months dont know about now and the error message would come up after about a week or so, to which i did the same again
Description
When using OpenCode, API connections intermittently fail with:
This error surfaces raw
fetch()internals to the user rather than providing a meaningful error message or automatic recovery. While similar issues exist (#21643 for Zen models on QEMU, #22803 for SGLang ECONNRESET during streaming), this issue covers the general case where the underlying connection drops for any provider — including standard OpenAI/Anthropic endpoints on stable networks.The core problem is that OpenCode does not gracefully handle transient socket closures. Expected behavior would be:
Plugins
none
OpenCode version
1.4.6
Steps to reproduce
This is difficult to reproduce deterministically as it depends on network conditions, but occurs regularly in practice.
Screenshot and/or share link
No response
Operating System
Linux (various distributions)
Terminal
various