Repository navigation
feat(chat): manage own API keys from Chat, with Use for and routing by the model's provider (W4-06) - #2033
Merged
Conversation
…take the key out (W4-05) The composer finds a pasted key by its provider's shape (sk-ant-, sk-or-v1-, sk-proj-, sk-, AIza): Send waits, a line says why, and Remove takes the key out of the text. Save securely shows only where the page offers a key form. The run routes refuse such a message or typed answer with api_key before anything keeps it, and never log it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…indow # Conflicts: # web/src/components/chat/composer/chat-composer.tsx
…y the model's provider (W4-06) - Use for (Chat, Images) on each saved key, in its settings; Anthropic's is for Chat only, and a key saved before counts as Chat. PATCH sets it; a save that names none keeps it. - A picked model's steps run on the own key for its provider, then the own OpenRouter key, then Ansvisor's; Auto runs on the active key only when it is for Chat. An unreadable key still stops the step. - Your API keys, from the model menu (Admins, where own keys are open): each key with Use for, Test and Add API key. - Add API key: a form straight to Settings' route, tested before it is kept, never through the model. "Use my OpenAI key" in the composer and Save securely on a pasted key open it; non-Admins and other plans read why not. - When the own key fails, Admins may click "Use Ansvisor's limit" to ask again on the AI limit; Chat never switches by itself. - Help: help/chat/models.md and help/chat/chat.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…indow Opus 5.5 hidden until tested: no key is looked for a pick not offered; it runs Auto. Co-Authored-By: Claude Opus 5.5 <[email protected]>
8 of 13 tasks
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t-own-keys-window Co-Authored-By: Claude Opus 5.5 <[email protected]>
…chat-own-keys-window Co-Authored-By: Claude Opus 5.5 <[email protected]>
…PI key section Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y in Use Chat Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main's replay masking (ansvisor#2009) wants every plain password input to carry ph-no-capture. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and routing - asksToAddKey needs an API key, a provider's or own key, or a bare "key" that ends the sentence, so "our key competitors" or "key topics" are sent. - A message that does open the Add API key card stays in the box; sending it again sends it to Chat. - ownChatKeyProvider (and so chatRunsOnOwnKey) counts the active key only when it is for Chat, as resolveChatModelKey does. - The model menu marks Your key per model in resolvePickedModelKey's order: an own key for its provider, else an own OpenRouter key, both for Chat (ownChatKeyProviders).
gkhngyk
previously approved these changes
Nov 3, 2026
8 of 13 tasks
…indow # Conflicts: # help/chat/chat.md # web/src/app/api/chat/runs/route.ts # web/src/components/chat/composer/chat-composer.tsx # web/src/lib/chat/engine-model.test.ts # web/src/lib/chat/engine.ts # web/src/lib/chat/key-paste.test.ts # web/src/lib/chat/key-paste.ts # web/src/lib/chat/run-api.ts # web/src/lib/help/approved-articles.json
…indow # Conflicts: # web/src/lib/chat/engine.ts
cihan-gyk
dismissed
gkhngyk’s stale review
November 4, 2026 17:12
The merge-base changed after approval.
cihan-gyk
dismissed
gkhngyk’s stale review
November 4, 2026 17:26
The merge-base changed after approval.
…ys-window # Conflicts: # web/src/lib/chat/engine.ts
This was referenced Nov 4, 2026
gkhngyk
pushed a commit
that referenced
this pull request
Nov 5, 2026
The Agent Center article had "Let an agent publish on its own" twice, from two pull requests. Merge them into one section that keeps both sections' facts: publishing new pages on Webflow, WordPress and Wix as well as CMS drafts, the two switches with Full auto, the Manager's read-only switch, At most a day (1 to 20, 5 by default), the reasons a page still waits for a click, and the reset after a change. Add that it needs Growth and up and only shows where the workspace has it. "On your own AI key" said every agent runs on the workspace's own key. Since agents run on their own model (#2032) and a picked model runs on its provider's key, then the OpenRouter key, then the AI limit (#2033), that holds for agents on Auto only: say so. Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9 Co-authored-by: Claude <[email protected]>
gkhngyk
pushed a commit
that referenced
this pull request
Nov 5, 2026
The Model step of the agent form (Agent Center > new or edit agent) said
"Runs on your {provider} key" from Auto's key alone. Since #2032 an agent
runs on its own model, and since #2033 a picked model runs on the key for
its provider, then the workspace's OpenRouter key, then Ansvisor's key on
the monthly AI limit. So an agent on Fast or Best writing in a workspace
whose own key is OpenAI ran on the AI limit while the form said OpenAI.
The line and Max per run's note now follow the model the form has chosen,
as the engine picks its key:
- Auto: the key Auto runs on, else the monthly AI limit;
- a picked model: the own key for its provider, else the OpenRouter key,
else the monthly AI limit;
- the free trial, and a model no longer offered, run Auto: Auto's key.
The order lives in one place: pickedModelKeyOrder and pickedModelOwnKey
(lib/chat/models.ts, safe in the browser). resolvePickedModelKey loops
over pickedModelKeyOrder, the model menu's "Your key" uses
pickedModelOwnKey, and the form's modelKeyProvider uses it with
runChoiceOf. The form's setup carries the providers of the own keys for
Chat (ownChatKeyProviders, no key decrypted) and whether the plan runs a
picked model (modelChoiceOpen).
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Co-authored-by: Claude <[email protected]>
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
Own API keys from Chat (CHAT-16 items 19–23, Wave 4 plan W4-06): a Your API keys window, an Add API key form card, Use for per key, routing by the picked model's provider, and Use Ansvisor's limit when a key fails. Own keys remain Enterprise's (the 2026-10-30 decision).
Use for: Chat / Images on each saved key (
organization_ai_keys.settings.useFor; no migration).PATCH /api/settings/ai-providers { provider, useFor }sets it. APUTthat names no uses keeps the saved ones, so Settings' own form doesn't wipe them.Routing a picked model's steps (
resolvePickedModelKey):Auto keeps running on the key Chat uses (
active), now only when that key is for Chat. A key that can't be read stops the step, as before; there is never a silent fallback.Your API keys (
your-keys-dialog.tsx) opens from the model menu's own-key row, for Admins where own keys are open. It lists each key with its last four characters, marks the one Auto runs on, and offers the Use for toggles, Test, Add API key and a link to Settings.Add API key (
add-key-card.tsx) is a form, never a tool call:The key goes straight to Settings' route, which tests it before it keeps it; it never reaches the model, the chat or a log. Non-Admins read "Ask your Admin"; below Enterprise, "Own API keys come with Enterprise."
From the composer:
When an own key fails mid-run: the error card keeps "Open AI Providers" and adds Use Ansvisor's limit for Admins while the limit has room. It sends the question again with
keySource: 'ansvisor'; the engine takes it from an Admin only. Chat never switches by itself (AGENT-OWN-KEY).Help:
help/chat/models.md(Your API keys, when your key stops working) andhelp/chat/chat.md(Save securely); bothapproved: false.Stacked on #2032 (with #2020 merged in, for Save securely). Merged, not rebased.
Related issue
None. Chat Wave 4 plan, W4-06.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
On an Enterprise workspace, as an Admin:
cd web && yarn vitest run src/lib/chat/key-routing.test.ts src/app/api/settings/ai-providers src/components/chat/run src/components/chat/composer src/lib/agent/providers.test.ts.Screenshots (light and dark, 1024 px): Your API keys, the Add API key card, and the error card with Use Ansvisor's limit.
No migration. No new environment variables (it uses W4-03's optional
OPENROUTER_API_KEY).Checklist
yarn lintpassesyarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change)Screens: shown to the owner in a local preview (1024px, light and dark) and approved on 2026-11-02.
CI passed on this branch (210d0d5), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41525032198): schema is up to date; web
format:check, lint, typecheck, all tests andyarn buildpass; server lint,format:checkand all tests pass.🤖 Generated with Claude Code