Repository navigation
[AISAGE-502] feat(gateway): route gateway traffic via KILO_AI_GATEWAY_URL - #15030
Conversation
| if (KILO_AI_GATEWAY_BASE && text === clean(KILO_AI_GATEWAY_BASE).toString().replace(/\/+$/, "")) return `${text}/` | ||
| const parts = segments(url) | ||
| const api = parts.lastIndexOf("api") | ||
| if (api < 0 || parts[api + 1] !== "v1") return undefined |
There was a problem hiding this comment.
SUGGESTION: The /api/v1 heuristic matches any base URL, not just the configured gateway
This branch treats any resolved base whose path contains an /api/v1 segment as the AI gateway root, even when it did not come from KILO_AI_GATEWAY_BASE (for example a user-configured provider.kilo.options.baseURL or an embedder baseUrl such as https://proxy.test/api/v1/custom). Those paths are truncated to .../api/v1/, which is not the legacy routing the PR description says explicit overrides keep. Restricting the match to the configured gateway base (as the line above does) would preserve override behavior; if the broader match is intentional, it is worth calling out in the description to avoid surprising custom-proxy setups.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
There was a problem hiding this comment.
Fixed in eae9c90: only the configured AI gateway base (KILO_AI_GATEWAY_URL or the default) is treated as the gateway root. Custom base URLs containing /api/v1 keep the legacy /api/openrouter and /api/gateway routing, with tests covering it.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge The incremental commit (
No memory-leak, lifecycle, or resource concerns are introduced — the diff is pure URL string computation. Files Reviewed (10 files)
Previous Review Summaries (2 snapshots, latest commit eae9c90)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit eae9c90)Status: No Issues Found | Recommendation: Merge The incremental commit ( Files Reviewed (2 files)
Previous review (commit d749650)Status: 1 Issue Found | Recommendation: Merge Overview
The routing refactor is consistent across all call sites: legacy Issue Details (click to expand)SUGGESTION
Files Reviewed (22 files)
Reviewed by deepseek-v4.1-flash · Input: 68.8K · Output: 13.5K · Cached: 897.3K Review guidance: REVIEW.md from base branch |
What
Adds a
KILO_AI_GATEWAY_URLenvironment variable that overrides the base URL for AI gateway traffic only. Kilo API traffic (auth, profile, defaults, modes, notifications, tRPC, Exa search) still usesKILO_API_URL.Which variable wins:
KILO_AI_GATEWAY_URLKILO_API_URLhttps://ai-gateway.kilo.ai/api/v1(new default)${KILO_API_URL}/api/gateway/v1${KILO_AI_GATEWAY_URL}Every gateway endpoint is a path relative to that base:
chat/completions,responses,messages,models,organizations/{id}/models,embeddings,embedding-models,transcription-models,audio/transcriptions,fim/completions, andedit/completions.Why
Gateway endpoints now live in the separate
ai-gatewayapp, and every route there is under a single/api/v1root. The old web app split them across/api/openrouter,/api/gateway,/api/fim,/api/edit, and/api/organizations/{id}/models.Since Kilo-Org/cloud#7420,
apps/webhas no gateway routes of its own. It rewrites/api/gateway/v1/:path*to the AI gateway's/api/v1/:path*, so${KILO_API_URL}/api/gateway/v1works the same as an AI gateway base. Because of that, setting onlyKILO_API_URLkeeps all gateway traffic on that server (for example a local web app), without per-endpoint route mapping.How
@kilocode/kilo-gatewayresolves the gateway base in one place (resolveKiloAiGatewayBase,KILO_AI_GATEWAY_BASE).KILO_OPENROUTER_BASEis that base, so the core Kilo plugin, the models catalogapiURL, andgenerate_imagepick it up without further changes.resolveKiloGatewayUrl(path)builds endpoint URLs for FIM, next-edit, audio transcriptions, and org model listing.CloudCataloglists models from the gateway base but still fetches defaults from the Kilo API. Gateway URLs from env vars get the same HTTPS/loopback-only validation asKILO_API_URL.Things a reviewer should know:
provider.kilo.options.baseURLand URLs embedded in tokens still route through/api/openrouterand/api/gatewayon that URL.ai-gateway.kilo.ai. Networks that only allowapi.kilo.aiwill need to allow the new host too.