anomalyco / anomalyco/opencode

Moonshot/Kimi models hang or fail in OpenCode while direct streaming via cURL works

Open
#41,273 2 comments 1 reaction 1 assignee View on GitHub

@rekram1-node is already working on this.

Since Aug 8, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

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:

  1. OpenCode's built-in Moonshot AI provider
  2. 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

  1. Is this a known issue with the Moonshot provider or @ai-sdk/openai-compatible?
  2. Does OpenCode add any stream_options, temperature, reasoning, tool/schema, or other parameters that may be incompatible with Moonshot's current API?
  3. Is there a recommended compatibility configuration for Moonshot/Kimi?
  4. 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
  1. Configure the built-in Moonshot AI provider in OpenCode and authenticate using a valid Moonshot/Kimi API key from platform.kimi.ai.

  2. Select a Kimi model (tested with kimi-k2.6, kimi-k2.7-code, and kimi-k3).

  3. Send a simple prompt such as "Reply with exactly: OK".

  4. OpenCode hangs and does not return a response, or eventually reports:
    "Cannot connect to API: The socket connection was closed unexpectedly."

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

  6. Test the same API key and endpoint directly with cURL from the same Mac and network.

  7. Direct requests to /v1/models return HTTP 200.

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.