Fix API key initialization crash preventing first-time users from accessing settings#13
Merged
tmaier-kettering merged 6 commits intoSep 26, 2025
Conversation
… API key Co-authored-by: tmaier-kettering <109093855+tmaier-kettering@users.noreply.github.com>
Copilot
AI
changed the title
Currently new users cannot use the software because the api_key must be set but users obviously can't do that if they can't open the software to write their api key into the settings menu.
The full error message currently popping up is:
"Failed to exe...
Fix API key initialization crash preventing first-time users from accessing settings
Sep 25, 2025
Co-authored-by: tmaier-kettering <109093855+tmaier-kettering@users.noreply.github.com>
Co-authored-by: tmaier-kettering <109093855+tmaier-kettering@users.noreply.github.com>
…0-42a3-9c3b-7a57f732649d Implement user-specific settings storage to prevent writing to application config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
New users could not use CodebookAI because the application crashed on startup when no OpenAI API key was configured. The error message was:
This created a catch-22 situation: users needed an API key to open the application, but they needed the application to be running to access the Settings menu where they could enter their API key.
Root Cause
The issue was in
settings/models_registry.pywhere the OpenAI client was instantiated at module import time:Since
main.pyimports frommodels_registry, the application would crash during startup before the GUI could even load.Solution
This PR implements graceful API key handling with minimal changes:
1. Safe Client Initialization
Modified
models_registry.pyto handle missing API keys gracefully:2. User-Friendly Error Messages
Updated
batch_method.pyto provide clear guidance instead of crashing:3. Client Refresh Mechanism
Added
refresh_client()function and integrated it into the settings workflow so the client is properly reinitialized when users save their API key.User Experience
Before this fix:
After this fix:
Impact
models_registry.py,batch_method.py,settings_window.pyThis fix resolves the primary blocker preventing new users from adopting CodebookAI while maintaining backward compatibility for existing users.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/tmaier-kettering/tmaier-kettering%2FCodebookAI/languages/home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.