feat: add cloudflare ai gateway provider

This commit is contained in:
Peter Steinberger
2026-02-04 04:10:13 -08:00
parent 19ecdce275
commit 5b0851ebd8
28 changed files with 663 additions and 9 deletions

View File

@@ -10,6 +10,7 @@ import { buildTokenProfileId, validateAnthropicSetupToken } from "../../auth-tok
import { applyGoogleGeminiModelDefault } from "../../google-gemini-model-default.js";
import {
applyAuthProfileConfig,
applyCloudflareAiGatewayConfig,
applyKimiCodeConfig,
applyMinimaxApiConfig,
applyMinimaxConfig,
@@ -23,6 +24,7 @@ import {
applyXiaomiConfig,
applyZaiConfig,
setAnthropicApiKey,
setCloudflareAiGatewayConfig,
setGeminiApiKey,
setKimiCodingApiKey,
setMinimaxApiKey,
@@ -281,6 +283,44 @@ export async function applyNonInteractiveAuthChoice(params: {
return applyVercelAiGatewayConfig(nextConfig);
}
if (authChoice === "cloudflare-ai-gateway-api-key") {
const accountId = opts.cloudflareAiGatewayAccountId?.trim() ?? "";
const gatewayId = opts.cloudflareAiGatewayGatewayId?.trim() ?? "";
if (!accountId || !gatewayId) {
runtime.error(
[
'Auth choice "cloudflare-ai-gateway-api-key" requires Account ID and Gateway ID.',
"Use --cloudflare-ai-gateway-account-id and --cloudflare-ai-gateway-gateway-id.",
].join("\n"),
);
runtime.exit(1);
return null;
}
const resolved = await resolveNonInteractiveApiKey({
provider: "cloudflare-ai-gateway",
cfg: baseConfig,
flagValue: opts.cloudflareAiGatewayApiKey,
flagName: "--cloudflare-ai-gateway-api-key",
envVar: "CLOUDFLARE_AI_GATEWAY_API_KEY",
runtime,
});
if (!resolved) {
return null;
}
if (resolved.source !== "profile") {
await setCloudflareAiGatewayConfig(accountId, gatewayId, resolved.key);
}
nextConfig = applyAuthProfileConfig(nextConfig, {
profileId: "cloudflare-ai-gateway:default",
provider: "cloudflare-ai-gateway",
mode: "api_key",
});
return applyCloudflareAiGatewayConfig(nextConfig, {
accountId,
gatewayId,
});
}
if (authChoice === "moonshot-api-key") {
const resolved = await resolveNonInteractiveApiKey({
provider: "moonshot",