Description
Description
I am experiencing a persistent issue when using Moonshot/Kimi models in OpenCode.
Requests either hang indefinitely or eventually fail with:
Cannot connect to API:
The socket connection was closed unexpectedly
The problem occurs with both:
- OpenCode's built-in Moonshot AI provider
- A custom OpenAI-compatible provider configured with:
baseURL: https://api.moonshot.ai/v1
package: @ai-sdk/openai-compatible
Environment
- OS: macOS
- Architecture: Apple Silicon
- Install method: Homebrew
- OpenCode version: 1.18.14
- The same problem was also present on 1.17.9
- Node.js: 22.x
- Provider: Moonshot AI / custom OpenAI-compatible provider
- Account type: Kimi Open Platform prepaid / pay-as-you-go API balance
- API endpoint: https://api.moonshot.ai/v1
Models tested
The issue reproduces with:
- kimi-k2.6
- kimi-k2.7-code
- kimi-k3
What works
The Moonshot API itself works correctly from the same Mac, on the same network, with the same API key.
This request succeeds:
curl -v https://api.moonshot.ai/v1/models
-H "Authorization: Bearer $MOONSHOT_API_KEY"
It returns HTTP 200 and the full model list.
More importantly, direct streaming inference also works:
curl -N https://api.moonshot.ai/v1/chat/completions
-H "Authorization: Bearer $MOONSHOT_API_KEY"
-H "Content-Type: application/json"
-d '{
"model": "kimi-k2.6",
"messages": [
{"role": "user", "content": "Reply with exactly: OK"}
],
"stream": true
}'
The response streams correctly and terminates with:
data: [DONE]
So:
- API key is valid
- account balance is available
- DNS/network connectivity works
- TLS works
- /v1/models works
- /v1/chat/completions works
- streaming works correctly outside OpenCode
What fails
Built-in Moonshot provider:
providerID=moonshotai
modelID=kimi-k2.6 / kimi-k2.7-code
Result:
Cannot connect to API:
The socket connection was closed unexpectedly
Custom provider:
providerID=kimi-direct
package=@ai-sdk/openai-compatible
baseURL=https://api.moonshot.ai/v1
The custom provider is correctly loaded and its models are listed by OpenCode, but inference still hangs or produces the same socket error.
Troubleshooting already performed
- Upgraded OpenCode from 1.17.9 to 1.18.14
- Tested Node.js 22 and 24
- Cleared OpenCode cache
- Re-authenticated Moonshot provider
- Tested built-in Moonshot provider
- Tested custom OpenAI-compatible provider
- Explicitly set baseURL to https://api.moonshot.ai/v1
- Tested kimi-k2.6
- Tested kimi-k2.7-code
- Tested kimi-k3
- Disabled VPN
- Verified no HTTP/HTTPS/SOCKS proxy is configured
- Verified no proxy environment variables are present
- Verified direct SSE streaming through cURL works
Expected behavior
OpenCode should receive and process the same streaming response that works successfully through cURL.
Actual behavior
OpenCode hangs during inference or eventually reports:
The socket connection was closed unexpectedly
Questions
- Is this a known issue with the Moonshot provider or @ai-sdk/openai-compatible?
- Does OpenCode add any stream_options, temperature, reasoning, tool/schema, or other parameters that may be incompatible with Moonshot's current API?
- Is there a recommended compatibility configuration for Moonshot/Kimi?
- Is there a way to log the complete outgoing HTTP request body generated by OpenCode so it can be compared with the successful cURL request?
I can provide full debug logs and the opencode.jsonc configuration if needed.
Plugins
None
OpenCode version
1.18.14
Steps to reproduce
-
Configure the built-in Moonshot AI provider in OpenCode and authenticate using a valid Moonshot/Kimi API key from platform.kimi.ai.
-
Select a Kimi model (tested with kimi-k2.6, kimi-k2.7-code, and kimi-k3).
-
Send a simple prompt such as "Reply with exactly: OK".
-
OpenCode hangs and does not return a response, or eventually reports:
"Cannot connect to API: The socket connection was closed unexpectedly."
-
The same issue also occurs when using a custom OpenAI-compatible provider configured with:
baseURL: https://api.moonshot.ai/v1
package: @ai-sdk/openai-compatible
-
Test the same API key and endpoint directly with cURL from the same Mac and network.
-
Direct requests to /v1/models return HTTP 200.
-
Direct streaming requests to /v1/chat/completions work correctly, return streamed chunks, and terminate normally with:
data: [DONE]
Therefore the API key, Kimi account balance, network connection, endpoint, and Moonshot streaming API itself appear to be working. The problem only occurs when the request is made through OpenCode.
The issue occurred in OpenCode 1.17.9 and still occurs after upgrading to 1.18.14.
Screenshot and/or share link
No response
Operating System
macOS
Terminal
Apple Terminal
Description
Description
I am experiencing a persistent issue when using Moonshot/Kimi models in OpenCode.
Requests either hang indefinitely or eventually fail with:
Cannot connect to API:
The socket connection was closed unexpectedly
The problem occurs with both:
baseURL: https://api.moonshot.ai/v1
package: @ai-sdk/openai-compatible
Environment
Models tested
The issue reproduces with:
What works
The Moonshot API itself works correctly from the same Mac, on the same network, with the same API key.
This request succeeds:
curl -v https://api.moonshot.ai/v1/models
-H "Authorization: Bearer $MOONSHOT_API_KEY"
It returns HTTP 200 and the full model list.
More importantly, direct streaming inference also works:
curl -N https://api.moonshot.ai/v1/chat/completions
-H "Authorization: Bearer $MOONSHOT_API_KEY"
-H "Content-Type: application/json"
-d '{
"model": "kimi-k2.6",
"messages": [
{"role": "user", "content": "Reply with exactly: OK"}
],
"stream": true
}'
The response streams correctly and terminates with:
data: [DONE]
So:
What fails
Built-in Moonshot provider:
providerID=moonshotai
modelID=kimi-k2.6 / kimi-k2.7-code
Result:
Cannot connect to API:
The socket connection was closed unexpectedly
Custom provider:
providerID=kimi-direct
package=@ai-sdk/openai-compatible
baseURL=https://api.moonshot.ai/v1
The custom provider is correctly loaded and its models are listed by OpenCode, but inference still hangs or produces the same socket error.
Troubleshooting already performed
Expected behavior
OpenCode should receive and process the same streaming response that works successfully through cURL.
Actual behavior
OpenCode hangs during inference or eventually reports:
The socket connection was closed unexpectedly
Questions
I can provide full debug logs and the opencode.jsonc configuration if needed.
Plugins
None
OpenCode version
1.18.14
Steps to reproduce
Configure the built-in Moonshot AI provider in OpenCode and authenticate using a valid Moonshot/Kimi API key from platform.kimi.ai.
Select a Kimi model (tested with kimi-k2.6, kimi-k2.7-code, and kimi-k3).
Send a simple prompt such as "Reply with exactly: OK".
OpenCode hangs and does not return a response, or eventually reports:
"Cannot connect to API: The socket connection was closed unexpectedly."
The same issue also occurs when using a custom OpenAI-compatible provider configured with:
baseURL: https://api.moonshot.ai/v1
package: @ai-sdk/openai-compatible
Test the same API key and endpoint directly with cURL from the same Mac and network.
Direct requests to /v1/models return HTTP 200.
Direct streaming requests to /v1/chat/completions work correctly, return streamed chunks, and terminate normally with:
data: [DONE]
Therefore the API key, Kimi account balance, network connection, endpoint, and Moonshot streaming API itself appear to be working. The problem only occurs when the request is made through OpenCode.
The issue occurred in OpenCode 1.17.9 and still occurs after upgrading to 1.18.14.
Screenshot and/or share link
No response
Operating System
macOS
Terminal
Apple Terminal