{"record":{"id":"b7064db77b38231b","repo":"jackwener/OpenCLI","slug":"hf-models-failed-http-resp-status","errorCode":null,"errorMessage":"hf models failed: HTTP ${resp.status}","messagePattern":"hf models failed: HTTP (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/hf/models.js","lineNumber":61,"sourceCode":"        url.searchParams.set('direction', '-1');\n        url.searchParams.set('limit', String(limit));\n        url.searchParams.set('full', 'true');\n        if (args.search) url.searchParams.set('search', String(args.search));\n        if (args.pipeline) url.searchParams.set('pipeline_tag', String(args.pipeline));\n\n        let resp;\n        try {\n            resp = await fetch(url, {\n                headers: {\n                    'Accept': 'application/json',\n                    'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',\n                },\n            });\n        } catch (error) {\n            throw new CommandExecutionError(`hf models request failed: ${error?.message || error}`);\n        }\n        if (!resp.ok) {\n            throw new CommandExecutionError(`hf models failed: HTTP ${resp.status}`);\n        }\n        let data;\n        try {\n            data = await resp.json();\n        } catch (error) {\n            throw new CommandExecutionError(`hf models returned malformed JSON: ${error?.message || error}`);\n        }\n        const list = Array.isArray(data) ? data : [];\n        if (list.length === 0) {\n            throw new EmptyResultError('hf models', 'No matching models on huggingface.co.');\n        }\n        return list.slice(0, limit).map((m, i) => {\n            const id = m.id || m.modelId || '';\n            const slashIdx = id.indexOf('/');\n            const author = slashIdx > 0 ? id.slice(0, slashIdx) : '';\n            const tags = Array.isArray(m.tags) ? m.tags.filter(t => !t.startsWith('license:')).slice(0, 10).join(', ') : '';\n            return {\n                rank: i + 1,","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/models.js#L43-L79","documentation":"CommandExecutionError thrown at clis/hf/models.js:61 when the HTTP response from https://huggingface.co/api/models arrives but resp.ok is false — i.e. any non-2xx status (404, 429, 5xx, etc.). The library reports the raw status code because the models endpoint does not receive per-status handling (unlike paper.js which special-cases 404 and 429).","triggerScenarios":"Hugging Face API returning an error status for GET /api/models: HTTP 429 when unauthenticated traffic is rate-limited, 5xx during HF incidents, 404/blocked responses from intermediaries, or a proxy returning an error page.","commonSituations":"Scripting the CLI in a tight loop and triggering HF rate limiting (429); huggingface.co partial outage returning 502/503; a corporate proxy returning 403 for the API path; stale DNS pinning to a wrong host returning 404.","solutions":["Read the status in the message: 429 means back off and retry after a delay; 5xx means retry later or check HF status; 403/401 from a proxy means fix proxy/auth.","Add delay/exponential backoff around the command when 429 occurs (HF throttles unauthenticated traffic).","Run curl -sS -o /dev/null -w '%{http_code}' 'https://huggingface.co/api/models?limit=1' to confirm whether the status reproduces outside the CLI.","If a proxy/CDN intercepts, bypass or reconfigure it so requests reach huggingface.co directly."],"exampleFix":"// before\nfor (const q of queries) { await run('hf models --search ' + q); } // hammers API -> 429\n// after\nfor (const q of queries) {\n  await run('hf models --search ' + q);\n  await new Promise(r => setTimeout(r, 2000)); // avoid rate limiting\n}","handlingStrategy":"retry","validationCode":"// Detect likely rate limiting before hammering the API\nconst r = await fetch('https://huggingface.co/api/models?limit=1');\nif (r.status === 429) {\n  const wait = Number(r.headers.get('retry-after') ?? 5);\n  console.error(`HF rate limited; wait ${wait}s before running hf models`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await run('hf models --search ' + q);\n} catch (e) {\n  const m = String(e.message).match(/HTTP (\\d+)/);\n  if (m && m[1] === '429') {\n    await new Promise(r => setTimeout(r, 5000)); // back off on rate limit\n    await run('hf models --search ' + q);\n  } else if (m && m[1].startsWith('5')) {\n    await new Promise(r => setTimeout(r, 30000)); // server-side issue\n  } else throw e;\n}","preventionTips":["Throttle loops over `hf models` with delays to avoid 429.","Treat 5xx as transient — retry with backoff, check HF status.","Probe the endpoint with curl to reproduce/see the raw status.","Keep unauthenticated call volume low; HF throttles anonymous traffic."],"tags":["http","api","huggingface","rate-limit"],"backgroundTag":"http-error-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}