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.
This commit is contained in:
ace-pm 2026-04-15 08:54:52 +02:00
parent cb8ac79ce6
commit 1fc62582ed
4 changed files with 10 additions and 2 deletions

View file

@ -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];

View file

@ -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);
});

View file

@ -45,7 +45,12 @@ function mergeHeaders(...headerSources: (Record<string, string> | 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(

View file

@ -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";