{"record":{"id":"eba834069b835bc4","repo":"FlowiseAI/Flowise","slug":"please-set-an-api-key-for-huggingface-hub-in-the-e","errorCode":null,"errorMessage":"Please set an API key for HuggingFace Hub in the environment variable HUGGINGFACEHUB_API_KEY or in the apiKey field of the HuggingFaceInference constructor.","messagePattern":"Please set an API key for HuggingFace Hub in the environment variable HUGGINGFACEHUB_API_KEY or in the apiKey field of the HuggingFaceInference constructor\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/llms/HuggingFaceInference/core.ts","lineNumber":67,"sourceCode":"    frequencyPenalty: number | undefined = undefined\n\n    apiKey: string | undefined = undefined\n\n    endpoint: string | 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.topP = fields?.topP ?? this.topP\n        this.topK = fields?.topK ?? this.topK\n        this.frequencyPenalty = fields?.frequencyPenalty ?? this.frequencyPenalty\n        this.endpoint = fields?.endpoint ?? ''\n        this.apiKey = fields?.apiKey ?? getEnvironmentVariable('HUGGINGFACEHUB_API_KEY')\n        if (!this.apiKey) {\n            throw new Error(\n                'Please set an API key for HuggingFace Hub in the environment variable HUGGINGFACEHUB_API_KEY or in the apiKey field of the HuggingFaceInference constructor.'\n            )\n        }\n    }\n\n    _llmType() {\n        return 'hf'\n    }\n\n    /** @ignore */\n    async _call(prompt: string, options: this['ParsedCallOptions']): Promise<string> {\n        const { HfInference } = await HuggingFaceInference.imports()\n        const hf = new HfInference(this.apiKey)\n        // v4 uses Inference Providers by default; only override if custom endpoint provided\n        const hfClient = this.endpoint ? hf.endpoint(this.endpoint) : hf\n        const obj: any = {\n            parameters: {\n                // make it behave similar to openai, returning only the generated text","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/llms/HuggingFaceInference/core.ts#L49-L85","documentation":"HuggingFaceInference constructor resolves apiKey as fields.apiKey then falls back to the HUGGINGFACEHUB_API_KEY environment variable; if both are falsy it throws. The check happens at construction, before any network call.","triggerScenarios":"Instantiating the HuggingFaceInference LLM node without a credential and without HUGGINGFACEHUB_API_KEY exported in the process environment.","commonSituations":"Forgot to attach the HF credential to the node in Flowise; env var typo (e.g. HUGGINGFACE_API_KEY); deployed container without the secret mounted; .env not loaded at boot.","solutions":["Set HUGGINGFACEHUB_API_KEY in the runtime environment (export / .env / container secret).","Attach a HuggingFace credential component in the node and pass its apiKey into fields.","Restart the process after setting the variable so it is read at construction."],"exampleFix":"// before\nconst llm = new HuggingFaceInference({ model: 'mistralai/Mistral-7B' })\n// after\nconst llm = new HuggingFaceInference({ model: 'mistralai/Mistral-7B', apiKey: process.env.HUGGINGFACEHUB_API_KEY })","handlingStrategy":"validation","validationCode":"function resolveHfKey(fields?: { apiKey?: string }): string {\n  const key = fields?.apiKey ?? process.env.HUGGINGFACEHUB_API_KEY\n  if (!key) throw new Error('HUGGINGFACEHUB_API_KEY is not set')\n  return key\n}\nconst hf = new HuggingFaceInference({ apiKey: resolveHfKey(fields), ...fields })","typeGuard":"function hasHfKey(fields?: { apiKey?: string }): boolean {\n  return Boolean(fields?.apiKey ?? process.env.HUGGINGFACEHUB_API_KEY)\n}","tryCatchPattern":"try {\n  const llm = new HuggingFaceInference(fields)\n} catch (e) {\n  if (/HUGGINGFACEHUB_API_KEY/.test((e as Error).message)) {\n    // surface a credential-setup error to the user, do not retry\n  }\n  throw e\n}","preventionTips":["Set HUGGINGFACEHUB_API_KEY in the deployment environment, not just locally.","Attach a credential component in Flowise rather than relying on env.","Add a startup health check that fails fast if the key is absent.","Use the exact variable name HUGGINGFACEHUB_API_KEY."],"tags":["huggingface","llm","api-key","auth","configuration"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}