Repository navigation
feat(chat): hold a Content Editor image request on the AI budget, with no Chat run (W4-09) - #2101
Merged
Merged
Conversation
…eal cost (W4-07) An image request now holds each image it may make at the model's image price, then takes from the one AI budget exactly what OpenRouter said the images cost (usage.cost), with no markup; credits draw the same amount and the workspace's own key counts nothing. The server answers how many images the limit left covers and what share of the plan's monthly limit one image is, per model, so the menu can show it and pick the cheapest as default. The web side adds the OpenRouter image client (plain fetch, four at a time, 1K, refusals cost nothing) and the image models list. Nothing calls them yet: Chat (W4-08) and the editor (W4-09) wire them in. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h no Chat run (W4-09) The editor makes images outside Chat, so it has no run for Chat's hold. POST /api/internal/chat/budget/reserve-draft-images holds each image at the model's image price through the budget's own reservation (as the editor's other AI), the row tied to the draft and its images as its units; on the workspace's own key it writes the row as its own and holds nothing. It is charged and released as a Chat step is: at what the provider said it cost, no markup. A draft of another workspace is 404. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
previously approved these changes
Nov 3, 2026
8 of 13 tasks
8 of 13 tasks
…metering # Conflicts: # server/src/lib/chat-budget.test.js # server/src/routes/internal-chat-budget.js # web/src/lib/chat/budget.test.ts
…editor # Conflicts: # server/src/lib/chat-budget.test.js
cihan-gyk
dismissed
gkhngyk’s stale review
November 4, 2026 17:41
The merge-base changed after approval.
cihan-gyk
dismissed
gkhngyk’s stale review
November 4, 2026 17:46
The merge-base changed after approval.
cihan-gyk
pushed a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Nov 4, 2026
…mages ansvisor#2095 (W4-07) is now in main. The budget files keep main's ansvisor#2095 code plus ansvisor#2101's reserve-draft-images, identical to ansvisor#2101's latest (feature/image-budget-editor f80a465), and this branch's W4-09 editor additions in web/src/lib/chat/budget.ts. # Conflicts: # server/src/lib/chat-budget.test.js # server/src/routes/internal-chat-budget.js # web/src/lib/chat/budget.test.ts web/.env.example: main now documents OPENROUTER_API_KEY (W4-03); the editor's images join that entry's comment instead of a second key line. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
cihan-gyk
pushed a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Nov 4, 2026
…mages ansvisor#2101 (W4-09 server hold) is now in main. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
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
The server part of W4-09 (images in the Content Editor): an image request made in the editor is held on the one AI budget, with no Chat run.
Chat's hold (
reserve_chat_ai_usage) needs a Chat run, and the editor has none. The new endpoint uses the budget's own reservation (reserve_ai_usage), as the editor's other AI does, and ties the row to the draft.POST /api/internal/chat/budget/reserve-draft-images { orgId, draftId, model, images, ownKey? }(CRON_SECRET, as the other internal budget endpoints):imageUnitUsd, feat(chat): meter image requests on the AI budget at the provider's real cost (W4-07) #2095). The row hasfeature = 'image',content_draft_id, and its images asunits(00462).own_key, cost 0) and nothing is held, so the limit doesn't move.ai_limitwhen the budget is spent; 402 without an active plan; 403chat_off; 404 for a draft that isn't the workspace's (its brand's organization is checked)./charge(withimages: { produced, costUsd }) and/release. The charge takes exactly what the provider said it cost, no markup; credits draw the same.The rate limiter already leaves
/api/internal/chat/budget/*calls with the secret out.Stacked on #2095 (W4-07). The web part (the editor's Generate with AI) comes in its own pull request on top of this one.
Related issue
None. Chat Wave 4, W4-09 (CHAT-25 §9, CHAT-15 §E).
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
cd server && npx vitest run src/lib/chat-budget.test.js src/routes/internal-chat-budget.test.js. Covered:No migration (
reserve_ai_usagetakesfeature = 'image'since 00405,unitssince 00462). No new environment variables. No user-visible change, so no Help article.Checklist
yarn lintpassesyarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change)CI passed on this branch (08df762), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41684045979): 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