Skip to content

Commit f963c8d

Browse files
authored
Merge pull request #91 from Miyamura80/feat/optional-api-keys
Make API keys optional & add code quality TODOs
2 parents 6756ba5 + 47e0030 commit f963c8d

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

TODO.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,19 @@
44

55
- [ ] Integrate [Strix](https://github.com/usestrix/strix) - **Requires human supervision**
66
- [ ] Re-init Postgres API key due to potential leak
7+
8+
## Code Quality
9+
10+
### High Priority
11+
12+
- [ ] Broad exception handling in `src/utils/logging_config.py:64` - catches all exceptions indiscriminately
13+
- [ ] Validator anti-pattern in `common/global_config.py:188-198` - validators ignore input parameter `v`
14+
- [ ] Circular import risk in `common/flags.py:6-7` - `setup_logging()` called at import time
15+
- [ ] Broad exceptions in `utils/llm/dspy_langfuse.py:280,321,438` - catches generic `Exception`
16+
- [ ] Unsafe exception re-instantiation in `src/utils/logging_config.py:61-71` - reconstructs exceptions unsafely
17+
18+
### Medium Priority
19+
20+
- [ ] Type ignore comments in `utils/llm/dspy_langfuse.py` - indicates type system gaps
21+
- [ ] Limited test coverage for `init/`, `utils/llm/` directories
22+
- [ ] Feature flag not checked in all fallback paths

common/global_config.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ class Config(BaseSettings):
172172
logging: LoggingConfig
173173
features: FeaturesConfig = Field(default_factory=lambda: FeaturesConfig())
174174

175-
# Environment variables (required)
175+
# Environment variables
176176
DEV_ENV: str
177-
OPENAI_API_KEY: str
178-
ANTHROPIC_API_KEY: str
179-
GROQ_API_KEY: str
180-
PERPLEXITY_API_KEY: str
181-
GEMINI_API_KEY: str
177+
OPENAI_API_KEY: str | None = None
178+
ANTHROPIC_API_KEY: str | None = None
179+
GROQ_API_KEY: str | None = None
180+
PERPLEXITY_API_KEY: str | None = None
181+
GEMINI_API_KEY: str | None = None
182182

183183
# Runtime environment (computed)
184184
is_local: bool = Field(default=False)
@@ -252,7 +252,13 @@ def llm_api_key(self, model_name: str | None = None) -> str:
252252
"gemini": self.GEMINI_API_KEY,
253253
}
254254
if provider in api_keys:
255-
return api_keys[provider]
255+
key = api_keys[provider]
256+
if key is None:
257+
raise ValueError(
258+
f"API key for provider '{provider}' is not configured. "
259+
f"Set {provider.upper()}_API_KEY in your .env file."
260+
)
261+
return key
256262
raise ValueError(f"No API key configured for model: {model_identifier}")
257263

258264

0 commit comments

Comments
 (0)