jackwener/OpenCLI · error · ArgumentError

hf spaces sdk must be one of gradio / streamlit / docker / s

Error message

hf spaces sdk must be one of gradio / streamlit / docker / static

What it means

`hf spaces` validates the optional `sdk` filter against the fixed set of Space SDKs Hugging Face supports: '' (no filter), gradio, streamlit, docker, and static. Unknown SDK names throw this ArgumentError before the API call.

Source

Thrown at clis/hf/spaces.js:44

    ],
    columns: ['rank', 'id', 'author', 'sdk', 'likes', 'tags', 'lastModified', 'url'],
    func: async (args) => {
        const sortRaw = String(args.sort ?? 'likes').toLowerCase();
        const sort = SORT_ALIAS[sortRaw] ?? sortRaw;
        if (!SORT_OPTIONS.includes(sort)) {
            throw new ArgumentError(`hf spaces sort must be one of ${SORT_OPTIONS.join(', ')}`);
        }
        const limit = Number(args.limit ?? 20);
        if (!Number.isInteger(limit) || limit <= 0) {
            throw new ArgumentError('hf spaces limit must be a positive integer');
        }
        if (limit > 100) {
            throw new ArgumentError('hf spaces limit must be <= 100');
        }
        const sdk = args.sdk == null ? '' : String(args.sdk).trim().toLowerCase();
        const allowedSdks = new Set(['', 'gradio', 'streamlit', 'docker', 'static']);
        if (!allowedSdks.has(sdk)) {
            throw new ArgumentError(`hf spaces sdk must be one of gradio / streamlit / docker / static`);
        }

        const url = new URL('https://huggingface.co/api/spaces');
        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 (sdk) url.searchParams.set('sdk', sdk);

        let resp;
        try {
            resp = await fetch(url, {
                headers: { Accept: 'application/json', 'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)' },
            });
        }
        catch (err) {
            throw new CommandExecutionError(`hf spaces request failed: ${err?.message ?? err}`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use one of: gradio, streamlit, docker, static (e.g. `hf spaces --sdk gradio`).
  2. Omit `--sdk` entirely to list all Spaces regardless of SDK.
  3. Check https://huggingface.co/spaces to see which SDKs Spaces actually use.
  4. Catch ArgumentError and validate/normalize the sdk value in your wrapper before invoking.

Example fix

// before
hf spaces --sdk transformers
// after
hf spaces --sdk gradio   // SDKs are gradio / streamlit / docker / static
Defensive patterns

Strategy: validation

Validate before calling

const allowedSdks = new Set(['', 'gradio', 'streamlit', 'docker', 'static']);
const sdk = rawSdk == null ? '' : String(rawSdk).trim().toLowerCase();
if (!allowedSdks.has(sdk)) throw new Error(`sdk must be one of gradio / streamlit / docker / static`);

Type guard

function isValidSdk(v) {
  return ['gradio', 'streamlit', 'docker', 'static'].includes(String(v ?? '').trim().toLowerCase());
}

Try / catch

try {
  await run(['hf', 'spaces', '--sdk', rawSdk]);
} catch (err) {
  if (err instanceof ArgumentError && /sdk must be one of/.test(err.message)) {
    console.warn(`Unknown SDK "${rawSdk}"; listing all Spaces`);
    await run(['hf', 'spaces']);
  } else throw err;
}

Prevention

When it happens

Trigger: Running `hf spaces --sdk pytorch`, `--sdk transformers`, or any value not in {gradio, streamlit, docker, static} (case-insensitive; value is trimmed and lowercased first, so 'Gradio ' works).

Common situations: Confusing model/pipeline libraries (transformers, pytorch, tensorflow) with Space SDKs; copying SDK values from `hf models`; guessing that 'space' or 'js' are valid SDKs.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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