{"record":{"id":"652a50bccdd19df3","repo":"danny-avila/LibreChat","slug":"invalid-endpoint-for-finetuned-generation-must-be","errorCode":null,"errorMessage":"Invalid endpoint for finetuned generation. Must be one of: ${validFinetunedEndpoints.join(', ')}","messagePattern":"Invalid endpoint for finetuned generation\\. Must be one of: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"api/app/clients/tools/structured/FluxAPI.js","lineNumber":441,"sourceCode":"  }\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,\n      output_format: imageData.output_format || 'png',\n      finetune_id: imageData.finetune_id,\n      finetune_strength: imageData.finetune_strength || 1.0,\n      guidance: imageData.guidance || 2.5,\n    };\n\n    // Add optional parameters if provided\n    if (imageData.width) {\n      payload.width = imageData.width;\n    }","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/app/clients/tools/structured/FluxAPI.js#L423-L459","documentation":"Third guard in generateFinetunedImage(): only two endpoints may be used for finetuned generation — '/v1/flux-pro-finetuned' and '/v1/flux-pro-1.1-ultra-finetuned'. If the caller-supplied `endpoint` is anything else, it is rejected before the HTTP call. The default (when endpoint is omitted) is '/v1/flux-pro-finetuned', which is valid, so this only fires when an explicit endpoint is supplied.","triggerScenarios":"Calling generate_finetuned with `imageData.endpoint` set to a value not in the allowlist — e.g. '/v1/flux-pro', '/v1/flux-dev', '/v1/flux-pro-1.1', or a typo like '/v1/flux-pro-finetuned/' (trailing slash).","commonSituations":"Caller reused a payload from a normal generate run (which uses '/v1/flux-pro'); attempted to point finetuned generation at a newer endpoint before adding it to the allowlist; trailing-slash or case mismatch; stale docs listing an old endpoint name.","solutions":["Omit `endpoint` to use the default '/v1/flux-pro-finetuned'.","Set endpoint to exactly '/v1/flux-pro-finetuned' or '/v1/flux-pro-1.1-ultra-finetuned' (no trailing slash, exact case).","If you genuinely need a new endpoint, add it to the validFinetunedEndpoints array in the source after confirming BFL/fal support it.","Log the received endpoint value before the call to catch trailing-whitespace or encoding issues."],"exampleFix":"// before\nawait fluxTool.invoke({\n  action: 'generate_finetuned',\n  prompt: 'a koi',\n  finetune_id: 'ft-1',\n  endpoint: '/v1/flux-pro', // not allowed for finetuned\n});\n\n// after\nawait fluxTool.invoke({\n  action: 'generate_finetuned',\n  prompt: 'a koi',\n  finetune_id: 'ft-1',\n  // endpoint omitted -> defaults to /v1/flux-pro-finetuned\n});","handlingStrategy":"validation","validationCode":"const FINETUNED_ENDPOINTS = ['/v1/flux-pro-finetuned', '/v1/flux-pro-1.1-ultra-finetuned'];\nfunction buildFluxFinetunedArgs(input) {\n  const endpoint = input.endpoint || '/v1/flux-pro-finetuned';\n  if (!FINETUNED_ENDPOINTS.includes(endpoint)) {\n    throw new Error(`endpoint must be one of: ${FINETUNED_ENDPOINTS.join(', ')}`);\n  }\n  return { action: 'generate_finetuned', ...input, endpoint };\n}","typeGuard":"function isValidFinetunedEndpoint(arg) {\n  const ep = arg?.endpoint || '/v1/flux-pro-finetuned';\n  return ['/v1/flux-pro-finetuned', '/v1/flux-pro-1.1-ultra-finetuned'].includes(ep);\n}","tryCatchPattern":"try {\n  await fluxTool.invoke(args);\n} catch (e) {\n  if (/Invalid endpoint for finetuned/.test(e.message)) return 'That endpoint does not support finetuned generation.';\n  throw e;\n}","preventionTips":["Omit `endpoint` for finetuned runs unless you specifically need the ultra variant.","Keep a single shared allowlist constant both in client validation and the tool source.","Normalize endpoint strings (trim, lowercase path) before comparison."],"tags":["fluxapi","input-validation","endpoint","allowlist","finetune"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}