diff --git a/app/(chat)/api/chat/route.ts b/app/(chat)/api/chat/route.ts index 677611f59..4ac130ddd 100644 --- a/app/(chat)/api/chat/route.ts +++ b/app/(chat)/api/chat/route.ts @@ -7972,14 +7972,16 @@ export async function POST(request: Request) { // ========== Gemini 处理结束 ========== // ========== 阿里云千问图片生成独立处理 ========== - const isAlibabaLikeImageProvider = [ - "alibaba-image", - "ruxa-image", - "fal-image", - "openai-image", - "midjourney", - "runway", - ].includes((languageModel as any).provider); + const isAlibabaLikeImageProvider = + isImageGenerationModel && + [ + "alibaba-image", + "ruxa-image", + "fal-image", + "openai-image", + "midjourney", + "runway", + ].includes((languageModel as any).provider); if (isAlibabaLikeImageProvider && typeof (languageModel as any).doGenerate === "function") { console.log("[Chat API] Using image generation provider:", (languageModel as any).provider); console.log("[Chat API] Image params:", effectiveImageParams); diff --git a/lib/ai/providers/runway.ts b/lib/ai/providers/runway.ts index 96fd84e8c..9c17e2f37 100644 --- a/lib/ai/providers/runway.ts +++ b/lib/ai/providers/runway.ts @@ -71,8 +71,9 @@ function joinEndpoint(baseURL: string, path: string) { } function buildHeaders(apiKey: string) { + const normalizedApiKey = normalizeRunwayCredentials(apiKey); return { - Authorization: `Bearer ${String(apiKey || "").trim()}`, + Authorization: `Bearer ${normalizedApiKey}`, "Content-Type": "application/json", "X-Runway-Version": RUNWAY_VERSION, }; @@ -82,6 +83,14 @@ function normalizeText(value: string) { return String(value || "").replace(/\u00a0/g, " ").trim().normalize("NFKC"); } +function normalizeRunwayCredentials(apiKey: string) { + const normalized = normalizeText(apiKey); + const stripped = normalized.replace(/^bearer\s+/i, "").replace(/^key\s+/i, ""); + const kvMatch = stripped.match(/^(?:runway[_-]?api[_-]?key|api[_-]?key|token)\s*[::]\s*(.+)$/i); + const candidate = kvMatch?.[1] ? kvMatch[1] : stripped; + return candidate.trim().replace(/[^\x20-\x7E]/g, ""); +} + function normalizeImageSizeLabel(imageSize?: string): "1K" | "2K" | "4K" { const normalized = String(imageSize || "").trim().toUpperCase(); if (normalized === "1K" || normalized === "2K" || normalized === "4K") {