{"record":{"id":"c0b75c5e47af222c","repo":"FlowiseAI/Flowise","slug":"please-set-an-api-key-for-huggingface-hub-either","errorCode":null,"errorMessage":"Please set an API key for HuggingFace Hub. Either configure it in the credential settings in the UI, or set the environment variable HUGGINGFACEHUB_API_KEY.","messagePattern":"Please set an API key for HuggingFace Hub\\. Either configure it in the credential settings in the UI, or set the environment variable HUGGINGFACEHUB_API_KEY\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/chatmodels/ChatHuggingFace/core.ts","lineNumber":60,"sourceCode":"    endpointUrl: string | undefined = undefined\n\n    includeCredentials: string | boolean | undefined = undefined\n\n    constructor(fields?: Partial<HFInput> & BaseLLMParams) {\n        super(fields ?? {})\n\n        this.model = fields?.model ?? this.model\n        this.temperature = fields?.temperature ?? this.temperature\n        this.maxTokens = fields?.maxTokens ?? this.maxTokens\n        this.stopSequences = fields?.stopSequences ?? this.stopSequences\n        this.topP = fields?.topP ?? this.topP\n        this.topK = fields?.topK ?? this.topK\n        this.frequencyPenalty = fields?.frequencyPenalty ?? this.frequencyPenalty\n        this.apiKey = fields?.apiKey ?? getEnvironmentVariable('HUGGINGFACEHUB_API_KEY')\n        this.endpointUrl = fields?.endpointUrl\n        this.includeCredentials = fields?.includeCredentials\n        if (!this.apiKey || this.apiKey.trim() === '') {\n            throw new Error(\n                'Please set an API key for HuggingFace Hub. Either configure it in the credential settings in the UI, or set the environment variable HUGGINGFACEHUB_API_KEY.'\n            )\n        }\n    }\n\n    _llmType() {\n        return 'hf'\n    }\n\n    invocationParams(options?: this['ParsedCallOptions']) {\n        // Return parameters compatible with chatCompletion API (OpenAI-compatible format)\n        const params: any = {\n            temperature: this.temperature,\n            max_tokens: this.maxTokens,\n            stop: options?.stop ?? this.stopSequences,\n            top_p: this.topP\n        }\n        // Include optional parameters if they are defined","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/chatmodels/ChatHuggingFace/core.ts#L42-L78","documentation":"The ChatHuggingFace core wrapper validates apiKey in its constructor: it falls back from fields.apiKey to the HUGGINGFACEHUB_API_KEY environment variable, and throws if neither is set or if the key is whitespace-only. This is a hard pre-flight before any network call.","triggerScenarios":"Instantiating ChatHuggingFace with neither apiKey in the config nor HUGGINGFACEHUB_API_KEY in the process environment, or passing a key of only spaces. Distinct from [83] (node-layer) — this is the LangChain-style wrapper's own constructor guard.","commonSituations":"Self-hosted Flowise server where HUGGINGFACEHUB_API_KEY was never added to the .env (or container env); a unit test instantiating ChatHuggingFace without mocking the env; deployment that lost its env vars after a restart; CI runner missing the secret.","solutions":["Add HUGGINGFACEHUB_API_KEY=hf_xxx to the Flowise server's .env (or container env) and restart.","Pass apiKey explicitly in the constructor fields when instantiating programmatically.","Confirm the variable name has no typo (it is HUGGINGFACEHUB_API_KEY, all caps).","For Flowise UI users, bind a HuggingFace credential so [83] supplies the key upstream."],"exampleFix":"// before\nconst model = new ChatHuggingFace({ model: 'meta-llama/Llama-3-8B' }) // throws [84]\n\n// after\nconst model = new ChatHuggingFace({\n  model: 'meta-llama/Llama-3-8B',\n  apiKey: process.env.HUGGINGFACEHUB_API_KEY\n})","handlingStrategy":"validation","validationCode":"const apiKey = fields?.apiKey ?? process.env.HUGGINGFACEHUB_API_KEY\nif (!apiKey || apiKey.trim() === '') {\n  throw new Error('Set HUGGINGFACEHUB_API_KEY in the environment or pass apiKey in fields.')\n}\nconst model = new ChatHuggingFace({ ...fields, apiKey })","typeGuard":"function isValidHuggingFaceKey(key: unknown): key is string {\n  return typeof key === 'string' && key.trim().length > 0\n}","tryCatchPattern":"try {\n  return new ChatHuggingFace(fields)\n} catch (e) {\n  if (e.message.includes('set an API key for HuggingFace Hub')) {\n    process.env.HUGGINGFACEHUB_API_KEY = await promptUserForKey()\n    return new ChatHuggingFace(fields)\n  }\n  throw e\n}","preventionTips":["Set HUGGINGFACEHUB_API_KEY in the server/container environment before boot.","Smoke-test model construction in a startup health check.","Keep secrets in a secret manager, not in checked-in .env files.","Confirm the env var name spelling (all caps) in deploy manifests."],"tags":["huggingface","api-key","environment","constructor","configuration"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}