mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
* feat: add LiteLLM provider types, env var, credentials, and auth choice Add litellm-api-key auth choice, LITELLM_API_KEY env var mapping, setLitellmApiKey() credential storage, and LITELLM_DEFAULT_MODEL_REF. * feat: add LiteLLM onboarding handler and provider config Add applyLitellmProviderConfig which properly registers models.providers.litellm with baseUrl, api type, and model definitions. This fixes the critical bug from PR #6488 where the provider entry was never created, causing model resolution to fail at runtime. * docs: add LiteLLM provider documentation Add setup guide covering onboarding, manual config, virtual keys, model routing, and usage tracking. Link from provider index. * docs: add LiteLLM to sidebar navigation in docs.json Add providers/litellm to both English and Chinese provider page lists so the docs page appears in the sidebar navigation. * test: add LiteLLM non-interactive onboarding test Wire up litellmApiKey flag inference and auth-choice handler for the non-interactive onboarding path, and add an integration test covering profile, model default, and credential storage. * fix: register --litellm-api-key CLI flag and add preferred provider mapping Wire up the missing Commander CLI option, action handler mapping, and help text for --litellm-api-key. Add litellm-api-key to the preferred provider map for consistency with other providers. * fix: remove zh-CN sidebar entry for litellm (no localized page yet) * style: format buildLitellmModelDefinition return type * fix(onboarding): harden LiteLLM provider setup (#12823) * refactor(onboarding): keep auth-choice provider dispatcher under size limit --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
308 lines
7.5 KiB
TypeScript
308 lines
7.5 KiB
TypeScript
import type { AuthProfileStore } from "../agents/auth-profiles.js";
|
|
import type { AuthChoice } from "./onboard-types.js";
|
|
|
|
export type AuthChoiceOption = {
|
|
value: AuthChoice;
|
|
label: string;
|
|
hint?: string;
|
|
};
|
|
|
|
export type AuthChoiceGroupId =
|
|
| "openai"
|
|
| "anthropic"
|
|
| "google"
|
|
| "copilot"
|
|
| "openrouter"
|
|
| "litellm"
|
|
| "ai-gateway"
|
|
| "cloudflare-ai-gateway"
|
|
| "moonshot"
|
|
| "zai"
|
|
| "xiaomi"
|
|
| "opencode-zen"
|
|
| "minimax"
|
|
| "synthetic"
|
|
| "venice"
|
|
| "qwen"
|
|
| "together"
|
|
| "qianfan"
|
|
| "xai"
|
|
| "custom";
|
|
|
|
export type AuthChoiceGroup = {
|
|
value: AuthChoiceGroupId;
|
|
label: string;
|
|
hint?: string;
|
|
options: AuthChoiceOption[];
|
|
};
|
|
|
|
const AUTH_CHOICE_GROUP_DEFS: {
|
|
value: AuthChoiceGroupId;
|
|
label: string;
|
|
hint?: string;
|
|
choices: AuthChoice[];
|
|
}[] = [
|
|
{
|
|
value: "openai",
|
|
label: "OpenAI",
|
|
hint: "Codex OAuth + API key",
|
|
choices: ["openai-codex", "openai-api-key"],
|
|
},
|
|
{
|
|
value: "anthropic",
|
|
label: "Anthropic",
|
|
hint: "setup-token + API key",
|
|
choices: ["token", "apiKey"],
|
|
},
|
|
{
|
|
value: "minimax",
|
|
label: "MiniMax",
|
|
hint: "M2.1 (recommended)",
|
|
choices: ["minimax-portal", "minimax-api", "minimax-api-lightning"],
|
|
},
|
|
{
|
|
value: "moonshot",
|
|
label: "Moonshot AI (Kimi K2.5)",
|
|
hint: "Kimi K2.5 + Kimi Coding",
|
|
choices: ["moonshot-api-key", "moonshot-api-key-cn", "kimi-code-api-key"],
|
|
},
|
|
{
|
|
value: "google",
|
|
label: "Google",
|
|
hint: "Gemini API key + OAuth",
|
|
choices: ["gemini-api-key", "google-antigravity", "google-gemini-cli"],
|
|
},
|
|
{
|
|
value: "xai",
|
|
label: "xAI (Grok)",
|
|
hint: "API key",
|
|
choices: ["xai-api-key"],
|
|
},
|
|
{
|
|
value: "openrouter",
|
|
label: "OpenRouter",
|
|
hint: "API key",
|
|
choices: ["openrouter-api-key"],
|
|
},
|
|
{
|
|
value: "qwen",
|
|
label: "Qwen",
|
|
hint: "OAuth",
|
|
choices: ["qwen-portal"],
|
|
},
|
|
{
|
|
value: "zai",
|
|
label: "Z.AI (GLM 4.7)",
|
|
hint: "API key",
|
|
choices: ["zai-api-key"],
|
|
},
|
|
{
|
|
value: "qianfan",
|
|
label: "Qianfan",
|
|
hint: "API key",
|
|
choices: ["qianfan-api-key"],
|
|
},
|
|
{
|
|
value: "copilot",
|
|
label: "Copilot",
|
|
hint: "GitHub + local proxy",
|
|
choices: ["github-copilot", "copilot-proxy"],
|
|
},
|
|
{
|
|
value: "ai-gateway",
|
|
label: "Vercel AI Gateway",
|
|
hint: "API key",
|
|
choices: ["ai-gateway-api-key"],
|
|
},
|
|
{
|
|
value: "opencode-zen",
|
|
label: "OpenCode Zen",
|
|
hint: "API key",
|
|
choices: ["opencode-zen"],
|
|
},
|
|
{
|
|
value: "xiaomi",
|
|
label: "Xiaomi",
|
|
hint: "API key",
|
|
choices: ["xiaomi-api-key"],
|
|
},
|
|
{
|
|
value: "synthetic",
|
|
label: "Synthetic",
|
|
hint: "Anthropic-compatible (multi-model)",
|
|
choices: ["synthetic-api-key"],
|
|
},
|
|
{
|
|
value: "together",
|
|
label: "Together AI",
|
|
hint: "API key",
|
|
choices: ["together-api-key"],
|
|
},
|
|
{
|
|
value: "venice",
|
|
label: "Venice AI",
|
|
hint: "Privacy-focused (uncensored models)",
|
|
choices: ["venice-api-key"],
|
|
},
|
|
{
|
|
value: "litellm",
|
|
label: "LiteLLM",
|
|
hint: "Unified LLM gateway (100+ providers)",
|
|
choices: ["litellm-api-key"],
|
|
},
|
|
{
|
|
value: "cloudflare-ai-gateway",
|
|
label: "Cloudflare AI Gateway",
|
|
hint: "Account ID + Gateway ID + API key",
|
|
choices: ["cloudflare-ai-gateway-api-key"],
|
|
},
|
|
{
|
|
value: "custom",
|
|
label: "Custom Provider",
|
|
hint: "Any OpenAI or Anthropic compatible endpoint",
|
|
choices: ["custom-api-key"],
|
|
},
|
|
];
|
|
|
|
export function buildAuthChoiceOptions(params: {
|
|
store: AuthProfileStore;
|
|
includeSkip: boolean;
|
|
}): AuthChoiceOption[] {
|
|
void params.store;
|
|
const options: AuthChoiceOption[] = [];
|
|
|
|
options.push({
|
|
value: "token",
|
|
label: "Anthropic token (paste setup-token)",
|
|
hint: "run `claude setup-token` elsewhere, then paste the token here",
|
|
});
|
|
|
|
options.push({
|
|
value: "openai-codex",
|
|
label: "OpenAI Codex (ChatGPT OAuth)",
|
|
});
|
|
options.push({ value: "chutes", label: "Chutes (OAuth)" });
|
|
options.push({ value: "openai-api-key", label: "OpenAI API key" });
|
|
options.push({ value: "xai-api-key", label: "xAI (Grok) API key" });
|
|
options.push({
|
|
value: "qianfan-api-key",
|
|
label: "Qianfan API key",
|
|
});
|
|
options.push({ value: "openrouter-api-key", label: "OpenRouter API key" });
|
|
options.push({
|
|
value: "litellm-api-key",
|
|
label: "LiteLLM API key",
|
|
hint: "Unified gateway for 100+ LLM providers",
|
|
});
|
|
options.push({
|
|
value: "ai-gateway-api-key",
|
|
label: "Vercel AI Gateway API key",
|
|
});
|
|
options.push({
|
|
value: "cloudflare-ai-gateway-api-key",
|
|
label: "Cloudflare AI Gateway",
|
|
hint: "Account ID + Gateway ID + API key",
|
|
});
|
|
options.push({
|
|
value: "moonshot-api-key",
|
|
label: "Kimi API key (.ai)",
|
|
});
|
|
options.push({
|
|
value: "moonshot-api-key-cn",
|
|
label: "Kimi API key (.cn)",
|
|
});
|
|
options.push({
|
|
value: "kimi-code-api-key",
|
|
label: "Kimi Code API key (subscription)",
|
|
});
|
|
options.push({ value: "synthetic-api-key", label: "Synthetic API key" });
|
|
options.push({
|
|
value: "venice-api-key",
|
|
label: "Venice AI API key",
|
|
hint: "Privacy-focused inference (uncensored models)",
|
|
});
|
|
options.push({
|
|
value: "together-api-key",
|
|
label: "Together AI API key",
|
|
hint: "Access to Llama, DeepSeek, Qwen, and more open models",
|
|
});
|
|
options.push({
|
|
value: "github-copilot",
|
|
label: "GitHub Copilot (GitHub device login)",
|
|
hint: "Uses GitHub device flow",
|
|
});
|
|
options.push({ value: "gemini-api-key", label: "Google Gemini API key" });
|
|
options.push({
|
|
value: "google-antigravity",
|
|
label: "Google Antigravity OAuth",
|
|
hint: "Uses the bundled Antigravity auth plugin",
|
|
});
|
|
options.push({
|
|
value: "google-gemini-cli",
|
|
label: "Google Gemini CLI OAuth",
|
|
hint: "Uses the bundled Gemini CLI auth plugin",
|
|
});
|
|
options.push({ value: "zai-api-key", label: "Z.AI (GLM 4.7) API key" });
|
|
options.push({
|
|
value: "xiaomi-api-key",
|
|
label: "Xiaomi API key",
|
|
});
|
|
options.push({
|
|
value: "minimax-portal",
|
|
label: "MiniMax OAuth",
|
|
hint: "Oauth plugin for MiniMax",
|
|
});
|
|
options.push({ value: "qwen-portal", label: "Qwen OAuth" });
|
|
options.push({
|
|
value: "copilot-proxy",
|
|
label: "Copilot Proxy (local)",
|
|
hint: "Local proxy for VS Code Copilot models",
|
|
});
|
|
options.push({ value: "apiKey", label: "Anthropic API key" });
|
|
// Token flow is currently Anthropic-only; use CLI for advanced providers.
|
|
options.push({
|
|
value: "opencode-zen",
|
|
label: "OpenCode Zen (multi-model proxy)",
|
|
hint: "Claude, GPT, Gemini via opencode.ai/zen",
|
|
});
|
|
options.push({ value: "minimax-api", label: "MiniMax M2.1" });
|
|
options.push({
|
|
value: "minimax-api-lightning",
|
|
label: "MiniMax M2.1 Lightning",
|
|
hint: "Faster, higher output cost",
|
|
});
|
|
options.push({ value: "custom-api-key", label: "Custom Provider" });
|
|
|
|
if (params.includeSkip) {
|
|
options.push({ value: "skip", label: "Skip for now" });
|
|
}
|
|
|
|
return options;
|
|
}
|
|
|
|
export function buildAuthChoiceGroups(params: { store: AuthProfileStore; includeSkip: boolean }): {
|
|
groups: AuthChoiceGroup[];
|
|
skipOption?: AuthChoiceOption;
|
|
} {
|
|
const options = buildAuthChoiceOptions({
|
|
...params,
|
|
includeSkip: false,
|
|
});
|
|
const optionByValue = new Map<AuthChoice, AuthChoiceOption>(
|
|
options.map((opt) => [opt.value, opt]),
|
|
);
|
|
|
|
const groups = AUTH_CHOICE_GROUP_DEFS.map((group) => ({
|
|
...group,
|
|
options: group.choices
|
|
.map((choice) => optionByValue.get(choice))
|
|
.filter((opt): opt is AuthChoiceOption => Boolean(opt)),
|
|
}));
|
|
|
|
const skipOption = params.includeSkip
|
|
? ({ value: "skip", label: "Skip for now" } satisfies AuthChoiceOption)
|
|
: undefined;
|
|
|
|
return { groups, skipOption };
|
|
}
|