Add OpenCode Go provider#54
Open
mulfyx wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add OpenCode Go provider
Closes #46.
Summary
chat/completionsor Anthropic-compatiblemessages.opencode-go/<model-id>names and unambiguous bare model IDs.Routing and authentication
OpenCode Go splits one subscription catalog across two upstream APIs:
/chat/completionsAuthorization: Bearer ...glm-5.2,glm-5.1,glm-5,kimi-k2.7-code,kimi-k2.6,kimi-k2.5,deepseek-v4-pro,deepseek-v4-flash,mimo-v2.5,mimo-v2.5-pro/messagesx-api-key+anthropic-versionminimax-m3,minimax-m2.7,minimax-m2.5,qwen3.7-max,qwen3.7-plus,qwen3.6-plus,qwen3.5-plusThe API key is resolved in this order:
CCP_OPENCODE_API_KEYOPENCODE_API_KEYopencode.apiKeyinconfig.jsonCCP_OPENCODE_BASE_URLoropencode.baseUrlcan override the defaulthttps://opencode.ai/zen/go/v1base URL.The canonical
opencode-go/prefix can always be used to force this provider. Bare IDs are also registered where they do not conflict with an existing provider. In particular, barekimi-k2.6remains assigned to the existing Kimi provider, whileopencode-go/kimi-k2.6selects OpenCode Go.The current OpenCode documentation lists 14 endpoint assignments. Live
/modelsdiscovery also returned three older IDs that still completed real requests:glm-5,kimi-k2.5, andqwen3.5-plus. Three other discovered IDs were deliberately not advertised because direct requests failed:mimo-v2-pro,mimo-v2-omni, andhy3-preview.Protocol handling
role: systemmessages are merged with the top-level system prompt before translation.minimax-m3receives OpenCode's defaultthinking: {"type":"adaptive"}when the caller does not provide athinkingoption; an explicit caller value is preserved unchanged./v1/messages/count_tokensis handled locally and does not consume OpenCode Go quota.429responses map torate_limit_errorand preserveRetry-After.The provider intentionally keeps a static reviewed model catalog and does not add a runtime
models.devdependency. This change also does not introduce a new output-token truncation policy.Tool-call streaming fix
End-to-end Claude Code testing exposed a pre-existing bug in the shared OpenAI-compatible SSE reducer. Upstream tool-call argument fragments are keyed by the upstream tool index, but the reducer previously looked up later fragments using the generated Anthropic content-block index. If a thinking or text block appeared before the tool call, Claude Code could receive an empty tool input such as
Read {}orBash {}.The reducer now tracks both indices independently and matches argument fragments by the upstream tool index. A regression test covers a reasoning block followed by a fragmented tool call. This also hardens the existing Kimi translation path.
Verification
cargo test --all-targets: 604 passed, 0 failed.qwen3.5-plusMessages route and verify that the MiniMax adaptive-thinking fallback does not overwrite caller-supplied thinking.2.1.207smoke tests on the current implementation passed for all 17 supported models.Read,Write, Bash auto-review, Bash execution, and final result verification.sorted()and.sort().stream_eventoutput. The run and one clean retry after a Claude Code auto-review timeout recorded 115 successful OpenCode Go upstream requests across all 17 models, with no failed or non-2xx requests.glm-5.2,qwen3.5-plus, andminimax-m3as representatives of both upstream protocols and the adaptive-thinking path; all three streamed successfully with HTTP 200 and no proxy errors.cargo fmt --all -- --checkpasses.git diff --checkpasses.References
streamTextand consumesfullStreamqwen3.5-plusis declared with the Anthropic provider protocolminimax-m3