From 1fc62582ed48d58660767ef2acbb40ada51f371b Mon Sep 17 00:00:00 2001 From: ace-pm Date: Wed, 15 Apr 2026 08:54:52 +0200 Subject: [PATCH] feat(anthropic): support longcat as Bearer-auth Anthropic-compatible provider LongCat (Meituan) ships an Anthropic-compatible endpoint at https://api.longcat.chat/anthropic that authenticates via `Authorization: Bearer $KEY` instead of Anthropic's native `x-api-key` header. Without this change, pi sends x-api-key and LongCat replies with 401 invalid_api_key / missing_api_key. Same topology as the existing alibaba-coding-plan / minimax / minimax-cn entries (#3783). - Add "longcat" to usesAnthropicBearerAuth() so createClient routes the key through authToken. - Add "longcat": "LONGCAT_API_KEY" to env-api-keys.ts envMap so getEnvApiKey() can resolve it when options.apiKey is absent. - Add "longcat" to KnownProvider so the === literal check type-checks. - Extend anthropic-auth.test.ts to assert usesAnthropicBearerAuth returns true for longcat. --- packages/pi-ai/src/env-api-keys.ts | 1 + packages/pi-ai/src/providers/anthropic-auth.test.ts | 1 + packages/pi-ai/src/providers/anthropic.ts | 7 ++++++- packages/pi-ai/src/types.ts | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/pi-ai/src/env-api-keys.ts b/packages/pi-ai/src/env-api-keys.ts index 48edd5575..1fa055125 100644 --- a/packages/pi-ai/src/env-api-keys.ts +++ b/packages/pi-ai/src/env-api-keys.ts @@ -141,6 +141,7 @@ export function getEnvApiKey(provider: any): string | undefined { ollama: "OLLAMA_API_KEY", "ollama-cloud": "OLLAMA_API_KEY", "custom-openai": "CUSTOM_OPENAI_API_KEY", + longcat: "LONGCAT_API_KEY", }; const envVar = envMap[provider]; diff --git a/packages/pi-ai/src/providers/anthropic-auth.test.ts b/packages/pi-ai/src/providers/anthropic-auth.test.ts index 4593e1a5d..19e201b0d 100644 --- a/packages/pi-ai/src/providers/anthropic-auth.test.ts +++ b/packages/pi-ai/src/providers/anthropic-auth.test.ts @@ -12,6 +12,7 @@ test("usesAnthropicBearerAuth covers Bearer-only Anthropic-compatible providers assert.equal(usesAnthropicBearerAuth("alibaba-coding-plan"), true); assert.equal(usesAnthropicBearerAuth("minimax"), true); assert.equal(usesAnthropicBearerAuth("minimax-cn"), true); + assert.equal(usesAnthropicBearerAuth("longcat"), true); assert.equal(usesAnthropicBearerAuth("anthropic"), false); }); diff --git a/packages/pi-ai/src/providers/anthropic.ts b/packages/pi-ai/src/providers/anthropic.ts index ec9b21fde..375008ab4 100644 --- a/packages/pi-ai/src/providers/anthropic.ts +++ b/packages/pi-ai/src/providers/anthropic.ts @@ -45,7 +45,12 @@ function mergeHeaders(...headerSources: (Record | undefined)[]): } export function usesAnthropicBearerAuth(provider: Model<"anthropic-messages">["provider"]): boolean { - return provider === "alibaba-coding-plan" || provider === "minimax" || provider === "minimax-cn"; + return ( + provider === "alibaba-coding-plan" || + provider === "minimax" || + provider === "minimax-cn" || + provider === "longcat" + ); } async function createClient( diff --git a/packages/pi-ai/src/types.ts b/packages/pi-ai/src/types.ts index 9ec6ad85f..2c6ca9530 100644 --- a/packages/pi-ai/src/types.ts +++ b/packages/pi-ai/src/types.ts @@ -46,7 +46,8 @@ export type KnownProvider = | "alibaba-coding-plan" | "alibaba-dashscope" | "ollama" - | "ollama-cloud"; + | "ollama-cloud" + | "longcat"; export type Provider = KnownProvider | string; export type ThinkingLevel = "minimal" | "low" | "medium" | "high" | "xhigh";