Skip to content

Allows Mistral byok to be used for Codestral#4000

Open
chrarnoldus wants to merge 1 commit into
mainfrom
christiaan/allow-codestral-mistral
Open

Allows Mistral byok to be used for Codestral#4000
chrarnoldus wants to merge 1 commit into
mainfrom
christiaan/allow-codestral-mistral

Conversation

@chrarnoldus

Copy link
Copy Markdown
Contributor

No description provided.

@chrarnoldus chrarnoldus self-assigned this Jun 12, 2026

const byokProviderKey = fimProvider === 'mistral' ? 'codestral' : 'inception';
const byokProviderKeys: UserByokProviderId[] =
fimProvider === 'mistral' ? ['codestral', 'mistral'] : ['inception'];

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: BYOK key priority not honoured — DB orderBy(created_at) overrides the ['codestral', 'mistral'] intent

getBYOKforUser/getBYOKforOrganization query with inArray(byok_api_keys.provider_id, providerIds) and orderBy(byok_api_keys.created_at). SQL's IN (…) clause does not preserve the input array order, so when a user has both a codestral key and a mistral key the DB returns them oldest-first.

userByok?.at(0) (line 237) then picks the oldest key regardless of which provider it is. If the mistral key was created before the codestral key, the codestral key is silently ignored and the user's Mistral La Plateforme key is used with api.mistral.ai — the correct endpoint for that key type, but the codestral key preference is lost.

To honour the priority ordering, consider re-sorting the returned entries client-side by their position in byokProviderKeys before calling .at(0):

const sorted = userByok?.slice().sort(
  (a, b) => byokProviderKeys.indexOf(a.providerId) - byokProviderKeys.indexOf(b.providerId)
);
const userByokEntry = sorted?.at(0);

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

return [];
}
if (isCodestralModel(modelId)) {
providers.splice(0, 0, 'codestral');

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: Array.prototype.splice is mutating — prefer unshift or a spread

providers.splice(0, 0, 'codestral') works here because the array is local, but providers.unshift('codestral') is the conventional way to prepend in-place, and ['codestral', ...providers] (reassigning the const) makes the intent most readable. Neither change is required for correctness, but the current idiom is surprising to readers who expect splice for removal, not insertion at index 0.


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

@kilo-code-bot

kilo-code-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Executive Summary

The ['codestral', 'mistral'] priority ordering in the FIM route is silently defeated by the DB query's orderBy(created_at), meaning a user with both keys may not get the expected key-to-endpoint routing.

Overview

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

WARNING

File Line Issue
apps/web/src/app/api/fim/completions/route.ts 158 BYOK key priority ordering ['codestral', 'mistral'] not honoured — DB returns rows by created_at, so userByok?.at(0) picks the oldest key, not the preferred codestral key

SUGGESTION

File Line Issue
apps/web/src/lib/ai-gateway/byok/index.ts 32 providers.splice(0, 0, 'codestral') — unconventional; prefer providers.unshift('codestral') or ['codestral', ...providers]
Files Reviewed (4 files)
  • apps/web/src/app/api/fim/completions/route.ts — 1 issue
  • apps/web/src/lib/ai-gateway/byok/index.ts — 1 issue
  • apps/web/src/components/organizations/byok/BYOKKeysManager.tsx — no issues (rename of codestral entry to Legacy Codestral-only key and removal of (other models) suffix from mistral label)
  • apps/web/src/routers/byok-router.ts — no issues (removal of Codestral model filter from fetchSupportedModels so Codestral models now appear in the mistral provider list)

Fix these issues in Kilo Cloud


Reviewed by claude-4.6-sonnet-20260217 · 905,544 tokens

Review guidance: REVIEW.md from base branch main

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