fix(ssw-common): SswLLMClient Anthropic X-Api-Key header (BS-新64, v0.17)

## 根因
今天 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
This commit is contained in:
ssw committed 2026-07-07 04:09:16 +08:00
1 parent 022ceb3cb9
commit 53d2f605e7
1 file changed
+10 -6
@@ -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());