Skip to content

Commit b259019

Browse files
committed
fix(console): proxy inference without parsing
1 parent 3a31c4e commit b259019

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

  • packages/console/app/src/routes/zen/util

packages/console/app/src/routes/zen/util/handler.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ export async function handler(
8686
type ProviderInfo = Awaited<ReturnType<typeof selectProvider>>
8787
type CostInfo = ReturnType<typeof calculateCost>
8888

89+
const proxyUrl = new URL(input.request.url)
90+
if (proxyUrl.pathname.startsWith("/zen/")) {
91+
const protocol = opts.format === "anthropic" ? "anthropic" : opts.format === "google" ? "google" : "openai"
92+
proxyUrl.pathname = proxyUrl.pathname.replace(
93+
/^\/zen(?:\/go)?\/v1/,
94+
`/inference/${opts.modelList === "lite" ? "go/" : ""}${protocol}/${protocol === "google" ? "v1beta" : "v1"}`,
95+
)
96+
const request = new Request(proxyUrl, input.request)
97+
const ip = request.headers.get("x-real-ip")
98+
if (ip) request.headers.set("x-zen-ip", ip)
99+
const requestID = request.headers.get("x-opencode-request")
100+
if (requestID) request.headers.set("x-opencode-request-id", requestID)
101+
if (request.headers.get("authorization")?.toLowerCase() === "bearer public")
102+
request.headers.delete("authorization")
103+
if (request.headers.get("x-api-key") === "public") request.headers.delete("x-api-key")
104+
if (request.headers.get("x-goog-api-key") === "public") request.headers.delete("x-goog-api-key")
105+
return fetch(request)
106+
}
107+
89108
const MAX_FAILOVER_RETRIES = 3
90109
const MAX_RETRYABLE_STATUS_RETRIES = 3
91110
const dict = i18n(localeFromRequest(input.request))

0 commit comments

Comments
 (0)