fix: send a single auth header when listing models and testing keys - #8445
Open
MFA-G wants to merge 1 commit into
Open
fix: send a single auth header when listing models and testing keys#8445MFA-G wants to merge 1 commit into
MFA-G wants to merge 1 commit into
Conversation
For OpenAI-compatible custom providers, the model-list and key-test requests sent both `Authorization: *** <key>` and `x-api-key: <key>`. Some upstreams reject mixed auth: AWS Bedrock Mantle answers 401 "request must not include both 'authorization' and 'x-api-key' headers", so a valid key fails the key test and model refresh. Add applyProviderAuthHeader() and use it in the three request paths (fetchModelsFromProvider, fetchTopRemoteModels, handleTestApiKeys): Anthropic-shaped providers authenticate via x-api-key, everything else uses Authorization: *** This mirrors how chat requests already pick exactly one auth header per provider in model-factory. The key-test path also gains the default anthropic-version / browser-access headers so Anthropic key tests behave like model refreshes. Fixes janhq#8444
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
For an OpenAI-compatible custom provider, Jan sends both authentication headers when testing an API key and refreshing the model list:
Some upstreams reject requests that carry both. AWS Bedrock Mantle answers
401 Unauthorized:{ "error": { "code": "invalid_api_key", "message": "request must not include both 'authorization' and 'x-api-key' headers" } }So a valid key fails Test keys and model refresh, even though normal chat requests work (they already send only the bearer header).
Fixes #8444.
Fix
Add
applyProviderAuthHeader()inremoteModelCatalog.tsand use it in the three request paths that previously hard-coded both headers:TauriProvidersService.fetchModelsFromProvider(services/providers/tauri.ts)fetchTopRemoteModels→buildHeaders(lib/remoteModelCatalog.ts)handleTestApiKeys(routes/settings/providers/$providerName.tsx)Behavior now matches how chat requests already authenticate in
model-factory.ts:api_type === 'anthropic', or name/host containsanthropic) →x-api-keyAuthorization: *** <key>The key-test path additionally gains the default
anthropic-version/ browser-access headers (via the existingensureAnthropicHeaders), so an Anthropic key test behaves the same as a model refresh.Tests
Updated/added unit tests asserting exactly one auth header per provider type:
lib/__tests__/remoteModelCatalog.test.ts— OpenAI sends onlyAuthorization(nox-api-key); Anthropic sends onlyx-api-key(noAuthorization).services/providers/__tests__/tauri.test.ts— same, plus an anthropic-shaped custom provider case.Validation:
yarn vitest --runon the three affected files: 79 tests pass.services/core/__tests__/tauri.test.ts, fails only because the@janhq/assistant-extensionworkspace package isn't built in this environment — unrelated to this change).yarn eslinton all changed source files: clean.