diff --git a/changelog/unreleased/custom-api-provider.md b/changelog/unreleased/custom-api-provider.md new file mode 100644 index 000000000..12900d007 --- /dev/null +++ b/changelog/unreleased/custom-api-provider.md @@ -0,0 +1,11 @@ +### English + +- Add a Custom API provider: one account is one endpoint (base URL + key), with OpenAI Chat Completions, Anthropic Messages, or Responses as the upstream wire and no reverse proxy. +- Custom endpoints get their catalog from `/models` or a manual model list, and their models are routed as `custom/`. +- Console: "Add account" offers a Custom API form — base URL, key, the upstream protocol (OpenAI, Anthropic, or Responses), and an optional model list. + +### 中文 + +- 新增「自定义 API」供应商:一个账号就是一个端点(Base URL + 密钥),上游协议可选 OpenAI Chat Completions、Anthropic Messages 或 Responses,直连不走反代。 +- 自定义端点按 `/models` 或手填列表生成 catalog,模型按 `custom/` 路由。 +- 控制台:「添加账号」新增「自定义 API」表单 —— Base URL、密钥、上游协议(OpenAI、Anthropic、Responses)以及可选的模型列表。 diff --git a/frontend/src/components/AddAccountModal.tsx b/frontend/src/components/AddAccountModal.tsx index fb018096c..bc3222eff 100644 --- a/frontend/src/components/AddAccountModal.tsx +++ b/frontend/src/components/AddAccountModal.tsx @@ -76,6 +76,7 @@ const labelKeys: Record = { 'minimaxcode-global': 'accountTypeMiniMaxCodeGlobal', 'opencode-go': 'accountTypeOpenCode', 'opencode-zen': 'accountTypeOpenCode', + 'custom-api': 'accountTypeCustomAPI', 'freemilk-global': 'accountTypeFreeMilk', } @@ -101,6 +102,7 @@ const hintKeys: Record = { 'minimaxcode-global': 'accountTypeMiniMaxCodeGlobalHint', 'opencode-go': 'accountTypeOpenCodeGoHint', 'opencode-zen': 'accountTypeOpenCodeZenHint', + 'custom-api': 'accountTypeCustomAPIHint', 'freemilk-global': 'accountTypeFreeMilkHint', } @@ -165,6 +167,10 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) { const [zhipuOrganization, setZhipuOrganization] = useState('') const [zhipuProject, setZhipuProject] = useState('') const [doubaoCookies, setDoubaoCookies] = useState('') + const [customBaseURL, setCustomBaseURL] = useState('') + const [customKey, setCustomKey] = useState('') + const [customProtocol, setCustomProtocol] = useState<'openai' | 'anthropic' | 'responses'>('openai') + const [customModels, setCustomModels] = useState('') const [phase, setPhase] = useState('idle') const [message, setMessage] = useState('') const [authUrl, setAuthUrl] = useState('') @@ -274,6 +280,10 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) { setZhipuOrganization('') setZhipuProject('') setDoubaoCookies('') + setCustomBaseURL('') + setCustomKey('') + setCustomProtocol('openai') + setCustomModels('') setAdvancedOpen(false) setPhase('idle') setMessage('') @@ -456,6 +466,41 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) { } } + async function runCustom() { + const baseURL = customBaseURL.trim().replace(/\/+$/, '') + if (!baseURL) { setMessage(t('customBaseURLRequired')); return } + if (!activeOption) { setMessage(t('accountTypeHint')); return } + setMessage('') + try { + setPhase('busy') + const options = accountOptions() + const models = customModels + .split(/[\n,]/) + .map((model) => model.trim()) + .filter(Boolean) + await importAccount({ + format: 'custom-api-v1', + api_key: customKey.trim(), + base_url: baseURL, + protocol: customProtocol, + models, + name: name.trim() || t('accountTypeCustomAPI'), + enabled: true, + provider: activeOption.provider, + region: activeOption.region, + max_inflight: options.max_inflight, + priority: options.priority, + }) + setPhase('done') + setMessage(t('wizardAccountReady')) + onAdded() + window.setTimeout(finishAndClose, 700) + } catch (error) { + setPhase('idle') + setMessage(error instanceof Error ? error.message : String(error)) + } + } + async function runDoubao() { const cookie = doubaoCookies.trim() if (!cookie) { setMessage(t('doubaoCookieRequired')); return } @@ -596,6 +641,7 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) { const tabPending = (key: TabKey) => busy && tab === key const isZhipu = activeOption?.provider === 'zhipu' const isDoubao = activeOption?.provider === 'doubaowork' + const isCustom = activeOption?.provider === 'custom' const methodOptions = [ activeOption?.descriptor.capabilities?.browser_login !== false ? { value: 'browser' as const, label: t('tabBrowser') } @@ -800,7 +846,40 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) { ) : null} - {isZhipu || isDoubao ? null : ( + {isCustom ? ( +
+

{t('customEndpointLead')}

+ + setCustomBaseURL(event.target.value)} placeholder={t('customBaseURLPh')} aria-label={t('customBaseURL')} disabled={busy} autoFocus /> + + + setCustomKey(event.target.value)} placeholder={t('customAPIKeyPh')} aria-label={t('customAPIKey')} disabled={busy} /> + +
+ {t('customProtocol')} + { if (!busy) setCustomProtocol(next) }} + options={[ + { value: 'openai', label: t('customProtocolOpenAI'), hint: t('customProtocolOpenAIHint'), disabled: busy }, + { value: 'anthropic', label: t('customProtocolAnthropic'), hint: t('customProtocolAnthropicHint'), disabled: busy }, + { value: 'responses', label: t('customProtocolResponses'), hint: t('customProtocolResponsesHint'), disabled: busy }, + ]} + /> +
+ +