Fix "Failed to fetch available models" 401 error in DeepSeek Harness
A 401 on "Failed to fetch available models" in DeepSeek Harness is an authentication failure: model discovery calls the OpenAI-compatible GET /models endpoint, and an invalid/expired API key or a base URL pointing outside the official endpoint gets rejected with 401. The rule underneath is that the base URL, key and model name must all match the same provider. Fix it in four steps: replace the key, fix the base URL, check the proxy, verify.
DeepSeek Harness 401 error text and when it triggers
The message is "Failed to fetch available models" returning 401 — when opening the model settings, switching models or sending a chat, model discovery's call to GET /models is rejected by the server. Triggers and how to read them (source):
- Open Settings → Models; the UI tries to fetch the available model list and gets 401;
- Or when switching models / starting a chat, the model discovery step fails first with 401;
- Key judgment: 401 is an authentication-layer error, not a missing model — the server never accepted your identity;
UNKNOWN_MODELis a different layer; - The search order is fixed: suspect the key first, then the base URL, then the proxy environment.
Why DeepSeek Harness 401s: invalid key, wrong base URL, proxy interference
The 401 has two root causes — an invalid key (expired, mistyped, extra whitespace) and a wrong base URL (not the official DeepSeek endpoint) — both under the rule that the base URL, key and model name must all match. In detail:
- Invalid key: model discovery calls the OpenAI-compatible
GET /modelsendpoint, and a wrong key returns 401 (source); the DeepSeek API docs confirm Bearer Token authentication (source); - Wrong base URL: pointing the base URL at a custom gateway, an old domain or an address with an extra path sends the request to the wrong endpoint, which 401s;
- Three-way match: the key is issued by DeepSeek, the base URL is the official DeepSeek endpoint, and the model name lives in the DeepSeek model list — the providers.md doc states these must match (source);
- Proxy interference: a system proxy or
HTTPS_PROXYenv var intercepting the request can make the server see malformed headers and return 401.
Fix DeepSeek Harness 401: replace the key, fix the base URL, check the proxy, verify
Follow the order credential → endpoint → environment: replace the key, fix the base URL, rule out the proxy, then re-trigger "fetch available models" to verify. Step by step:
- Replace the key — generate a fresh key on the DeepSeek open platform (confirm the account has balance and the key is not expired), and swap it in on Settings → Models; when pasting, watch for leading/trailing spaces and compare it character by character;
- Fix the base URL — confirm the provider's base URL is the official DeepSeek endpoint:
No extra path at the end; if it currently points at a custom gateway, switch to the official endpoint, or make sure the gateway and key belong to the same provider;text
https://api.deepseek.com - Check the proxy environment — run:
Ifbash
env | grep -i proxyHTTPS_PROXY/HTTP_PROXYare set, inspect the rules: addapi.deepseek.comto the direct/whitelist, or temporarily disable the global proxy and retry; - Verify — back on Settings → Models, re-trigger "fetch available models"; you should get the model list (e.g. deepseek-chat, deepseek-reasoner). Then send one test message — a normal reply means it is fixed;
- If it still 401s, restart dsh and retry — config and credentials load at startup, and changed config may not take effect until a restart.
How to verify a DeepSeek Harness 401 fix: curl the official endpoint and retry in the UI
Verification works in two layers: first use curl to test the key and endpoint directly, bypassing dsh, then re-trigger "fetch available models" in the UI — only when both pass is the fix complete. In order:
-
curl the endpoint without a key — expect a 401 as confirmation that the endpoint is reachable and authentication is actually enforced:
bashcurl -i https://api.deepseek.com/v1/modelsAn
HTTP/1.1 401response means the official endpoint works and auth is intercepting; if you do not even get a 401 (timeout / connection failure), check the network and proxy first. -
curl the endpoint with your key — a valid key should return 200 with the model list:
bashcurl https://api.deepseek.com/v1/models -H "Authorization: Bearer <your-key>"200 → key and endpoint are both correct; 401 → the key is still invalid, back to step 1 of the fix section.
-
Retry in the UI — back on Settings → Models, re-trigger "fetch available models"; you should see deepseek-chat, deepseek-reasoner and other models in the list.
-
Close with one chat message — send a test message in a session; a normal reply means the fix is complete.
Notes: DeepSeek Harness 401 — replace the key before the base URL
- 401 is an authentication problem — replace the key first, then fix the base URL; do not touch the model name.
- The base URL and key must be same-source: an official key goes with the official endpoint, a custom gateway goes with its own key.
- Rule out the proxy early:
env | grep -i proxytakes ten seconds and saves time spent on the wrong track. - Restart dsh after config changes before verifying, to avoid stale config confusing the diagnosis.
- See install error troubleshooting for other DeepSeek Harness install issues.
Sources: dshbase troubleshooting, DeepSeek API official docs, DeepSeek Harness providers.md
FAQ
A 401 in DeepSeek Harness means authentication failed: model discovery calls the OpenAI-compatible GET /models endpoint, and the server rejects the request when the key is invalid or expired, or when the base URL points somewhere other than the official DeepSeek endpoint. The base URL, key and model name must all match — replace the key first, then check the base URL (source: dshbase troubleshooting).
Tell them apart in two steps: first replace the old key with a freshly generated one and retry; if it still returns 401, check the base URL — confirm it points at the official DeepSeek endpoint (https://api.deepseek.com) rather than a custom gateway or a mistyped address. The official API docs specify Bearer Token authentication (source: DeepSeek API docs).
On Settings → Models in DeepSeek Harness, find the provider's base URL field and enter the official DeepSeek endpoint https://api.deepseek.com, save, then trigger "fetch available models" again. Do not append extra paths, and make sure the key and base URL belong to the same provider.
Yes. In DeepSeek Harness, a system or environment-variable proxy intercepting the /models request can make the server return 401. Run env | grep -i proxy to inspect HTTPS_PROXY/HTTP_PROXY, add api.deepseek.com to the bypass/whitelist, or temporarily disable the proxy; once the proxy is ruled out, go back to checking the key and base URL.
Related Terms
- 401 Unauthorized
- 401 Unauthorized is the HTTP status for failed authentication — when the API key is missing, invalid or expired, the server rejects access to protected endpoints such as /models with a 401.— DeepSeek API official docs
- GET /models endpoint
- GET /models is the OpenAI-compatible endpoint that lists available models; DeepSeek Harness's model discovery calls it to load the model list, and a failed authentication returns 401.— dshbase troubleshooting
- Base URL
- Base URL is the API endpoint of the model service provider; the official DeepSeek endpoint is https://api.deepseek.com, and the base URL, key and model name must all match the same provider.— DeepSeek API official docs
- Bearer Token authentication
- Bearer Token authentication carries an access credential in the HTTP header Authorization: Bearer <key>, which is how the DeepSeek API verifies callers.— DeepSeek API official docs