AI: optional per-project provider config (falls back to the server default)#83
Merged
Conversation
Let a project point /v1/ai/chat at its own provider/model/key/gateway, falling
back to the instance-wide AI_PROVIDER default when unset — so one server can
serve tenants with different AI backends.
- GET/PUT/DELETE /v1/ai/config (key-gated, per-project). PUT takes a flat
{ provider, model?, maxTokens?, apiKey?, baseUrl?, headers?, region? } and
stores it as a full AiConfig; the existing getProvider(ai) is already
parameterized, so the chat route just resolves the effective config and passes
it through. Secrets are stored server-side and never read back (GET returns a
redacted view with hasApiKey/hasHeaders).
- The effective config (project override, else config.ai) is resolved by the chat
route and /v1/stats (so stats reflects each project's provider), cached briefly
to keep chat requests off the DB. New project_ai table on both backends.
- SDK: client.ai.getConfig/setConfig/clearConfig; discovery advertises the endpoint.
Verification: 71/71 SQLite + 53/53 Postgres 16 — override + redaction + validation
+ reset, and cross-tenant isolation (project A's openai override doesn't change
project C's effective provider). Docs updated (README, /docs).
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.
What
Lets a project point
/v1/ai/chatat its own provider/model/key/gateway, while anyone who doesn't opt in keeps using the server's instance-wideAI_PROVIDERdefault. One server can now serve tenants with different AI backends.API
GET/PUT/DELETE /v1/ai/config(key-gated, per-project).PUTtakes a flat{ provider, model?, maxTokens?, apiKey?, baseUrl?, headers?, region? }. Secrets are stored server-side and never read back —GETreturns a redacted view (hasApiKey/hasHeaders, plusprovider/model/baseUrl/region).How
AiConfig(the shapegetProvider(ai)already accepts), so the chat route just resolves the effective config (override → instance default) and passes it through — no provider-factory changes./v1/statsreports each project's effective provider/model. The effective config is cached briefly so chat requests skip the DB. Newproject_aitable on both backends.client.ai.getConfig/setConfig/clearConfig; discovery advertises the endpoint.Verification
400) + reset-to-default, and cross-tenant isolation — project A'sopenaioverride leaves project C on theanthropicinstance default./docs(AI REST).Last item today after this: verifiable identity (JWT/OIDC).
https://claude.ai/code/session_018efxvWw3MRjdtvE5xgBqya
Generated by Claude Code