fix(provider): match xAI base URL by hostname, not 'x.ai' substring#1669
Conversation
The xAI credential-mirroring checks in providerProfiles.ts used
`baseUrl.toLowerCase().includes('x.ai')`. That substring matches unrelated
hosts — e.g. `vertex.ai`, `essex.ai`, `max.ai` all contain `x.ai` — so an
OpenAI-compatible profile pointed at such a host was wrongly treated as xAI:
its api key got mirrored into XAI_API_KEY and route detection flipped to
`xai`, breaking model routing.
Route the three sites (profileSecretsAreComplete, the openAI profile-env
builder, and the active-profile env builder) through the existing
`isXaiBaseUrl` helper, which matches `hostname === 'api.x.ai'` — consistent
with how isFireworksBaseUrl/isNearaiBaseUrl are already used in this file.
Add a regression test asserting a `vertex.ai` profile does not set
XAI_API_KEY and is not detected as the xai provider.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📜 Recent review details⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🧰 Additional context used📓 Path-based instructions (5)**/*.{ts,tsx,js,jsx,py}📄 CodeRabbit inference engine (CONTRIBUTING.md)
Files:
**/*⚙️ CodeRabbit configuration file
Files:
{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}⚙️ CodeRabbit configuration file
Files:
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}⚙️ CodeRabbit configuration file
Files:
**⚙️ CodeRabbit configuration file
Files:
🔇 Additional comments (2)
📝 WalkthroughWalkthroughReplaces the substring-based ChangesXAI URL Detection Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 6 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
jatmn
left a comment
There was a problem hiding this comment.
Thanks for the contribution. I do not see any actionable issues from my review.
@kevincodex1 LGTM
Problem
The xAI credential-mirroring checks in
src/utils/providerProfiles.tsmatched the base URL with a raw substring:x.aiis a substring of unrelated hostnames —vertex.ai,essex.ai,max.ai,prox.aiall contain it. So an OpenAI-compatible profile pointed at such a host was wrongly treated as xAI:XAI_API_KEY, andgetAPIProvider) flipped toxai,which breaks model routing for that profile.
This file already imports
isFireworksBaseUrl/isNearaiBaseUrlfromrouteMetadataand uses them for exactly this kind of check; the xAI sites were just inconsistent leftovers. A matchingisXaiBaseUrlhelper already exists and matcheshostname === 'api.x.ai'.Fix
Route the three xAI sites through
isXaiBaseUrl:profileSecretsAreCompleteopenAIProfileEnv.XAI_API_KEY)env.XAI_API_KEY)No behavior change for real xAI profiles (
https://api.x.ai/v1); lookalike hosts are no longer misrouted.Test
Added a regression test in
providerProfiles.test.ts: a profile withbaseUrl: https://vertex.ai/v1does not setXAI_API_KEYand is not detected as thexaiprovider. Verified it fails before the fix and passes after.tsc --noEmitclean; fullproviderProfiles.test.tssuite green (91 tests).Summary by CodeRabbit
Bug Fixes
Tests