Skip to content

feat(providers): add a Custom API provider for OpenAI, Anthropic and Responses endpoints - #663

Open
guyu233 wants to merge 1 commit into
caigee-cmd:mainfrom
guyu233:feat/custom-endpoint-provider
Open

guyu233 wants to merge 1 commit into
caigee-cmd:mainfrom
guyu233:feat/custom-endpoint-provider

Conversation

@guyu233

@guyu233 guyu233 commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Why

There is no way to point cli2api at an endpoint that already speaks OpenAI, Anthropic or Responses with just a base URL and a key, without going through a CLI worker or reverse proxy. Operators today have to either use a native provider family or run something else in front.

New API, LiteLLM and Cherry Studio all solve this the same way: a channel/provider is Base URL + key + protocol, the model list comes from /models or is typed in, and the public model name is decoupled from the upstream one. This PR adds that as a first-class provider family instead of a new channel model, so priority, concurrency, proxy, cooldown and failover are reused as-is.

What changed

  • New custom provider family (internal/providers/custom/): one account is one endpoint. The credential (custom-api-v1) carries base_url, api_key, a wire protocol (openai | anthropic | responses | auto) and an optional manual model list. There is no child process, no CLI bundle and no reverse proxy.
  • Wire per endpoint, not guessed: openai posts to {base}/chat/completions, anthropic to {base}/messages, responses to {base}/responses; auto picks per model from an anthropic/… or responses/… prefix. Bare hosts get /v1, hosts that already carry /v1, /v4 or /v1beta only get the relative path appended, and a full path is used untouched.
  • Catalog: GET {base}/models with a 30-minute cache; a manual list replaces the catalog. A 404/405 on /models with a manual list still counts as ready, because that route is display-only.
  • Translation (internal/translate/upstream_body.go, upstream_stream.go): builds request bodies for the three wires and converts their streams back to OpenAI chat deltas, including tool calls, so /v1/chat/completions clients stream normally regardless of what sits behind the endpoint.
  • Probe / classification / import: the prober reads the catalog once; 401/403/429 map through the existing taxonomy; the importer accepts custom-api-v1 for export/import.

What it does not change

  • ToolProfileFor is not touched: upstream has no tool-profile table yet, and the profile for custom belongs with the tool-profile work, not here.
  • No new maintenance hook: with the current upstream providers.Adapter there is no liveness slot, so a custom account is maintained by the existing probe path.

Tests

  • go build ./...
  • go test ./internal/providers/custom/ ./internal/translate/ ./internal/providers/ ./internal/app/ — all pass
  • internal/providers/custom/custom_test.go covers all three wires (path, auth header, body shape), SSE → chat-delta conversion, tool calls, base-URL normalisation, manual vs fetched catalog, and classification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant