fix: use per-provider env key for custom providers in Models dialog#737
fix: use per-provider env key for custom providers in Models dialog#737365diascollaboration-prog wants to merge 5 commits into
Conversation
Custom providers with unrecognised base URLs all resolved to the shared CUSTOM_API_KEY env var via expectedEnvKeyForUrl(). Adding a second custom provider with a different URL would overwrite the first provider's key, making it impossible to run two custom providers simultaneously. Introduce customProviderEnvKey() that falls back to CUSTOM_PROVIDER_<NAME>_KEY (matching the naming already used by seedDefaults() in models.ts) when the URL is not in URL_KEY_MAP. Apply the same key derivation in openEditModal() so the field reads back the correct value, with a fallback to CUSTOM_API_KEY for keys written by older versions. Fixes fathah#681
|
Thanks for the fix. The direction makes sense, but I think this currently only fixes the Models dialog storage/display side, not the full runtime path. For known custom-compatible hosts, this should still work because we already resolve URL-specific env vars like The issue is unknown custom base URLs. This PR saves the key as:
But the active chat/gateway path does not consistently read that key. In the normal active config path, unknown custom URLs still rely on Can we either:
Without one of those, this may regress unknown custom providers even though the dialog looks correct. |
…E>_KEY config-health was not aware of per-provider env keys written by the Models dialog and seedDefaults(), so it could report MODEL_KEY_MISSING even when the gateway runtime would resolve the key correctly. Mirror the same baseUrl->name lookup that hermes.ts already uses so the health check and the runtime stay in sync.
|
Thanks for the detailed review, fathah. You're right that the original PR only covered the dialog side. I've pushed a second commit that extends customEndpointKeyResolvable() in config.ts to also resolve CUSTOM_PROVIDER__KEY:
This way the config-health path and the runtime gateway path stay in sync — no false MODEL_KEY_MISSING warning for a provider whose key was saved under CUSTOM_PROVIDER__KEY. The gateway runtime at hermes.ts:startGateway already had the CUSTOM_PROVIDER__KEY fallback (lines 2370–2383), so chat itself should resolve the key correctly once it's written. The gap was only in the health-check side, which this commit closes. |
- Fix import ordering in Models.tsx: customProviderEnvKey() was declared between two import blocks. - Clean up orphaned CUSTOM_PROVIDER_<NAME>_KEY env entries when a custom provider is renamed or deleted (new deleteEnvValue/ sshDeleteEnvValue + delete-env IPC handler + preload deleteEnv). - customEndpointKeyResolvable now checks every model sharing a base URL instead of only the first find() match, so a second custom provider on the same unknown host no longer gets a false "key missing" warning.
|
Pushed a follow-up commit addressing all three review points:
Added |
|
T-Rex pricing update — T-Rex was free through June 2026. Effective July 1, 2026, T-Rex adds 2 credits on top of the standard 1-credit review (3 total). T-Rex settings |
envKeyUsedByOtherModel() checks the in-memory models list before handleSave/handleDelete call deleteEnv, so renaming or removing one custom provider no longer wipes a key another entry still resolves to (e.g. two custom entries on the same known vendor host sharing GROQ_API_KEY, or two unknown-host entries with the same name).
Problem
When adding multiple custom providers with unrecognised base URLs, they all resolve to the shared
CUSTOM_API_KEYenv var viaexpectedEnvKeyForUrl(). The second provider's key silently overwrites the first, making it impossible to run two custom providers simultaneously. Closes #681.Root cause
expectedEnvKeyForUrl()returnsCUSTOM_API_KEYas a fallback for any URL not inURL_KEY_MAP. The save path inhandleSave()and the read-back path inopenEditModal()both use this function, so all unknown-URL providers share one bucket.Note:
seedDefaults()inmodels.tsalready writesCUSTOM_PROVIDER_<NAME>_KEYcorrectly for providers seeded fromconfig.yaml. This fix brings the GUI dialog into alignment with that existing behavior.Fix
Introduce
customProviderEnvKey(name, baseUrl)— a thin wrapper overexpectedEnvKeyForUrlthat falls back toCUSTOM_PROVIDER_<NAME>_KEY(same naming asseedDefaults) instead of the sharedCUSTOM_API_KEYwhen the URL is unknown.Three call-site changes, all in
Models.tsx:handleSave()— writes the per-provider keyopenEditModal()— reads the per-provider key, falls back toCUSTOM_API_KEYfor keys written by older versionsTesting
.env(CUSTOM_PROVIDER_<NAME>_KEY)