Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix: make sure custom endpoint uses own state

Gabriel Stein94cf4670ba97
diff --git a/src/components/OnboardingFlow.tsx b/src/components/OnboardingFlow.tsx
index 22dfacf83..cc4314404 100644
--- a/src/components/OnboardingFlow.tsx
+++ b/src/components/OnboardingFlow.tsx
@@ -67,6 +67,8 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
cloudTranscriptionBaseUrl,
openaiApiKey,
groqApiKey,
+ customTranscriptionApiKey,
+ setCustomTranscriptionApiKey,
dictationKey,
activationMode,
setActivationMode,
@@ -331,6 +333,8 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
setOpenaiApiKey={setOpenaiApiKey}
groqApiKey={groqApiKey}
setGroqApiKey={setGroqApiKey}
+ customTranscriptionApiKey={customTranscriptionApiKey}
+ setCustomTranscriptionApiKey={setCustomTranscriptionApiKey}
cloudTranscriptionBaseUrl={cloudTranscriptionBaseUrl}
setCloudTranscriptionBaseUrl={(url) =>
updateTranscriptionSettings({ cloudTranscriptionBaseUrl: url })
diff --git a/src/components/ReasoningModelSelector.tsx b/src/components/ReasoningModelSelector.tsx
index 3211eeb7a..703b0b455 100644
--- a/src/components/ReasoningModelSelector.tsx
+++ b/src/components/ReasoningModelSelector.tsx
@@ -59,6 +59,8 @@ interface ReasoningModelSelectorProps {
setGeminiApiKey: (key: string) => void;
groqApiKey: string;
setGroqApiKey: (key: string) => void;
+ customReasoningApiKey?: string;
+ setCustomReasoningApiKey?: (key: string) => void;
showAlertDialog: (dialog: { title: string; description: string }) => void;
}
@@ -79,6 +81,8 @@ export default function ReasoningModelSelector({
setGeminiApiKey,
groqApiKey,
setGroqApiKey,
+ customReasoningApiKey = "",
+ setCustomReasoningApiKey,
}: ReasoningModelSelectorProps) {
const [selectedMode, setSelectedMode] = useState<"cloud" | "local">("cloud");
const [selectedCloudProvider, setSelectedCloudProvider] = useState("openai");
@@ -147,11 +151,9 @@ export default function ReasoningModelSelector({
let apiKey: string | undefined;
try {
- const keyFromState = openaiApiKey?.trim();
- apiKey =
- keyFromState && keyFromState.length > 0
- ? keyFromState
- : await window.electronAPI?.getOpenAIKey?.();
+ // Use the custom reasoning API key for custom endpoints
+ const keyFromState = customReasoningApiKey?.trim();
+ apiKey = keyFromState && keyFromState.length > 0 ? keyFromState : undefined;
if (!normalizedBase.includes("://")) {
if (isMountedRef.current && latestReasoningBaseRef.current === normalizedBase) {
@@ -245,7 +247,7 @@ export default function ReasoningModelSelector({
}
}
},
- [cloudReasoningBaseUrl, openaiApiKey, reasoningModel, setReasoningModel]
+ [cloudReasoningBaseUrl, customReasoningApiKey, reasoningModel, setReasoningModel]
);
const trimmedCustomBase = customBaseInput.trim();
@@ -585,10 +587,10 @@ export default function ReasoningModelSelector({
<div className="space-y-3 pt-4">
<h4 className="font-medium text-gray-900">API Key (Optional)</h4>
<ApiKeyInput
- apiKey={openaiApiKey}
- setApiKey={setOpenaiApiKey}
+ apiKey={customReasoningApiKey}
+ setApiKey={setCustomReasoningApiKey || (() => {})}
label=""
- helpText="Optional. Sent as a Bearer token for authentication."
+ helpText="Optional. Sent as a Bearer token for authentication. This is separate from your OpenAI API key."
/>
</div>
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx
index 6b87b755a..66c7c1cd9 100644
--- a/src/components/SettingsPage.tsx
+++ b/src/components/SettingsPage.tsx
@@ -82,6 +82,10 @@ export default function SettingsPage({ activeSection = "general" }: SettingsPage
setAnthropicApiKey,
setGeminiApiKey,
setGroqApiKey,
+ customTranscriptionApiKey,
+ setCustomTranscriptionApiKey,
+ customReasoningApiKey,
+ setCustomReasoningApiKey,
setDictationKey,
updateTranscriptionSettings,
updateReasoningSettings,
@@ -642,6 +646,8 @@ export default function SettingsPage({ activeSection = "general" }: SettingsPage
setOpenaiApiKey={setOpenaiApiKey}
groqApiKey={groqApiKey}
setGroqApiKey={setGroqApiKey}
+ customTranscriptionApiKey={customTranscriptionApiKey}
+ setCustomTranscriptionApiKey={setCustomTranscriptionApiKey}
cloudTranscriptionBaseUrl={cloudTranscriptionBaseUrl}
setCloudTranscriptionBaseUrl={setCloudTranscriptionBaseUrl}
variant="settings"
@@ -681,6 +687,8 @@ export default function SettingsPage({ activeSection = "general" }: SettingsPage
setGeminiApiKey={setGeminiApiKey}
groqApiKey={groqApiKey}
setGroqApiKey={setGroqApiKey}
+ customReasoningApiKey={customReasoningApiKey}
+ setCustomReasoningApiKey={setCustomReasoningApiKey}
showAlertDialog={showAlertDialog}
/>
</div>
diff --git a/src/components/TranscriptionModelPicker.tsx b/src/components/TranscriptionModelPicker.tsx
index 8c9c2063d..7a4b68e61 100644
--- a/src/components/TranscriptionModelPicker.tsx
+++ b/src/components/TranscriptionModelPicker.tsx
@@ -41,6 +41,8 @@ interface TranscriptionModelPickerProps {
setOpenaiApiKey: (key: string) => void;
groqApiKey: string;
setGroqApiKey: (key: string) => void;
+ customTranscriptionApiKey?: string;
+ setCustomTranscriptionApiKey?: (key: string) => void;
cloudTranscriptionBaseUrl?: string;
setCloudTranscriptionBaseUrl?: (url: string) => void;
className?: string;
@@ -75,6 +77,8 @@ export default function TranscriptionModelPicker({
setOpenaiApiKey,
groqApiKey,
setGroqApiKey,
+ customTranscriptionApiKey = "",
+ setCustomTranscriptionApiKey,
cloudTranscriptionBaseUrl = "",
setCloudTranscriptionBaseUrl,
className = "",
@@ -566,10 +570,10 @@ export default function TranscriptionModelPicker({
<div className="space-y-3 pt-4">
<h4 className="font-medium text-gray-900">API Key (Optional)</h4>
<ApiKeyInput
- apiKey={openaiApiKey}
- setApiKey={setOpenaiApiKey}
+ apiKey={customTranscriptionApiKey}
+ setApiKey={setCustomTranscriptionApiKey || (() => {})}
label=""
- helpText="Optional. Sent as a Bearer token for authentication."
+ helpText="Optional. Sent as a Bearer token for authentication. This is separate from your OpenAI API key."
/>
</div>
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.js
index a2e64f521..aa3c24770 100644
--- a/src/helpers/audioManager.js
+++ b/src/helpers/audioManager.js
@@ -329,14 +329,21 @@ class AudioManager {
let apiKey = null;
if (provider === "custom") {
- // Custom endpoints: API key is optional
- // Try OpenAI key first as it's commonly used for compatible endpoints
- apiKey = await window.electronAPI.getOpenAIKey();
- if (!isValidApiKey(apiKey, "openai")) {
- apiKey = localStorage.getItem("openaiApiKey");
- }
- // For custom, we allow null/empty - the endpoint may not require auth
- if (!isValidApiKey(apiKey, "openai")) {
+ apiKey = localStorage.getItem("customTranscriptionApiKey") || "";
+ apiKey = apiKey.trim();
+
+ logger.debug(
+ "Custom STT API key retrieval",
+ {
+ provider,
+ hasKey: !!apiKey,
+ keyLength: apiKey?.length || 0,
+ keyPreview: apiKey ? `${apiKey.substring(0, 8)}...` : "(none)",
+ },
+ "transcription"
+ );
+
+ if (!apiKey) {
apiKey = null;
}
} else if (provider === "groq") {
@@ -889,7 +896,12 @@ class AudioManager {
endpoint,
method: "POST",
hasAuthHeader: !!apiKey,
- formDataFields: ["file", "model", language && language !== "auto" ? "language" : null, shouldStream ? "stream" : null].filter(Boolean),
+ formDataFields: [
+ "file",
+ "model",
+ language && language !== "auto" ? "language" : null,
+ shouldStream ? "stream" : null,
+ ].filter(Boolean),
},
"transcription"
);
@@ -1111,8 +1123,8 @@ class AudioManager {
? localStorage.getItem("cloudTranscriptionBaseUrl") || ""
: "";
- const isCustomEndpoint = currentProvider === "custom" ||
- (currentBaseUrl && currentBaseUrl !== API_ENDPOINTS.TRANSCRIPTION_BASE);
+ // Only use custom URL when provider is explicitly "custom"
+ const isCustomEndpoint = currentProvider === "custom";
// Invalidate cache if provider or base URL changed
if (
@@ -1138,7 +1150,17 @@ class AudioManager {
}
try {
- const base = currentBaseUrl.trim() || API_ENDPOINTS.TRANSCRIPTION_BASE;
+ // Use custom URL only when provider is "custom", otherwise use provider-specific defaults
+ let base;
+ if (isCustomEndpoint) {
+ base = currentBaseUrl.trim() || API_ENDPOINTS.TRANSCRIPTION_BASE;
+ } else if (currentProvider === "groq") {
+ base = API_ENDPOINTS.GROQ_BASE;
+ } else {
+ // OpenAI or other standard providers
+ base = API_ENDPOINTS.TRANSCRIPTION_BASE;
+ }
+
const normalizedBase = normalizeBaseUrl(base);
logger.debug(
@@ -1181,7 +1203,8 @@ class AudioManager {
return cacheResult(API_ENDPOINTS.TRANSCRIPTION);
}
- if (!isSecureEndpoint(normalizedBase)) {
+ // Only validate HTTPS for custom endpoints (known providers are already HTTPS)
+ if (isCustomEndpoint && !isSecureEndpoint(normalizedBase)) {
logger.warn(
"STT endpoint: HTTPS required, falling back to default",
{ attemptedUrl: normalizedBase },
@@ -1193,11 +1216,7 @@ class AudioManager {
let endpoint;
if (/\/audio\/(transcriptions|translations)$/i.test(normalizedBase)) {
endpoint = normalizedBase;
- logger.debug(
- "STT endpoint: using full path from config",
- { endpoint },
- "transcription"
- );
+ logger.debug("STT endpoint: using full path from config", { endpoint }, "transcription");
} else {
endpoint = buildApiUrl(normalizedBase, "/audio/transcriptions");
logger.debug(
diff --git a/src/helpers/clipboard.js b/src/helpers/clipboard.js
index e653d1503..daf5ad6bc 100644
--- a/src/helpers/clipboard.js
+++ b/src/helpers/clipboard.js
@@ -796,10 +796,9 @@ class ClipboardManager {
xwaylandAvailable && xdotoolExists
? " If this is an XWayland app, xdotool can also be used."
: "";
- const installNote =
- !ydotoolExists
- ? " Consider installing ydotool as an alternative (requires ydotoold daemon)."
- : " If using ydotool, ensure the ydotoold daemon is running.";
+ const installNote = !ydotoolExists
+ ? " Consider installing ydotool as an alternative (requires ydotoold daemon)."
+ : " If using ydotool, ensure the ydotoold daemon is running.";
errorMsg =
"Clipboard copied, but paste simulation failed on Wayland. Your compositor may not support the virtual keyboard protocol." +
installNote +
diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.ts
index 84b0e0a8b..5a8c9d308 100644
--- a/src/hooks/useSettings.ts
+++ b/src/hooks/useSettings.ts
@@ -39,6 +39,8 @@ export interface ApiKeySettings {
anthropicApiKey: string;
geminiApiKey: string;
groqApiKey: string;
+ customTranscriptionApiKey: string;
+ customReasoningApiKey: string;
}
export function useSettings() {
@@ -148,6 +150,25 @@ export function useSettings() {
deserialize: String,
});
+ // Custom endpoint API keys (not synced to .env - stored in localStorage only)
+ const [customTranscriptionApiKey, setCustomTranscriptionApiKey] = useLocalStorage(
+ "customTranscriptionApiKey",
+ "",
+ {
+ serialize: String,
+ deserialize: String,
+ }
+ );
+
+ const [customReasoningApiKey, setCustomReasoningApiKey] = useLocalStorage(
+ "customReasoningApiKey",
+ "",
+ {
+ serialize: String,
+ deserialize: String,
+ }
+ );
+
// Sync API keys from main process on first mount (if localStorage was cleared)
const hasRunApiKeySync = useRef(false);
useEffect(() => {
@@ -355,6 +376,10 @@ export function useSettings() {
setAnthropicApiKey,
setGeminiApiKey,
setGroqApiKey,
+ customTranscriptionApiKey,
+ setCustomTranscriptionApiKey,
+ customReasoningApiKey,
+ setCustomReasoningApiKey,
setDictationKey,
activationMode,
setActivationMode,
diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.ts
index 7e9758122..6b78a59b6 100644
--- a/src/services/ReasoningService.ts
+++ b/src/services/ReasoningService.ts
@@ -31,6 +31,19 @@ class ReasoningService extends BaseReasoningService {
}
try {
+ const provider = window.localStorage.getItem("reasoningProvider") || "";
+ const isCustomProvider = provider === "custom";
+
+ if (!isCustomProvider) {
+ logger.logReasoning("CUSTOM_REASONING_ENDPOINT_CHECK", {
+ hasCustomUrl: false,
+ provider,
+ reason: "Provider is not 'custom', using default OpenAI endpoint",
+ defaultEndpoint: API_ENDPOINTS.OPENAI_BASE,
+ });
+ return API_ENDPOINTS.OPENAI_BASE;
+ }
+
const stored = window.localStorage.getItem("cloudReasoningBaseUrl") || "";
const trimmed = stored.trim();
@@ -38,6 +51,7 @@ class ReasoningService extends BaseReasoningService {
if (!trimmed) {
logger.logReasoning("CUSTOM_REASONING_ENDPOINT_CHECK", {
hasCustomUrl: false,
+ provider,
usingDefault: true,
defaultEndpoint: API_ENDPOINTS.OPENAI_BASE,
});
@@ -48,6 +62,7 @@ class ReasoningService extends BaseReasoningService {
logger.logReasoning("CUSTOM_REASONING_ENDPOINT_CHECK", {
hasCustomUrl: true,
+ provider,
rawUrl: trimmed,
normalizedUrl: normalized,
defaultEndpoint: API_ENDPOINTS.OPENAI_BASE,
@@ -80,7 +95,8 @@ class ReasoningService extends BaseReasoningService {
logger.logReasoning("CUSTOM_REASONING_ENDPOINT_RESOLVED", {
customEndpoint: normalized,
- isCustom: normalized !== API_ENDPOINTS.OPENAI_BASE,
+ isCustom: true,
+ provider,
});
return normalized;
@@ -167,7 +183,24 @@ class ReasoningService extends BaseReasoningService {
}
}
- private async getApiKey(provider: "openai" | "anthropic" | "gemini" | "groq"): Promise<string> {
+ private async getApiKey(
+ provider: "openai" | "anthropic" | "gemini" | "groq" | "custom"
+ ): Promise<string> {
+ // For custom provider, get API key from localStorage (not from .env)
+ if (provider === "custom") {
+ const customKey = window.localStorage?.getItem("customReasoningApiKey") || "";
+ const trimmedKey = customKey.trim();
+
+ logger.logReasoning("CUSTOM_KEY_RETRIEVAL", {
+ provider,
+ hasKey: !!trimmedKey,
+ keyLength: trimmedKey.length,
+ keyPreview: trimmedKey ? `${trimmedKey.substring(0, 8)}...` : "none",
+ });
+
+ return trimmedKey;
+ }
+
let apiKey = this.apiKeyCache.get(provider);
logger.logReasoning(`${provider.toUpperCase()}_KEY_RETRIEVAL`, {
@@ -432,9 +465,13 @@ class ReasoningService extends BaseReasoningService {
agentName: string | null = null,
config: ReasoningConfig = {}
): Promise<string> {
+ const reasoningProvider = window.localStorage?.getItem("reasoningProvider") || "";
+ const isCustomProvider = reasoningProvider === "custom";
+
logger.logReasoning("OPENAI_START", {
model,
agentName,
+ isCustomProvider,
hasApiKey: false, // Will update after fetching
});
@@ -442,7 +479,7 @@ class ReasoningService extends BaseReasoningService {
throw new Error("Already processing a request");
}
- const apiKey = await this.getApiKey("openai");
+ const apiKey = await this.getApiKey(isCustomProvider ? "custom" : "openai");
logger.logReasoning("OPENAI_API_KEY", {
hasApiKey: !!apiKey,