Files
opencode2api/internal/httpx/client.go
T
FLYFandAiFLYF f9ef5693ab feat(upstream): follow the OpenCode 2.1 client's version and /inference routes (#141)
Captured a 2.1.1 CLI request with the plugin hook that produced the 2.0.32
capture. The body is byte-identical; what moved is the version string and the
route.

The 2.1 client groups /inference routes by provider family, so a chat request
goes to /inference/openai/v1/chat/completions, responses to
/inference/openai/v1/responses and messages to /inference/anthropic/v1/messages.
A 2.0.32 client posted the protocol path directly and that route still answers,
so this is fidelity rather than a fix.

The family segment is only inserted for the /inference origin: a custom base
URL and the /zen/go lane keep the flat route, because the grouping belongs to
/inference alone.

Co-authored-by: AiFLYF <AiFLYF@users.noreply.github.com>
2026-10-23 09:23:58 +08:00

51 lines
2.1 KiB
Go

package httpx
// v2ClientVersion is the OpenCode 2.x CLI release the gateway claims to be on
// the v2 lanes (/inference and /zen/go). Upstream accepts a range of releases
// (the version number itself is not validated), so this only needs bumping
// when it starts rejecting older ones.
const v2ClientVersion = "2.1.1"
// v1ClientVersion is the OpenCode 1.x release the gateway claims to be on the
// v1 lane (/zen), and v1BunVersion is the Bun runtime that release ships with.
// Bump them together with the provider-utils versions below, all taken from a
// captured request of the same release.
const (
v1ClientVersion = "1.19.3"
v1BunVersion = "1.3.14"
)
// The AI SDK provider packages of OpenCode 1.19.3 each bundle their own
// provider-utils, whose version ends up in the User-Agent of every v1 model
// request, so the version depends on the wire protocol.
const (
// V1ChatSDK is bundled by @ai-sdk/openai-compatible (chat completions).
V1ChatSDK = "4.0.23"
// V1ResponsesSDK is bundled by @ai-sdk/openai (responses).
V1ResponsesSDK = "4.0.40"
// V1AnthropicSDK is bundled by @ai-sdk/anthropic (messages).
V1AnthropicSDK = "4.0.46"
)
// V2UserAgent reports the gateway as an OpenCode 2.x CLI using the shape the
// v2 gate expects: "opencode/<channel>/<version>/<name>".
func V2UserAgent() string {
return "opencode/latest/" + v2ClientVersion + "/cli"
}
// V1UserAgent is the OpenCode 1.x client's own User-Agent, a bare
// "opencode/<version>", which it sends as-is on requests that bypass the AI
// SDK. The earlier "(<os> <arch>; <runtime>)" suffix carried the gateway's Go
// runtime, which no real OpenCode client sends.
func V1UserAgent() string {
return "opencode/" + v1ClientVersion
}
// V1ModelUserAgent is the User-Agent of a v1 model request: the AI SDK appends
// the provider-utils version of the package serving the request and the
// runtime to the client's own User-Agent, e.g.
// "opencode/1.19.3 ai-sdk/provider-utils/4.0.23 runtime/bun/1.3.14".
func V1ModelUserAgent(providerUtils string) string {
return V1UserAgent() + " ai-sdk/provider-utils/" + providerUtils + " runtime/bun/" + v1BunVersion
}