Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: clear the API key when the connection type changes (#16842)

Nilayf8eedf8f753b
diff --git a/studio/frontend/src/features/chat/chat-providers-dialog.tsx b/studio/frontend/src/features/chat/chat-providers-dialog.tsx
index f645948b613..de4093ec3e4 100644
--- a/studio/frontend/src/features/chat/chat-providers-dialog.tsx
+++ b/studio/frontend/src/features/chat/chat-providers-dialog.tsx
@@ -371,6 +371,9 @@ export function ChatProvidersSettings({
const chooseProviderType = (value: string) => {
if (editingProviderId) return;
+ if (!(isOpenCodeProviderType(providerType) && isOpenCodeProviderType(value))) {
+ setApiKey("");
+ }
setProviderType(value);
setReasoningConfig(null);
setAvailableModels([]);
diff --git a/studio/frontend/tests/connections-type-switch-api-key.test.ts b/studio/frontend/tests/connections-type-switch-api-key.test.ts
new file mode 100644
index 00000000000..a65c402c73b
--- /dev/null
+++ b/studio/frontend/tests/connections-type-switch-api-key.test.ts
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { readSrc } from "./helpers/kit.ts";
+
+const dialog = readSrc("features/chat/chat-providers-dialog.tsx");
+const chooseProviderType =
+ dialog.match(/const chooseProviderType = \(value: string\) => \{[\s\S]*?\n {2}\};/)?.[0] ?? "";
+
+test("changing the connection type drops the typed API key", () => {
+ assert.notEqual(chooseProviderType, "");
+ assert.match(chooseProviderType, /setApiKey\(""\)/);
+});
+
+test("switching between the two OpenCode plans keeps the API key", () => {
+ assert.match(
+ chooseProviderType,
+ /if \(!\(isOpenCodeProviderType\(providerType\) && isOpenCodeProviderType\(value\)\)\) \{\s*setApiKey\(""\);\s*\}/,
+ );
+});