From 53d2f605e7d6de203e3ea6d2082db8bf4291ec46 Mon Sep 17 00:00:00 2001 From: ssw Date: Tue, 7 Jul 2026 04:09:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(ssw-common):=20SswLLMClient=20Anthropic=20X?= =?UTF-8?q?-Api-Key=20header=20(BS-=E6=96=B064,=20v0.17)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 根因 今天 minimax 默认走 Anthropic 端点 (api.minimaxi.com/anthropic), 401 错误: 'login fail: Please carry the API secret key in the X-Api-Key field of the request header' 旧代码用 'Authorization: Bearer' (OpenAI 协议), minimax anthropic 不接受. ## 修复 按协议分支设置 Authorization header: - OpenAI 兼容 (deepseek/jnpf官方/oa-compatible 等): 'Authorization: Bearer' - Anthropic 兼容 (minimax/anthropic 官方): 'X-Api-Key' + 'anthropic-version: 2023-06-01' ## base_ai 配置 base_ai 表 minimaxi 行的 credential 用过期 token (51 字符), 当前会话 ANTHROPIC_AUTH_TOKEN 是新 token (125 字符). 需 SQL UPDATE base_ai.credential 同步环境变量. ## 验证 1. mvn package -pl jnpf-admin -DskipTests ✅ 2. 重启 jnpf-admin (23s) 3. POST /api/ssw/ai/repair → 200 OK, 返回完整 form schema 4. dacli form create --ai '<描述>' --autoRelease 端到端跑通 ✅ - NCPF 400 → SSW fallback → minimax/anthropic → form 自动建表成功 - id=843949917733912901, enCode=testForm --- .../main/java/ssw/common/util/SswLLMClient.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ssw-common/ssw-common-biz/src/main/java/ssw/common/util/SswLLMClient.java b/ssw-common/ssw-common-biz/src/main/java/ssw/common/util/SswLLMClient.java index 3ddede6..102e472 100644 --- a/ssw-common/ssw-common-biz/src/main/java/ssw/common/util/SswLLMClient.java +++ b/ssw-common/ssw-common-biz/src/main/java/ssw/common/util/SswLLMClient.java @@ -101,12 +101,16 @@ public class SswLLMClient { String requestBody = isAnthropic ? toAnthropicBody(model, systemPrompt, userPrompt, maxTokens) : body.toJSONString(); - HttpResponse resp = HttpRequest.post(url) - .header("Authorization", "Bearer " + credential) - .header("Content-Type", "application/json") - .body(requestBody) - .timeout(READ_TIMEOUT * 1000) - .execute(); + // v0.17+ (2026-07-06): minimax anthropic 端点要求 X-Api-Key header + // (实测 401: 'Please carry the API secret key in the X-Api-Key field') + HttpRequest req = HttpRequest.post(url).header("Content-Type", "application/json"); + if (isAnthropic) { + req = req.header("X-Api-Key", credential) + .header("anthropic-version", "2023-06-01"); + } else { + req = req.header("Authorization", "Bearer " + credential); + } + HttpResponse resp = req.body(requestBody).timeout(READ_TIMEOUT * 1000).execute(); if (!resp.isOk()) { log.error("[SswLLMClient] HTTP {} body={}", resp.getStatus(), resp.body());