Problem
When configuring an Anthropic-compatible provider (e.g., api.anthropic.com or third-party providers using the Anthropic protocol), clicking "Fetch Models" returns HTTP 401 Unauthorized.
Root Cause
The fetch_models function in src-tauri/src/services/model_fetch.rs only sends the Authorization: Bearer <key> header for all providers:
.header("Authorization", format!("Bearer {api_key}"))
However, Anthropic's API requires:
x-api-key: <key> (primary authentication)
anthropic-version: 2023-06-01 (required version header)
The Authorization: Bearer header alone is not accepted by Anthropic endpoints, causing 401 errors.
Additionally: URL candidate ordering
The build_models_url_candidates function currently prefers /v1/models first for non-versioned URLs, which happens to be correct for Anthropic. However, without the proper auth headers, the correct URL still returns 401.
Reference
This issue was also fixed in the downstream fork:
The fix introduces a ModelFetchStrategy enum that sends provider-appropriate headers:
Bearer → Authorization: Bearer <key> (OpenAI style)
Anthropic → Authorization: Bearer <key> + x-api-key + anthropic-version
GoogleApiKey → x-goog-api-key (Gemini style)
Expected Behavior
Model fetching should work correctly for Anthropic-compatible endpoints by sending the appropriate authentication headers.
Problem
When configuring an Anthropic-compatible provider (e.g.,
api.anthropic.comor third-party providers using the Anthropic protocol), clicking "Fetch Models" returns HTTP 401 Unauthorized.Root Cause
The
fetch_modelsfunction insrc-tauri/src/services/model_fetch.rsonly sends theAuthorization: Bearer <key>header for all providers:However, Anthropic's API requires:
x-api-key: <key>(primary authentication)anthropic-version: 2023-06-01(required version header)The
Authorization: Bearerheader alone is not accepted by Anthropic endpoints, causing 401 errors.Additionally: URL candidate ordering
The
build_models_url_candidatesfunction currently prefers/v1/modelsfirst for non-versioned URLs, which happens to be correct for Anthropic. However, without the proper auth headers, the correct URL still returns 401.Reference
This issue was also fixed in the downstream fork:
The fix introduces a
ModelFetchStrategyenum that sends provider-appropriate headers:Bearer→Authorization: Bearer <key>(OpenAI style)Anthropic→Authorization: Bearer <key>+x-api-key+anthropic-versionGoogleApiKey→x-goog-api-key(Gemini style)Expected Behavior
Model fetching should work correctly for Anthropic-compatible endpoints by sending the appropriate authentication headers.