{"record":{"id":"03c52b745040918f","repo":"danny-avila/LibreChat","slug":"missing-required-field-finetune-id-for-finetuned","errorCode":null,"errorMessage":"Missing required field: finetune_id for finetuned generation. Please supply a finetune_id!","messagePattern":"Missing required field: finetune_id for finetuned generation\\. Please supply a finetune_id!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"api/app/clients/tools/structured/FluxAPI.js","lineNumber":431,"sourceCode":"        const formattedDetails = JSON.stringify(finetuneDetails, null, 2);\n        return [`Here are the available finetunes:\\n${formattedDetails}`, null];\n      }\n      return JSON.stringify(finetuneDetails);\n    } catch (error) {\n      const details = this.getDetails(error?.response?.data || error.message);\n      logger.error('[FluxAPI] Error while getting finetunes:', details);\n      const errorMsg = `Failed to get finetunes: ${details}`;\n      return this.isAgent ? this.returnValue([errorMsg, {}]) : new Error(errorMsg);\n    }\n  }\n\n  async generateFinetunedImage(imageData, requestApiKey) {\n    if (!imageData.prompt) {\n      throw new Error('Missing required field: prompt');\n    }\n\n    if (!imageData.finetune_id) {\n      throw new Error(\n        'Missing required field: finetune_id for finetuned generation. Please supply a finetune_id!',\n      );\n    }\n\n    // Validate endpoint is appropriate for finetuned generation\n    const validFinetunedEndpoints = ['/v1/flux-pro-finetuned', '/v1/flux-pro-1.1-ultra-finetuned'];\n    const endpoint = imageData.endpoint || '/v1/flux-pro-finetuned';\n\n    if (!validFinetunedEndpoints.includes(endpoint)) {\n      throw new Error(\n        `Invalid endpoint for finetuned generation. Must be one of: ${validFinetunedEndpoints.join(', ')}`,\n      );\n    }\n\n    let payload = {\n      prompt: imageData.prompt,\n      prompt_upsampling: imageData.prompt_upsampling || false,\n      safety_tolerance: imageData.safety_tolerance || 6,","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/app/clients/tools/structured/FluxAPI.js#L413-L449","documentation":"Second guard in generateFinetunedImage(): after prompt is present, a finetune_id is mandatory because the upstream /v1/flux-pro-finetuned endpoint rejects requests without it. The message is explicit about the missing field.","triggerScenarios":"Calling the Flux tool with `action: 'generate_finetuned'` and a valid `prompt`, but no `finetune_id` in imageData.","commonSituations":"The finetune ID was supposed to be selected from a list (list_finetunes) but the caller skipped that step; the ID lived in a variable that was undefined; copy/paste dropped the field; the model hallucinated a finetune call without the ID.","solutions":["Provide `finetune_id` (string) in the generate_finetuned payload.","If unknown, first call `action: 'list_finetunes'` to enumerate available finetune IDs.","Validate client-side that finetune_id is set before enabling the finetuned submit action.","Make the tool schema require finetune_id for the finetuned action so the model is forced to supply it."],"exampleFix":"// before\nawait fluxTool.invoke({\n  action: 'generate_finetuned',\n  prompt: 'a koi',\n});\n\n// after\nawait fluxTool.invoke({\n  action: 'generate_finetuned',\n  prompt: 'a koi',\n  finetune_id: 'flux-ft-20240101-abc',\n});","handlingStrategy":"validation","validationCode":"function buildFluxFinetunedArgs(input) {\n  if (typeof input.finetune_id !== 'string' || !input.finetune_id.trim()) {\n    throw new Error('generate_finetuned requires a finetune_id.');\n  }\n  return { action: 'generate_finetuned', ...input };\n}","typeGuard":"function hasFinetuneId(arg) {\n  return typeof arg?.finetune_id === 'string' && arg.finetune_id.trim().length > 0;\n}","tryCatchPattern":"try {\n  await fluxTool.invoke(args);\n} catch (e) {\n  if (/Missing required field: finetune_id/.test(e.message)) return 'Select a finetune first.';\n  throw e;\n}","preventionTips":["Require finetune_id in the schema for the generate_finetuned action.","Offer a list_finetunes picker so the user always supplies a real ID.","Validate finetune_id format (BFL/fal IDs have a known prefix) before calling."],"tags":["fluxapi","input-validation","finetune","required-field"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}