fix: allow non-OpenAI providers to skip OPENAI_API_KEY check#1207
fix: allow non-OpenAI providers to skip OPENAI_API_KEY check#1207professional-slacker wants to merge 3 commits into
Conversation
…r specific key exists - Added validation metadata to gitlawb-opengateway to indicate it doesn't require auth. - Updated getProviderValidationError to respect requiresAuth: false and provider-specific credential env vars. - This prevents mandatory OPENAI_API_KEY check from blocking other providers when an OpenAI profile is active.
jatmn
left a comment
There was a problem hiding this comment.
Findings
- [P2] Add a regression test for the Opengateway no-auth path
src/utils/providerValidation.test.ts
This PR fixes a fatal startup validation path forgitlawb-opengateway, but the provider validation tests still only cover adjacent OpenAI-compatible providers such as MiniMax, OpenRouter, DeepSeek, Moonshot, and Xiaomi MiMo. Because this bug only appears whenCLAUDE_CODE_USE_OPENAI=1,OPENAI_BASE_URLpoints atopengateway.gitlawb.com, andOPENAI_API_KEYis absent, it is easy to regress by changing descriptor routing or the fallback OpenAI key check later. Please add a focused test that assertsgetProviderValidationErrorreturnsnullfor the Opengateway base URL withoutOPENAI_API_KEY.
Ensures getProviderValidationError returns null when OPENAI_BASE_URL points at opengateway.gitlawb.com and OPENAI_API_KEY is absent.
|
Thanks for the review! I've added the requested regression tests:
Both tests verify that All 22 tests pass: |
gnanam1990
left a comment
There was a problem hiding this comment.
Thanks for tracking this down and adding the regression tests jatmn asked for — the no-auth UX problem with Gitlawb Opengateway is real and worth fixing.
A couple of things came up during local verification:
1. Typecheck regression. bun x tsc --noEmit now fails with:
src/utils/providerValidation.ts(481,66): error TS2339: Property 'kind' does not exist on type 'never'.
This is new on this branch (clean on main). The build still succeeds because the build step doesn't run tsc, but we gate on a clean typecheck.
2. The fix may already be complete via the descriptor. Tracing the validation flow for the opengateway scenario (CLAUDE_CODE_USE_OPENAI=1, base URL opengateway.gitlawb.com, no OPENAI_API_KEY): the runtime target resolves to the gateway via matchBaseUrlHosts, getDescriptorValidationError returns null, and getProviderValidationError returns null before ever reaching the new branch at lines 472–489. I confirmed empirically — reverting just the providerValidation.ts hunk and keeping only the gitlawb-opengateway.ts descriptor change, all 22 providerValidation.test.ts tests still pass, including both new ones. So the descriptor metadata is doing all the work and the providerValidation.ts changes are unreachable (which is why TS narrows to never there).
Dropping the providerValidation.ts hunk entirely would resolve the typecheck error, remove the unreachable branch, and still fix the reported bug with tests green. One small thing while you're in the descriptor: matchBaseUrlHosts lists opengateway.fly.dev alongside opengateway.gitlawb.com — is that an intentional supported host? It's not referenced anywhere else.
Could you rework down to the descriptor change (plus the tests) and confirm bun x tsc --noEmit is clean? Happy to re-review quickly after that.
Summary
This PR fixes a validation bug where OpenClaude incorrectly mandates an
OPENAI_API_KEYeven when using providers that either don't require authentication (e.g.,gitlawb-opengateway) or use their own specific environment variables (e.g.,XXXXX_API_KEY).The Problem
The current validation logic in
src/utils/providerValidation.tshas a final fallback that forcesOPENAI_API_KEYpresence ifCLAUDE_CODE_USE_OPENAIis truthy (which is often the case when an OpenAI profile is active in~/.openclaude.json).This causes:
--print), this validation error is fatal, preventing OpenClaude from running at all in automated environments.This is especially problematic for new users trying to use "FREE" providers like Gitlawb Opengateway, where they are met with a "Key required" error despite the UI promising a free, no-auth experience.
Note: This PR focuses on fixing the validation gate issues. We are aware of the deeper configuration redundancy issues (dual management between profiles and env vars) but have opted to skip addressing them in this PR to keep the scope focused on restoring immediate functionality.
Changes
getProviderValidationErrorto skip theOPENAI_API_KEYcheck if:requiresAuth: false.credentialEnvVarsare present in the environment.validationmetadata tosrc/integrations/gateways/gitlawb-opengateway.ts.Evidence (Reproduction with --print)