Skip to content

feat: multiple keyed endpoints per platform (multi base URL + keys) - #2

Open
andyfan1094 wants to merge 1 commit into
GodD6366:masterfrom
andyfan1094:feat/multi-endpoint-per-platform
Open

andyfan1094 wants to merge 1 commit into
GodD6366:masterfrom
andyfan1094:feat/multi-endpoint-per-platform

Conversation

@andyfan1094

Copy link
Copy Markdown

Summary

Allow each provider platform (openai / claude / grok / gemini) to register multiple keyed endpoints - e.g. a second sub2api server, a spare group, or a dedicated image-generation key - instead of being limited to one key and one shared base URL per platform.

  • New optional endpoints[] on ProviderProfile: each entry carries its own name, apiKeyEnv (credential ref), optional baseURL override (may point at a different gateway), optional wire-protocol override, and its own model catalog.
  • Route naming: the legacy top-level key keeps the bare platform route (sub2api-openai); every named endpoint registers as sub2api-openai-<name> (name validated against [A-Za-z0-9_-]+). Endpoint credential refs are stored as SUB2API_<PLATFORM>_<NAME>_API_KEY.
  • The pi-ai bridge emits one hand-declared profile per endpoint (display name gains a (name) suffix when a platform has several endpoints); endpoints without key + models are skipped, so partial/empty forms never surface dead routes.
  • Settings page: each provider card renders an editor per extra endpoint (key field with stored-state checkmark, base URL override, model catalog with models.dev auto-fill, per-endpoint model discovery and usage lookup). Saving is fully backward compatible.
  • Global image tools: tool model refs accept an optional #<endpoint> segment (provider: openai#backup) so analyze/generate can pin a specific endpoint; resolution falls back to whichever endpoint carries the model when omitted.
  • Discovery / usage probes accept an endpoint parameter, use that endpoint's stored credential, and probe the endpoint's own base URL when it overrides the global one.
  • Docs updated in both READMEs (config example + rules).

Backward compatibility

Existing single-key configs keep working untouched: no endpoints[] means exactly one route per platform, same route names, same settings shape. The settings schema treats all new fields as optional.

Testing

  • npm run typecheck and npm run build pass.
  • Smoke-tested the compiled bridge directly: legacy config produces identical routes; multi-endpoint config expands to sub2api-openai, sub2api-openai-backup, sub2api-openai-other-host; keyless/model-less entries are skipped; baseURL/protocol overrides land in the pi-ai profile; image-tool refs resolve to the named endpoint.

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.

2 participants