fix(core): send the Cloudflare AI Gateway gatewayApiKey

This commit is contained in:
Dan Smolsky
2026-11-07 06:45:21 -05:00
Unverified
parent c72ce6cf82
commit 2302dcca62
2 changed files with 21 additions and 3 deletions
+6 -3
View File
@@ -548,9 +548,12 @@ export const layer = Layer.effect(
)
function hasConfiguredAuth(model: RuntimeInfo) {
return [model.settings?.apiKey, model.settings?.authToken, model.settings?.accessToken].some(
(value) => typeof value === "string" && value !== "",
)
return [
model.settings?.apiKey,
model.settings?.gatewayApiKey,
model.settings?.authToken,
model.settings?.accessToken,
].some((value) => typeof value === "string" && value !== "")
}
const API_KEY_AUTH_PACKAGES: ReadonlySet<string> = new Set([
+15
View File
@@ -423,6 +423,21 @@ describe("ModelResolver", () => {
expect(headers["x-goog-api-key"]).toBeUndefined()
}),
)
const gateway = yield* resolver.resolveModel(
model("@opencode/ai/providers/cloudflare-ai-gateway", {
providerID: Provider.ID.make("gateway"),
settings: { baseURL: "https://gateway.example.com/v1/compat", gatewayApiKey: "gateway-fixture" },
}),
)
const headers = yield* gateway.model.route.auth.apply({
request: ai.request({ model: gateway.model, prompt: "Hello" }),
method: "POST",
url: gateway.model.route.endpoint.baseURL ?? "",
body: "{}",
headers: Headers.fromInput(gateway.model.options?.headers),
})
expect(headers.authorization).toBe("Bearer gateway-fixture")
}).pipe(Effect.provide(layer)),
)
})