diff --git a/internal/gateway/upstream.go b/internal/gateway/upstream.go index 04075d3..2f37df1 100644 --- a/internal/gateway/upstream.go +++ b/internal/gateway/upstream.go @@ -1369,6 +1369,9 @@ func (g *Gateway) recordUpstreamAttempt(ctx context.Context, route models.Route, // lane passes anonymousZenKey. func upstreamRequest(ctx context.Context, baseURL string, protocol wire.Protocol, body []byte, ids identity.RequestIDs, key string) (*http.Request, error) { endpoint := strings.TrimRight(baseURL, "/") + wire.Path(protocol) + if !models.IsV1Upstream(baseURL) { + endpoint = strings.TrimRight(baseURL, "/") + v2EndpointPath(baseURL, protocol) + } if protocol == wire.Anthropic && !models.IsV1Upstream(baseURL) { endpoint = withAnthropicBeta(endpoint) } @@ -1394,6 +1397,24 @@ func upstreamRequest(ctx context.Context, baseURL string, protocol wire.Protocol return req, nil } +// v2EndpointPath returns the route a 2.1 client posts to on a v2 origin. The +// 2.1 client groups /inference routes by provider family, so the family +// segment sits between the origin and the protocol path (a 2.0.32 client +// posted the protocol path directly, and that route still answers). Origins +// that are not the /inference gateway — a custom base, or /zen/go — keep the +// flat route, because the family grouping is specific to /inference. +func v2EndpointPath(baseURL string, protocol wire.Protocol) string { + parsed, err := url.Parse(baseURL) + if err != nil || !strings.HasSuffix(strings.TrimRight(parsed.Path, "/"), "/inference") { + return wire.Path(protocol) + } + family := "openai" + if protocol == wire.Anthropic { + family = "anthropic" + } + return "/" + family + wire.Path(protocol) +} + // withAnthropicBeta marks an Anthropic endpoint as beta the way the OpenCode // 2.x client does, preserving any query a configured base URL already carries. func withAnthropicBeta(endpoint string) string { diff --git a/internal/httpx/client.go b/internal/httpx/client.go index c8aa2b8..dcf6172 100644 --- a/internal/httpx/client.go +++ b/internal/httpx/client.go @@ -4,7 +4,7 @@ package httpx // 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.0.32" +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.