Skip to content

fix(web): tag ChatGPT BYOK models and skip its balance gate - #6310

Merged
iscekic merged 3 commits into
mainfrom
test/chatgpt-byok-e2e
Sep 18, 2026
Merged

iscekic merged 3 commits into
mainfrom
test/chatgpt-byok-e2e

Conversation

@iscekic

@iscekic iscekic commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

An enabled "Sign in with ChatGPT" connection now behaves like a user BYOK credential in two places:

  1. Models list. GET /api/openrouter/models tags every OpenAI model the ChatGPT project serves with hasUserByokAvailable: true. The model picker and the extension then show the BYOK badge, matching the pasted-key path. The tag reuses the same served-model gate as routing, so only models the delegated route can carry are tagged; -pro aliases, gpt-oss, and Kilo-exclusive slugs stay untagged.
  2. Credit gate. The delegated route no longer blocks a zero-balance account with 402 Paid Model - Credits Required. The request bills the ChatGPT plan, not Kilo credits. A new skipBalanceCheck provider flag carries this; abuse and organization policy checks still apply.

Verification

Manual paths on the local stack (http://localhost:5200) with a personal user and a real ChatGPT connection:

  • POST /api/openrouter/responses (openai/gpt-5-nano) at zero balance: server logged Routing request to openai-chatgpt; OpenAI returned 429 subscription_sharing_usage_limit_exceeded. No 402. The account is at its sharing quota, so no 200.
  • Control POST /api/openrouter/responses (anthropic/claude-sonnet-4) at zero balance: still 402, so the gate is unchanged for other providers.
  • GET /api/openrouter/models: 44 of 60 OpenAI models tagged hasUserByokAvailable: true; openai/gpt-5.6-luna-pro, openai/gpt-oss-120b, and openai/gpt-5.6-sol-discounted untagged.
  • The web model picker is gated behind repo-provider onboarding, so the tag was verified at the API that feeds both the picker and the extension.

Visual Changes

N/A

Reviewer Notes

  • Cloud-agent session creation still uses computeCloudAgentNextBalanceCheckEligibility, which does not know about the ChatGPT connection. A zero-balance user can still hit the worker-side $1 minimum. Out of scope for this change.
  • getOpenAiChatGptByokModelIds reads the connection once and calls the cached served-model lookup per OpenAI model.

…edit gate

Tag models the ChatGPT connection serves with `hasUserByokAvailable`, so the
model picker and the extension show the BYOK badge like pasted BYOK keys. The
tag reuses the same served-model gate as routing, so only models the delegated
route can carry are tagged.

Skip the zero-balance paid-model block when the ChatGPT subscription pays for
the request. The request bills the ChatGPT plan, not Kilo credits, so a
zero-balance account must not be blocked before reaching OpenAI. Abuse and
organization policy checks still apply.
@iscekic iscekic self-assigned this Sep 18, 2026
Comment thread apps/web/src/app/api/openrouter/models/route.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The follow-up commit 297117e6f adds a Jest module mock for @/lib/ai-gateway/openai-chatgpt/routing in the models catalog suite; the mock signature matches the real tagOpenAiChatGptByokModels contract and introduces no correctness, security, or reliability issues.

Files Reviewed (1 file)
  • apps/web/src/tests/openrouter-models.test.ts
Previous Review Summaries (2 snapshots, latest commit 33a69d2)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 33a69d2)

Status: No Issues Found | Recommendation: Merge

Executive Summary

The follow-up commit 33a69d21e moves ChatGPT BYOK tagging into getAvailableModelsForOrganization, closing the organization-catalog gap from the prior review; the changed code introduces no new correctness, security, or reliability issues.

Files Reviewed (6 files)
  • apps/web/src/app/api/openrouter/models/route.test.ts
  • apps/web/src/app/api/openrouter/models/route.ts
  • apps/web/src/lib/ai-gateway/openai-chatgpt/routing.test.ts
  • apps/web/src/lib/ai-gateway/openai-chatgpt/routing.ts
  • apps/web/src/lib/organizations/organization-models.test.ts
  • apps/web/src/lib/organizations/organization-models.ts

Previous review (commit 66f0f23)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
apps/web/src/app/api/openrouter/models/route.ts 84 ChatGPT BYOK tag skipped for organization members
Files Reviewed (7 files)
  • apps/web/src/app/api/openrouter/[...path]/route.test.ts
  • apps/web/src/app/api/openrouter/[...path]/route.ts
  • apps/web/src/app/api/openrouter/models/route.test.ts
  • apps/web/src/app/api/openrouter/models/route.ts - 1 issue
  • apps/web/src/lib/ai-gateway/openai-chatgpt/routing.test.ts
  • apps/web/src/lib/ai-gateway/openai-chatgpt/routing.ts
  • apps/web/src/lib/ai-gateway/providers/get-provider.ts

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

An organization member resolves an eligible ChatGPT request through their
personal connection, but the organization catalog only tagged organization
BYOK keys. Apply the same tag in getAvailableModelsForOrganization for member
subjects, so the organization model pickers and the extension match the
personal list.

Share the tag through tagOpenAiChatGptByokModels so the personal and
organization catalog paths cannot drift.
The models route now reads the ChatGPT connection, but this suite's drizzle
mock has no `where`, so every authenticated request returned 500. Mock
`tagOpenAiChatGptByokModels` in the suite, like the route test does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

human-ready The PR is ready for human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants