Skip to content

feat(ai-gateway): use TENCENT_FREE_API_KEY for free Tencent model in Vercel settings - #5128

Closed
chrarnoldus wants to merge 2 commits into
mainfrom
aromatic-collision
Closed

chrarnoldus wants to merge 2 commits into
mainfrom
aromatic-collision

Conversation

@chrarnoldus

Copy link
Copy Markdown
Contributor

Configure applyVercelSettings so that in the non-user-BYOK case, when routing the free Tencent model (tencent/hy3:free / tencent/hy3) and TENCENT_FREE_API_KEY is set, the API key is passed in providerOptions.gateway.byok.

@chrarnoldus chrarnoldus self-assigned this Aug 7, 2026
};

export function isTencentFreeModel(model: string): boolean {
return model === tencent_hy3_free_model.public_id || model === tencent_hy3_free_model.internal_id;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: isTencentFreeModel('tencent/hy3') also matches the internal (non-:free) id, which the rest of the gateway treats as a paid model

isFreeModel('tencent/hy3') returns false (no :free suffix, not a kilo-exclusive public_id, not auto-free), so a direct client request for tencent/hy3 is balance-gated and billed as a paid model (route.ts rejects zero-balance users for non-free models) — yet when such a request routes to Vercel it now carries the free TENCENT_FREE_API_KEY in providerOptions.gateway.byok. If tencent/hy3 is requestable as a paid catalog model, paying users would be served (and potentially rate-limited) by the free key while being billed paid rates. If only the :free public id should ever receive this key, drop the internal_id match here; otherwise please confirm the paid-id billing semantics are intended.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

const request: GatewayRequest = {
kind: 'chat_completions',
body: {
model: 'anthropic/claude-sonnet-4.5',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: This test uses anthropic/claude-sonnet-4.5, so it cannot catch the regression its title describes

Since isTencentFreeModel('anthropic/claude-sonnet-4.5') is always false, this test would still pass even if the Tencent byok block were later moved so it also runs in the userByok branch. Using tencent/hy3:free as the requested model together with a user BYOK entry would actually exercise the "does not override userByok" guard this test is named for.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Comment thread ENVIRONMENT.md
- `OPENAI_API_KEY` - OpenAI API key; used in `apps/web/src/lib/ai-gateway/embeddings/embedding-providers.ts` for the `text-embedding-3-small` embedding model, and as a provider config in `apps/web/src/lib/config.server.ts`. `[SECRET]`
- `MISTRAL_API_KEY` - Mistral API key; used in `apps/web/src/lib/ai-gateway/embeddings/embedding-providers.ts` for `codestral-embed-2505` and `mistral-embed` embeddings, in the FIM completions proxy at `apps/web/src/app/api/fim/completions/route.ts` (routes Mistral Codestral vs. La Plateforme keys), and as a provider config in `apps/web/src/lib/config.server.ts`. `[SECRET]`
- `STREAMLAKE_API_KEY` - StreamLake API key for model inference through the AI gateway; provider definition in `apps/web/src/lib/ai-gateway/providers/provider-definitions.ts`. `[SECRET]`
- `TENCENT_FREE_API_KEY` - API key for the free Tencent model when routed through Vercel AI Gateway. `[SECRET]`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Consider also adding TENCENT_FREE_API_KEY to .env.local.example

The other optional AI provider keys documented in this section (OPENAI_API_KEY, MISTRAL_API_KEY, STREAMLAKE_API_KEY, XAI_API_KEY) are also listed in .env.local.example, which dev/local/setup-env.ts parses during local setup. Adding the new key there keeps local-dev discoverability consistent.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The follow-up commit correctly restricts isTencentFreeModel to the public :free id and strengthens the userByok precedence test, resolving both prior code findings; only the .env.local.example documentation gap for TENCENT_FREE_API_KEY remains open.

Overview

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

SUGGESTION

File Line Issue
ENVIRONMENT.md 238 New TENCENT_FREE_API_KEY not added to .env.local.example alongside the other optional provider keys
Files Reviewed (4 files)
  • ENVIRONMENT.md - 1 issue
  • apps/web/src/lib/ai-gateway/models.test.ts - 0 issues
  • apps/web/src/lib/ai-gateway/providers/tencent.ts - 0 issues
  • apps/web/src/lib/ai-gateway/providers/vercel/index.test.ts - 0 issues

Fix these issues in Kilo Cloud

Previous Review Summary (commit 48125e3)

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

Previous review (commit 48125e3)

Status: 3 Issues Found | Recommendation: Address before merge

Executive Summary

The Vercel BYOK wiring for the free Tencent model is well-tested, but isTencentFreeModel also matches the paid internal id tencent/hy3, creating a billing/key-selection inconsistency that should be confirmed before merge.

Overview

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

WARNING

File Line Issue
apps/web/src/lib/ai-gateway/providers/tencent.ts 19 isTencentFreeModel matches internal id tencent/hy3, which isFreeModel and balance gating treat as a paid model — Vercel-routed paid requests would carry the free key

SUGGESTION

File Line Issue
apps/web/src/lib/ai-gateway/providers/vercel/index.test.ts 272 userByok-override test uses a non-Tencent model, so it cannot fail if the Tencent byok logic leaks into the userByok branch
ENVIRONMENT.md 238 New TENCENT_FREE_API_KEY not added to .env.local.example alongside the other optional provider keys
Files Reviewed (7 files)
  • ENVIRONMENT.md - 1 issue
  • apps/web/src/lib/ai-gateway/models.test.ts - 0 issues
  • apps/web/src/lib/ai-gateway/providers/openrouter/inference-provider-id.ts - 0 issues
  • apps/web/src/lib/ai-gateway/providers/tencent.ts - 1 issue
  • apps/web/src/lib/ai-gateway/providers/vercel/index.test.ts - 1 issue
  • apps/web/src/lib/ai-gateway/providers/vercel/index.ts - 0 issues
  • apps/web/src/lib/ai-gateway/providers/vercel/mapModelIdToVercel.test.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by kimi-k3 · Input: 28.7K · Output: 8.1K · Cached: 498.7K

Review guidance: REVIEW.md from base branch main

@chrarnoldus chrarnoldus closed this Aug 7, 2026
@chrarnoldus
chrarnoldus deleted the aromatic-collision branch August 7, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant