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
{{ message }}
Repository navigation
Cannot connect to API: The socket connection was closed unexpectedly #23123
When using OpenCode, API connections intermittently fail with:
Cannot connect to API: The socket connection was closed unexpectedly. For more information, pass verbose: true in the second argument to fetch()
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:
Thank 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.
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
Activity
github-actions commentedon Apr 17, 2026
This issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
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:
verbose: truein the second argument to fetch() #21643: Same error message — "Cannot connect to API: The socket connection was closed unexpectedly"If you believe this was flagged incorrectly, please let a maintainer know.
github-actions commentedon Apr 17, 2026
Thank 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.
annejan-svg commentedon Jul 29, 2026
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.
mzhmmzhm commentedon Oct 8, 2026
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
Pnlvfx commentedon Oct 21, 2026
why is this closed if it's not fixed?