fix(providers): omit Authorization header for keyless providers (Ollama)#239
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe OpenAI-compatible provider now conditionally sends ChangesOpenAI-compatible authentication
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The OpenAICompatibleProvider.complete() and completeStream() methods unconditionally set the 'Authorization: Bearer <apiKey>' header, even when apiKey is an empty string (as happens for Ollama, which has needsApiKey: false). This caused Ollama requests to fail because the empty bearer token was sent in the Authorization header. The fetchModels() method already handled this correctly by conditionally setting the header only when apiKey is truthy. This fix applies the same conditional pattern to complete() and completeStream(), matching the existing behavior of fetchModels(). Two tests are added to verify that the Authorization header is omitted when apiKey is empty, for both the complete and completeStream code paths. Fixes 404-PF#234
5651312 to
6bf117e
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
OpenAICompatibleProvider.complete()andcompleteStream()methods unconditionally set theAuthorization: Bearer <apiKey>header, even whenapiKeyis an empty stringneedsApiKey: false), where the empty bearer token is sent in the request headerfetchModels()method already handled this correctly by conditionally setting the header only whenapiKeyis truthy — this fix applies the same pattern tocomplete()andcompleteStream()Root Cause
When using Ollama (or any provider with
needsApiKey: false),assertApiKeyAvailable()correctly returns an empty string. However, theOpenAICompatibleProviderstill sendsAuthorization: Bearer(with an empty token) in the request headers. This causes issues with Ollama's server, which rejects the malformed Authorization header.Fix
Apply the same conditional header pattern already used in
fetchModels():This is done in both
complete()andcompleteStream().Test Plan
OpenAICompatibleProvider complete omits Authorization header when apiKey is empty (Ollama)OpenAICompatibleProvider completeStream omits Authorization header when apiKey is empty (Ollama)npm run buildFixes #234
Summary by CodeRabbit