feat(nextedit): add /api/nextedit/completions endpoint - #3481
Closed
kilo-code-bot[bot] wants to merge 3 commits into
Closed
feat(nextedit): add /api/nextedit/completions endpoint#3481kilo-code-bot[bot] wants to merge 3 commits into
kilo-code-bot[bot] wants to merge 3 commits into
Conversation
Adds a new proxy route at /api/nextedit/completions that mirrors the shape of /api/fim/completions but targets Inception's /v1/edit/completions endpoint. For now only the 'inception/' provider prefix is supported; the route accepts a chat-style messages array (single user message, no system role — Inception bakes the system prompt server-side) and returns the upstream response unchanged. Adds 'nextedit_completions' to GatewayApiKindSchema and a matching 'unsupported_nextedit_model' error type. Pricing reuses Inception's FIM per-token rates.
Contributor
Author
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryBoth previously flagged warnings have been resolved: Resolved Issues (previously flagged)
Files Reviewed (4 files)
Fix these issues in Kilo Cloud Reviewed by claude-4.6-sonnet-20260217 · 227,578 tokens Review guidance: REVIEW.md from base branch |
…tive max_tokens Address kilo-code-bot review: - Wrap parseNextEditUsageFromString in .catch so non-JSON upstream error bodies surface as Sentry events instead of silent unhandled rejections inside after(). - Constrain max_tokens to a positive integer at the schema level so values like -1 can no longer slip past the !max_tokens / >limit guard.
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
Adds a new proxy endpoint at
/api/nextedit/completionsto support next-edit (NES) requests, complementing the existing/api/fim/completionsroute. For now only Inception (Mercury Edit) is supported — the same provider used by Kilo-Org/kilocode#10536.The route mirrors the structure of
/api/fim/completions(auth → balance/org checks → BYOK lookup → upstream proxy → usage logging), but speaks the chat-stylemessagesshape that Inception's/v1/edit/completionsendpoint expects. Only models prefixedinception/are accepted; anything else returnsunsupported_nextedit_model.Changes
apps/web/src/app/api/nextedit/completions/route.ts— new POST handler. Validates the request, resolves provider from theinception/model prefix, enforces org policy (only/ignore), proxies tohttps://api.inceptionlabs.ai/v1/edit/completions, and reports usage.apps/web/src/lib/ai-gateway/llm-proxy-helpers.ts— addsextractNextEditPromptInfoandcountAndStoreNextEditUsage(reuses the Inception FIM per-token cost formula since it's the same model family).apps/web/src/lib/proxy-error-types.ts— addsunsupported_nextedit_model.packages/db/src/schema-types.ts— addsnextedit_completionstoGatewayApiKindSchemaso usage rows can be tagged distinctly fromfim_completions.Notes
/v1/edit/completionsonly accepts a singlerole: "user"message (Mercury bakes its system prompt server-side and returns 400 onrole: "system"), so the schema enforces that shape implicitly viamessages: Array(min(1))and the route forwards messages verbatim.stream: true.computeInceptionFimMicrodollarCost(0.25/0.75 microdollars per input/output token) because Mercury Edit 2 sits in the same Inception family as the existing FIM model.Verification
/api/fim/completionsroute to ensure the auth/balance/org-policy/BYOK flow is identical, with only the request/response parsing and upstream URL swapped.Visual Changes
N/A — backend-only.
Reviewer Notes
pnpm typecheckwas skipped (dependencies not installed in this sandbox; full typecheck takes long enough to disrupt the loop). CI will run it.nextedit_completionsenum value is additive; existing consumers ofGatewayApiKindaccept it as a string without further changes.martian/other providers once they expose an equivalent endpoint.