Skip to content

fix: pass API key for gemini/openai/openrouter in generate_candidates - #26

Open
looksg00d wants to merge 1 commit into
JayWebtech:mainfrom
looksg00d:fix/openrouter-key-not-passed-to-generate-candidates
Open

fix: pass API key for gemini/openai/openrouter in generate_candidates#26
looksg00d wants to merge 1 commit into
JayWebtech:mainfrom
looksg00d:fix/openrouter-key-not-passed-to-generate-candidates

Conversation

@looksg00d

@looksg00d looksg00d commented Jul 18, 2026

Copy link
Copy Markdown

Bug

Selecting Gemini, OpenAI, or OpenRouter as the LLM provider in Settings and entering an API key there has no effect on moment detection — it still fails with:

Set OPENROUTER_API_KEY or supply OpenRouter API Key to generate candidates.

(or the equivalent for GEMINI_API_KEY / OPENAI_API_KEY), even though the key is set in the UI, and even though the .env var isn't set at all.

Root cause

In src/main.tsx, both call sites of generate_candidates (in confirmImport() and moments()) resolve the outgoing apiKey with:

const activeKey = llmEngine === "claude" ? anthropicKey.trim() : (llmEngine === "deepseek" ? deepseekKey.trim() : "");

This only handles claude and deepseek; for gemini, openai, and openrouter it silently falls through to "" → sent as apiKey: null → the Rust side (lib.rs, generate_candidates) then only has the env var to fall back on, and errors if it isn't set.

Note runAutoPipeline() already has the correct full mapping a few lines above (used just for the pre-flight "is a key configured" check), it just was never mirrored into the two actual invoke("generate_candidates", ...) calls.

Fix

Mirror the same per-provider key mapping used in runAutoPipeline() into both generate_candidates call sites:

const activeKey =
  llmEngine === "claude" ? anthropicKey.trim() :
    llmEngine === "deepseek" ? deepseekKey.trim() :
      llmEngine === "gemini" ? geminiKey.trim() :
        llmEngine === "openai" ? openaiKey.trim() :
          llmEngine === "openrouter" ? openrouterKey.trim() : "";

Test plan

Ran into this myself with an OpenRouter key set only in Settings (no .env) — reading through the code confirmed activeKey was resolving to "" for the openrouter case, which matched the symptom exactly. The fix just mirrors the mapping already used (and working) in runAutoPipeline() a few lines above onto the two call sites that were missing it, so the logic itself isn't new/untested, just newly applied in these two spots. I have not personally re-run the full pipeline end-to-end against Gemini/OpenAI/OpenRouter after applying the fix to confirm candidate generation succeeds — flagging that in case a maintainer wants to verify before merging.

The activeKey resolution in confirmImport() and moments() only handled
the "claude" and "deepseek" llmEngine cases, falling through to an
empty string for "gemini", "openai", and "openrouter". As a result,
selecting one of those providers and entering its API key in Settings
had no effect: generate_candidates always received apiKey: null, and
the backend fell back to the OPENROUTER_API_KEY/GEMINI_API_KEY/etc. env
var, failing with e.g. "Set OPENROUTER_API_KEY or supply OpenRouter API
Key to generate candidates." even though the key was set in the UI.

runAutoPipeline() already has the correct per-provider key mapping a
few lines above; this mirrors that same mapping in both call sites of
generate_candidates.
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