Skip to content

fix: allow correcting API key after entering an invalid one for xAI/Gemini#11854

Merged
RomneyDa merged 9 commits into
mainfrom
cant-reenter-after-invalid
Mar 26, 2026
Merged

fix: allow correcting API key after entering an invalid one for xAI/Gemini#11854
RomneyDa merged 9 commits into
mainfrom
cant-reenter-after-invalid

Conversation

@RomneyDa
Copy link
Copy Markdown
Contributor

@RomneyDa RomneyDa commented Mar 25, 2026

Summary

When a user enters an invalid API key for a provider like xAI or Gemini, they get stuck — re-adding the same model silently creates a duplicate, and the onboarding flow appends new entries instead of updating existing ones.

Changes:

  • core.ts: When adding a model that already exists (same provider + model), show a warning toast and open the config file so the user can update their API key directly
  • onboarding.ts: setupProviderConfig now merges the new API key into existing hub-slug models instead of appending duplicates, preserving user-customized fields (roles, options, etc.)

Closes #9995

Test plan

  • Add a model (e.g. xAI Grok) with an invalid API key via Add Chat Model
  • Try to re-add the same model — verify a toast says "Model already exists in config" and the config file opens
  • Re-enter a Gemini API key through onboarding — verify the existing model is updated, not duplicated
  • Add a genuinely new model — verify it still works normally

… re-adding

When a user enters an invalid API key for a provider (e.g. xAI or Gemini)
and later tries to add the same model again with a correct key, the
addModel function previously either skipped (exact match) or created a
duplicate with a numbered suffix. Now it detects models with the same
provider and model name and updates the existing entry in-place, allowing
users to correct their API key by re-adding the model.

Closes #9995
@RomneyDa RomneyDa requested a review from a team as a code owner March 25, 2026 23:23
@RomneyDa RomneyDa requested review from sestinj and removed request for a team March 25, 2026 23:23
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 25, 2026
@continue
Copy link
Copy Markdown
Contributor

continue Bot commented Mar 25, 2026

Docs Review: No documentation updates needed.

This PR is an internal bug fix to the addModel function that makes re-adding a model with the same provider and model name update the existing entry (e.g., to correct an invalid API key) rather than skipping or creating a duplicate. This aligns the behavior with user expectations and doesn't introduce new configuration options or change how users interact with Continue — it simply makes the existing model addition workflow work correctly.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

…f appending duplicates

When re-entering an API key through the onboarding flow, setupProviderConfig
previously appended new model entries without removing the old ones with
the invalid key. Now it filters out existing models with the same hub slug
before adding the new ones, ensuring the user ends up with a single set
of correctly-configured models.
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="core/config/onboarding.ts">

<violation number="1" location="core/config/onboarding.ts:107">
P2: Filtering out existing `uses` entries and re-adding `newModels` will discard any extra configuration fields on those models (e.g., roles or options). To update an API key without losing settings, merge into the existing model entry instead of replacing it.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread core/config/onboarding.ts Outdated
Avoid overwriting user-customized fields (apiBase, completionOptions,
title, etc.) when updating an existing model. Only the apiKey is changed.
…cating

Address review feedback: update only the API key on existing model entries
to preserve user-customized fields (roles, options, etc.).

- setupProviderConfig: merge `with` into existing hub-slug models, only
  append entries for slugs not yet in config
- addModel: narrow update to only set apiKey on matching provider+model
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="core/config/onboarding.ts">

<violation number="1" location="core/config/onboarding.ts:107">
P2: This update path preserves pre-existing duplicate `uses` entries instead of collapsing them, so users with legacy duplicated models will still keep duplicates after re-entering a key.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread core/config/onboarding.ts Outdated
The YAML config model type is a union that includes uses-based models
without an apiKey property. Use 'provider' in m guard and cast to any
for the assignment.
@RomneyDa RomneyDa marked this pull request as draft March 26, 2026 01:33
…keys in onboarding

When a user tries to add a model that already exists (e.g. after entering
an invalid API key), show a warning toast and open the config file so they
can update the key directly. Also fix setupProviderConfig to merge API
keys into existing models instead of creating duplicates.

Closes #9995
@RomneyDa RomneyDa changed the title fix: update existing model API key instead of creating duplicate when re-adding fix: allow correcting API key after entering an invalid one for xAI/Gemini Mar 26, 2026
Use 'uses' in m type guards to narrow the union type instead of
casting to any.
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Issues and PRs Mar 26, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Mar 26, 2026
@RomneyDa RomneyDa marked this pull request as ready for review March 26, 2026 04:32
@RomneyDa RomneyDa merged commit 9396142 into main Mar 26, 2026
64 of 65 checks passed
@RomneyDa RomneyDa deleted the cant-reenter-after-invalid branch March 26, 2026 04:32
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Issues and PRs Mar 26, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Entering a valid API key after previously entering an incorrect one for xAI or Gemini.

2 participants