Skip to content

fix: send a single auth header when listing models and testing keys - #8445

Open
MFA-G wants to merge 1 commit into
janhq:mainfrom
MFA-G:fix/single-auth-header-model-list
Open

fix: send a single auth header when listing models and testing keys#8445
MFA-G wants to merge 1 commit into
janhq:mainfrom
MFA-G:fix/single-auth-header-model-list

Conversation

@MFA-G

@MFA-G MFA-G commented Jul 17, 2026

Copy link
Copy Markdown

Problem

For an OpenAI-compatible custom provider, Jan sends both authentication headers when testing an API key and refreshing the model list:

Authorization: *** <key>
x-api-key: <key>

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() in remoteModelCatalog.ts and use it in the three request paths that previously hard-coded both headers:

  • TauriProvidersService.fetchModelsFromProvider (services/providers/tauri.ts)
  • fetchTopRemoteModelsbuildHeaders (lib/remoteModelCatalog.ts)
  • handleTestApiKeys (routes/settings/providers/$providerName.tsx)

Behavior now matches how chat requests already authenticate in model-factory.ts:

  • Anthropic-shaped providers (api_type === 'anthropic', or name/host contains anthropic) → x-api-key
  • Everything else (OpenAI-compatible) → Authorization: *** <key>

The key-test path additionally gains the default anthropic-version / browser-access headers (via the existing ensureAnthropicHeaders), 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 only Authorization (no x-api-key); Anthropic sends only x-api-key (no Authorization).
  • services/providers/__tests__/tauri.test.ts — same, plus an anthropic-shaped custom provider case.

Validation:

  • yarn vitest --run on the three affected files: 79 tests pass.
  • Full web-app suite: 2786 tests pass (the one unrelated failing file, services/core/__tests__/tauri.test.ts, fails only because the @janhq/assistant-extension workspace package isn't built in this environment — unrelated to this change).
  • yarn eslint on all changed source files: clean.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

bug: OpenAI-compatible key test sends both Authorization and x-api-key headers

1 participant