Repository navigation
feat(provider): add Custom API provider with console form - #672
Merged
Merged
Conversation
- Backend: custom adapter that proxies OpenAI Chat Completions, Anthropic Messages, or Responses upstreams directly (no reverse proxy); catalog from /models or a manual model list; models routed as custom/<model>. - Console: Add-account Custom API form (base URL, key, upstream protocol, optional model list) with bilingual labels and a dedicated provider mark. - Import detection maps custom-api-v1 credentials to the custom provider. - Add bilingual unreleased changelog fragment.
caigee-cmd
requested changes
Dec 5, 2026
caigee-cmd
left a comment
Owner
There was a problem hiding this comment.
感谢贡献这个 Custom API 供应商!整体结构很清晰:一个账号对应一个端点,进程内直连,不起子进程,也没有碰 store / executor / runtime 的边界,和现有 in-process provider 的写法一致。
我在本地把最新 main 合进来后跑了 go build ./...,以及 internal/providers/...、internal/translate、internal/control、internal/executor、internal/gateway 的测试,全部通过。我也确认了这个 PR 没有破坏性改动:没有新的 migration,没有修改任何现有 provider,translate 里只新增导出符号,custom-api-v1 的导入格式也不会被其他 provider 认领。
有几处我觉得合并前最好处理一下,具体位置和改法都写在行内评论里了。前三条会影响 Anthropic 和 OpenAI 两种协议的实际可用性,所以先标成 Request changes,改完我这边很快再看一遍:
- Anthropic 协议拉
/models时没带 Anthropic 的鉴权头(catalog.go),没手填模型时 Probe 会一直失败。 - 手填了模型,
/models返回 401/403 时 Probe 仍判定不可用(client.go)。 - OpenAI 协议流式请求缺少
stream_options.include_usage(upstream_body.go),token 用量大概率记成 0。 Classify先匹配正文关键词再看状态码(errors.go),容易把普通请求错误误判成账号鉴权或额度问题,导致账号被冷却。- changelog 写了"或自动",但 UI 里没有 auto 选项(
AddAccountModal.tsx/ changelog)。 - 提示文案没有标"实验性"(
messages.ts)。按 AGENTS.md,除 Qoder、WorkBuddy、Trae CN Work 外的 provider 都是实验性,其他 provider 的 hint 都以Experimental./实验性。开头。
另外还有几处小问题,不阻塞合并,顺手改掉就更好了:
chat.go的stripProviderPrefix里"custom/auto/"永远匹配不到,因为"custom/"排在前面会先命中。可以删掉这一项,或者把它挪到列表最前面。chat.go的onlyModel注释说"手填列表只有一个模型时生效",但Models()遇到手填列表会直接返回,不写c.catalogs,所以这个分支对手填列表其实不生效。详见行内评论。catalog.go的lookupModel目前没有调用方,可以先删掉。RelayUpstreamStream的default分支(io.Copy)在当前调用路径里走不到,因为 OpenAI 协议在chat.go里已经单独处理了。保留也可以,但建议注释说明一下。- Anthropic 请求体会同时转发
temperature和top_p,部分较新的 Claude 模型不允许两者同时出现。可以考虑两者都有时只保留temperature。
再次感谢,这个功能很实用,期待合并 🙏
- catalog: use Anthropic auth headers for GET /models when the protocol is anthropic - probe: treat 401/403 on /models as usable when a manual catalog is set - openai wire: request stream_options.include_usage so token counts are recorded - classify: status code first, body keywords only refine ambiguous statuses - anthropic wire: keep temperature and drop top_p when both are sent - chat: single manual model fills a missing request model; lookupModel removed - console: mark the provider experimental; changelog no longer mentions auto
Contributor
Author
|
已按评论全部改完并推了新提交(428fdebe),并把最新
小问题也一并处理了:
本地 @caigee-cmd 麻烦再看一遍 🙏 |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/modelsor a manual model list, and models are routed ascustom/<model>.custom-api-v1format; the import detector maps that format to the custom provider.Implementation
internal/providers/custom/(catalog, chat/stream relay, credential validation, quota/outcome/error mapping, import/export), wired intointernal/providers/registry.goandinternal/app/app.goalongside the existing PAT-style providers.internal/translate/:BuildUpstreamBody,RelayUpstreamStream, and theUpstreamProtocoltype.CustomMark, the modal custom form and guards, and English/Chinese i18n entries.changelog/unreleased/custom-api-provider.md.Test plan
go test ./...go vet ./...cd worker && npm test(covered by CI)cd frontend && npm run build && npm run lintchangelog/unreleased/<slug>.md, or this PR has no user-facing change