jackwener/OpenCLI · error · ArgumentError

hf models limit must be <= 100

Error message

hf models limit must be <= 100

What it means

ArgumentError thrown at clis/hf/models.js:38 when the --limit argument is a valid positive integer but exceeds the CLI's hard cap of 100, which matches a single page of the Hugging Face /api/models endpoint. The library enforces this client-side rather than silently truncating or making paginated requests.

Source

Thrown at clis/hf/models.js:38

    args: [
        { name: 'sort', type: 'string', default: 'downloads', help: `Sort key: ${SORT_OPTIONS.join(', ')}` },
        { name: 'search', type: 'string', required: false, help: 'Optional name/owner substring filter (e.g. "llama", "mistralai/")' },
        { name: 'pipeline', type: 'string', required: false, help: 'Filter by pipeline tag (e.g. text-generation, image-classification)' },
        { name: 'limit', type: 'int', default: 20, help: 'Max models (max 100; one API page).' },
    ],
    columns: ['rank', 'id', 'author', 'pipelineTag', 'downloads', 'likes', 'tags', 'lastModified', 'url'],
    func: async (args) => {
        const sortRaw = String(args.sort ?? 'downloads').toLowerCase();
        const sort = SORT_ALIAS[sortRaw] ?? sortRaw;
        if (!SORT_OPTIONS.includes(sort)) {
            throw new ArgumentError(`hf models sort must be one of ${SORT_OPTIONS.join(', ')}`);
        }
        const limit = Number(args.limit ?? 20);
        if (!Number.isInteger(limit) || limit <= 0) {
            throw new ArgumentError('hf models limit must be a positive integer');
        }
        if (limit > 100) {
            throw new ArgumentError('hf models limit must be <= 100');
        }

        const url = new URL('https://huggingface.co/api/models');
        url.searchParams.set('sort', sort);
        url.searchParams.set('direction', '-1');
        url.searchParams.set('limit', String(limit));
        url.searchParams.set('full', 'true');
        if (args.search) url.searchParams.set('search', String(args.search));
        if (args.pipeline) url.searchParams.set('pipeline_tag', String(args.pipeline));

        let resp;
        try {
            resp = await fetch(url, {
                headers: {
                    'Accept': 'application/json',
                    'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',
                },
            });

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Lower --limit to 100 or less (the maximum supported per call).
  2. Use --search or --pipeline filters to narrow results so fewer than 100 rows are needed.
  3. Run multiple invocations with different --search or --pipeline values to cover more models across calls.
  4. Paginated fetching beyond one page is not implemented; it would require changes to clis/hf/models.js.

Example fix

// before
opencli hf models --limit 500
// after
opencli hf models --limit 100
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(rawLimit ?? 20);
if (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer');
if (n > 100) console.warn('hf models caps at 100 per call; clamping');
const safeLimit = Math.min(n, 100);

Try / catch

try {
  await run(`hf models --limit ${wanted}`);
} catch (e) {
  if (String(e.message).includes('limit must be <= 100')) {
    console.error('Cap is 100 per call; splitting the request');
    await run('hf models --limit 100');
  } else throw e;
}

Prevention

When it happens

Trigger: Running `hf models --limit 101` or higher, e.g. --limit 500 or --limit 1000, when trying to list more models than one API page can return.

Common situations: Expecting the CLI to paginate like the HF hub library does; wanting a full catalog export in one call; copying a limit from a script that used the un-paginated API with large limits.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/1222f9afc526ae7e. Report an issue: GitHub.