mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 09:41:24 +00:00
Auth: switch Kimi Coding to built-in provider
This commit is contained in:
@@ -99,7 +99,7 @@ const AUTH_CHOICE_GROUP_DEFS: {
|
||||
{
|
||||
value: "moonshot",
|
||||
label: "Moonshot AI",
|
||||
hint: "Kimi K2 + Kimi Code",
|
||||
hint: "Kimi K2 + Kimi Coding",
|
||||
choices: ["moonshot-api-key", "kimi-code-api-key"],
|
||||
},
|
||||
{
|
||||
@@ -147,7 +147,7 @@ export function buildAuthChoiceOptions(params: {
|
||||
label: "Vercel AI Gateway API key",
|
||||
});
|
||||
options.push({ value: "moonshot-api-key", label: "Moonshot AI API key" });
|
||||
options.push({ value: "kimi-code-api-key", label: "Kimi Code API key" });
|
||||
options.push({ value: "kimi-code-api-key", label: "Kimi Coding API key" });
|
||||
options.push({ value: "synthetic-api-key", label: "Synthetic API key" });
|
||||
options.push({
|
||||
value: "venice-api-key",
|
||||
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
applyXiaomiConfig,
|
||||
applyXiaomiProviderConfig,
|
||||
applyZaiConfig,
|
||||
KIMI_CODE_MODEL_REF,
|
||||
KIMI_CODING_MODEL_REF,
|
||||
MOONSHOT_DEFAULT_MODEL_REF,
|
||||
OPENROUTER_DEFAULT_MODEL_REF,
|
||||
SYNTHETIC_DEFAULT_MODEL_REF,
|
||||
@@ -38,7 +38,7 @@ import {
|
||||
VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF,
|
||||
XIAOMI_DEFAULT_MODEL_REF,
|
||||
setGeminiApiKey,
|
||||
setKimiCodeApiKey,
|
||||
setKimiCodingApiKey,
|
||||
setMoonshotApiKey,
|
||||
setOpencodeZenApiKey,
|
||||
setOpenrouterApiKey,
|
||||
@@ -77,7 +77,10 @@ export async function applyAuthChoiceApiProviders(
|
||||
authChoice = "ai-gateway-api-key";
|
||||
} else if (params.opts.tokenProvider === "moonshot") {
|
||||
authChoice = "moonshot-api-key";
|
||||
} else if (params.opts.tokenProvider === "kimi-code") {
|
||||
} else if (
|
||||
params.opts.tokenProvider === "kimi-code" ||
|
||||
params.opts.tokenProvider === "kimi-coding"
|
||||
) {
|
||||
authChoice = "kimi-code-api-key";
|
||||
} else if (params.opts.tokenProvider === "google") {
|
||||
authChoice = "gemini-api-key";
|
||||
@@ -273,51 +276,56 @@ export async function applyAuthChoiceApiProviders(
|
||||
|
||||
if (authChoice === "kimi-code-api-key") {
|
||||
let hasCredential = false;
|
||||
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "kimi-code") {
|
||||
await setKimiCodeApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||
const tokenProvider = params.opts?.tokenProvider?.trim().toLowerCase();
|
||||
if (
|
||||
!hasCredential &&
|
||||
params.opts?.token &&
|
||||
(tokenProvider === "kimi-code" || tokenProvider === "kimi-coding")
|
||||
) {
|
||||
await setKimiCodingApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||
hasCredential = true;
|
||||
}
|
||||
|
||||
if (!hasCredential) {
|
||||
await params.prompter.note(
|
||||
[
|
||||
"Kimi Code uses a dedicated endpoint and API key.",
|
||||
"Kimi Coding uses a dedicated endpoint and API key.",
|
||||
"Get your API key at: https://www.kimi.com/code/en",
|
||||
].join("\n"),
|
||||
"Kimi Code",
|
||||
"Kimi Coding",
|
||||
);
|
||||
}
|
||||
const envKey = resolveEnvApiKey("kimi-code");
|
||||
const envKey = resolveEnvApiKey("kimi-coding");
|
||||
if (envKey) {
|
||||
const useExisting = await params.prompter.confirm({
|
||||
message: `Use existing KIMICODE_API_KEY (${envKey.source}, ${formatApiKeyPreview(envKey.apiKey)})?`,
|
||||
message: `Use existing KIMI_API_KEY (${envKey.source}, ${formatApiKeyPreview(envKey.apiKey)})?`,
|
||||
initialValue: true,
|
||||
});
|
||||
if (useExisting) {
|
||||
await setKimiCodeApiKey(envKey.apiKey, params.agentDir);
|
||||
await setKimiCodingApiKey(envKey.apiKey, params.agentDir);
|
||||
hasCredential = true;
|
||||
}
|
||||
}
|
||||
if (!hasCredential) {
|
||||
const key = await params.prompter.text({
|
||||
message: "Enter Kimi Code API key",
|
||||
message: "Enter Kimi Coding API key",
|
||||
validate: validateApiKeyInput,
|
||||
});
|
||||
await setKimiCodeApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
|
||||
await setKimiCodingApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "kimi-code:default",
|
||||
provider: "kimi-code",
|
||||
profileId: "kimi-coding:default",
|
||||
provider: "kimi-coding",
|
||||
mode: "api_key",
|
||||
});
|
||||
{
|
||||
const applied = await applyDefaultModelChoice({
|
||||
config: nextConfig,
|
||||
setDefaultModel: params.setDefaultModel,
|
||||
defaultModel: KIMI_CODE_MODEL_REF,
|
||||
defaultModel: KIMI_CODING_MODEL_REF,
|
||||
applyDefaultConfig: applyKimiCodeConfig,
|
||||
applyProviderConfig: applyKimiCodeProviderConfig,
|
||||
noteDefault: KIMI_CODE_MODEL_REF,
|
||||
noteDefault: KIMI_CODING_MODEL_REF,
|
||||
noteAgentModel,
|
||||
prompter: params.prompter,
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@ const PREFERRED_PROVIDER_BY_AUTH_CHOICE: Partial<Record<AuthChoice, string>> = {
|
||||
"openrouter-api-key": "openrouter",
|
||||
"ai-gateway-api-key": "vercel-ai-gateway",
|
||||
"moonshot-api-key": "moonshot",
|
||||
"kimi-code-api-key": "kimi-code",
|
||||
"kimi-code-api-key": "kimi-coding",
|
||||
"gemini-api-key": "google",
|
||||
"google-antigravity": "google-antigravity",
|
||||
"google-gemini-cli": "google-gemini-cli",
|
||||
|
||||
@@ -19,11 +19,8 @@ import {
|
||||
ZAI_DEFAULT_MODEL_REF,
|
||||
} from "./onboard-auth.credentials.js";
|
||||
import {
|
||||
buildKimiCodeModelDefinition,
|
||||
buildMoonshotModelDefinition,
|
||||
KIMI_CODE_BASE_URL,
|
||||
KIMI_CODE_MODEL_ID,
|
||||
KIMI_CODE_MODEL_REF,
|
||||
KIMI_CODING_MODEL_REF,
|
||||
MOONSHOT_BASE_URL,
|
||||
MOONSHOT_DEFAULT_MODEL_ID,
|
||||
MOONSHOT_DEFAULT_MODEL_REF,
|
||||
@@ -206,29 +203,9 @@ export function applyMoonshotConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
|
||||
export function applyKimiCodeProviderConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
const models = { ...cfg.agents?.defaults?.models };
|
||||
models[KIMI_CODE_MODEL_REF] = {
|
||||
...models[KIMI_CODE_MODEL_REF],
|
||||
alias: models[KIMI_CODE_MODEL_REF]?.alias ?? "Kimi Code",
|
||||
};
|
||||
|
||||
const providers = { ...cfg.models?.providers };
|
||||
const existingProvider = providers["kimi-code"];
|
||||
const existingModels = Array.isArray(existingProvider?.models) ? existingProvider.models : [];
|
||||
const defaultModel = buildKimiCodeModelDefinition();
|
||||
const hasDefaultModel = existingModels.some((model) => model.id === KIMI_CODE_MODEL_ID);
|
||||
const mergedModels = hasDefaultModel ? existingModels : [...existingModels, defaultModel];
|
||||
const { apiKey: existingApiKey, ...existingProviderRest } = (existingProvider ?? {}) as Record<
|
||||
string,
|
||||
unknown
|
||||
> as { apiKey?: string };
|
||||
const resolvedApiKey = typeof existingApiKey === "string" ? existingApiKey : undefined;
|
||||
const normalizedApiKey = resolvedApiKey?.trim();
|
||||
providers["kimi-code"] = {
|
||||
...existingProviderRest,
|
||||
baseUrl: KIMI_CODE_BASE_URL,
|
||||
api: "openai-completions",
|
||||
...(normalizedApiKey ? { apiKey: normalizedApiKey } : {}),
|
||||
models: mergedModels.length > 0 ? mergedModels : [defaultModel],
|
||||
models[KIMI_CODING_MODEL_REF] = {
|
||||
...models[KIMI_CODING_MODEL_REF],
|
||||
alias: models[KIMI_CODING_MODEL_REF]?.alias ?? "Kimi K2.5",
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -240,10 +217,6 @@ export function applyKimiCodeProviderConfig(cfg: OpenClawConfig): OpenClawConfig
|
||||
models,
|
||||
},
|
||||
},
|
||||
models: {
|
||||
mode: cfg.models?.mode ?? "merge",
|
||||
providers,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -262,7 +235,7 @@ export function applyKimiCodeConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
fallbacks: (existingModel as { fallbacks?: string[] }).fallbacks,
|
||||
}
|
||||
: undefined),
|
||||
primary: KIMI_CODE_MODEL_REF,
|
||||
primary: KIMI_CODING_MODEL_REF,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -74,13 +74,13 @@ export async function setMoonshotApiKey(key: string, agentDir?: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function setKimiCodeApiKey(key: string, agentDir?: string) {
|
||||
export async function setKimiCodingApiKey(key: string, agentDir?: string) {
|
||||
// Write to resolved agent dir so gateway finds credentials on startup.
|
||||
upsertAuthProfile({
|
||||
profileId: "kimi-code:default",
|
||||
profileId: "kimi-coding:default",
|
||||
credential: {
|
||||
type: "api_key",
|
||||
provider: "kimi-code",
|
||||
provider: "kimi-coding",
|
||||
key,
|
||||
},
|
||||
agentDir: resolveAuthAgentDir(agentDir),
|
||||
|
||||
@@ -12,13 +12,8 @@ export const MOONSHOT_DEFAULT_MODEL_ID = "kimi-k2-0905-preview";
|
||||
export const MOONSHOT_DEFAULT_MODEL_REF = `moonshot/${MOONSHOT_DEFAULT_MODEL_ID}`;
|
||||
export const MOONSHOT_DEFAULT_CONTEXT_WINDOW = 256000;
|
||||
export const MOONSHOT_DEFAULT_MAX_TOKENS = 8192;
|
||||
export const KIMI_CODE_BASE_URL = "https://api.kimi.com/coding/v1";
|
||||
export const KIMI_CODE_MODEL_ID = "kimi-for-coding";
|
||||
export const KIMI_CODE_MODEL_REF = `kimi-code/${KIMI_CODE_MODEL_ID}`;
|
||||
export const KIMI_CODE_CONTEXT_WINDOW = 262144;
|
||||
export const KIMI_CODE_MAX_TOKENS = 32768;
|
||||
export const KIMI_CODE_HEADERS = { "User-Agent": "KimiCLI/0.77" } as const;
|
||||
export const KIMI_CODE_COMPAT = { supportsDeveloperRole: false } as const;
|
||||
export const KIMI_CODING_MODEL_ID = "k2p5";
|
||||
export const KIMI_CODING_MODEL_REF = `kimi-coding/${KIMI_CODING_MODEL_ID}`;
|
||||
|
||||
// Pricing: MiniMax doesn't publish public rates. Override in models.json for accurate costs.
|
||||
export const MINIMAX_API_COST = {
|
||||
@@ -45,12 +40,6 @@ export const MOONSHOT_DEFAULT_COST = {
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
export const KIMI_CODE_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
const MINIMAX_MODEL_CATALOG = {
|
||||
"MiniMax-M2.1": { name: "MiniMax M2.1", reasoning: false },
|
||||
@@ -102,17 +91,3 @@ export function buildMoonshotModelDefinition(): ModelDefinitionConfig {
|
||||
maxTokens: MOONSHOT_DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildKimiCodeModelDefinition(): ModelDefinitionConfig {
|
||||
return {
|
||||
id: KIMI_CODE_MODEL_ID,
|
||||
name: "Kimi For Coding",
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
cost: KIMI_CODE_DEFAULT_COST,
|
||||
contextWindow: KIMI_CODE_CONTEXT_WINDOW,
|
||||
maxTokens: KIMI_CODE_MAX_TOKENS,
|
||||
headers: KIMI_CODE_HEADERS,
|
||||
compat: KIMI_CODE_COMPAT,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ export {
|
||||
OPENROUTER_DEFAULT_MODEL_REF,
|
||||
setAnthropicApiKey,
|
||||
setGeminiApiKey,
|
||||
setKimiCodeApiKey,
|
||||
setKimiCodingApiKey,
|
||||
setMinimaxApiKey,
|
||||
setMoonshotApiKey,
|
||||
setOpencodeZenApiKey,
|
||||
@@ -54,14 +54,12 @@ export {
|
||||
ZAI_DEFAULT_MODEL_REF,
|
||||
} from "./onboard-auth.credentials.js";
|
||||
export {
|
||||
buildKimiCodeModelDefinition,
|
||||
buildMinimaxApiModelDefinition,
|
||||
buildMinimaxModelDefinition,
|
||||
buildMoonshotModelDefinition,
|
||||
DEFAULT_MINIMAX_BASE_URL,
|
||||
KIMI_CODE_BASE_URL,
|
||||
KIMI_CODE_MODEL_ID,
|
||||
KIMI_CODE_MODEL_REF,
|
||||
KIMI_CODING_MODEL_ID,
|
||||
KIMI_CODING_MODEL_REF,
|
||||
MINIMAX_API_BASE_URL,
|
||||
MINIMAX_HOSTED_MODEL_ID,
|
||||
MINIMAX_HOSTED_MODEL_REF,
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
applyZaiConfig,
|
||||
setAnthropicApiKey,
|
||||
setGeminiApiKey,
|
||||
setKimiCodeApiKey,
|
||||
setKimiCodingApiKey,
|
||||
setMinimaxApiKey,
|
||||
setMoonshotApiKey,
|
||||
setOpencodeZenApiKey,
|
||||
@@ -275,18 +275,18 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
|
||||
if (authChoice === "kimi-code-api-key") {
|
||||
const resolved = await resolveNonInteractiveApiKey({
|
||||
provider: "kimi-code",
|
||||
provider: "kimi-coding",
|
||||
cfg: baseConfig,
|
||||
flagValue: opts.kimiCodeApiKey,
|
||||
flagName: "--kimi-code-api-key",
|
||||
envVar: "KIMICODE_API_KEY",
|
||||
envVar: "KIMI_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setKimiCodeApiKey(resolved.key);
|
||||
if (resolved.source !== "profile") await setKimiCodingApiKey(resolved.key);
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "kimi-code:default",
|
||||
provider: "kimi-code",
|
||||
profileId: "kimi-coding:default",
|
||||
provider: "kimi-coding",
|
||||
mode: "api_key",
|
||||
});
|
||||
return applyKimiCodeConfig(nextConfig);
|
||||
|
||||
Reference in New Issue
Block a user