danny-avila/LibreChat · error · Error

No source found for image file

Error message

No source found for image file

What it means

Thrown inside the image-edit tool while iterating orderedFiles: each imageFile must resolve to a `source` (which storage strategy owns it), either from `imageFile.source` or the fallback `appFileStrategy` (passed as fields.fileStrategy at tool creation). If both are empty, the tool cannot pick a download strategy and throws.

Source

Thrown at api/app/clients/tools/structured/OpenAIImageTools.js:304

          {},
        );

        for (const file of fetchedFiles) {
          requestFilesMap[file.file_id] = file;
          orderedFiles[indexOfMissing[file.file_id]] = file;
        }
      }
      for (const imageFile of orderedFiles) {
        if (!imageFile) {
          continue;
        }
        /** @type {NodeStream<File>} */
        let stream;
        /** @type {NodeStreamDownloader<File>} */
        let getDownloadStream;
        const source = imageFile.source || appFileStrategy;
        if (!source) {
          throw new Error('No source found for image file');
        }
        if (streamMethods[source]) {
          getDownloadStream = streamMethods[source];
        } else {
          ({ getDownloadStream } = getStrategyFunctions(source));
          streamMethods[source] = getDownloadStream;
        }
        if (!getDownloadStream) {
          throw new Error(`No download stream method found for source: ${source}`);
        }
        stream = await getDownloadStream(req, imageFile.filepath);
        if (!stream) {
          throw new Error('Failed to get download stream for image file');
        }
        formData.append('image[]', stream, {
          filename: imageFile.filename,
          contentType: imageFile.type,
        });

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Ensure createOpenAIImageTools receives `fileStrategy` (the app-wide FileSources value) in its fields.
  2. Backfill the `source` field on File documents that are missing it (it should be one of FileSources enum values like local, s3, firebase).
  3. Investigate why the file document was persisted without a source — check the upload path.
  4. Reject edit requests for files lacking a source earlier, with a clearer user-facing message.

Example fix

// before
const tools = createOpenAIImageTools({ req, isAgent: true }); // fileStrategy missing
// file.source also undefined -> 'No source found for image file'

// after
const { appConfig } = require('~/server/config');
const tools = createOpenAIImageTools({
  req,
  isAgent: true,
  fileStrategy: appConfig.fileStrategy, // e.g. FileSources.s3
});
Defensive patterns

Strategy: validation

Validate before calling

function assertEditToolFields(fields = {}) {
  if (!fields.fileStrategy) {
    throw new Error('createOpenAIImageTools requires fields.fileStrategy as a fallback source.');
  }
}
function assertFilesHaveSource(files, fallback) {
  for (const f of files) {
    if (!f.source && !fallback) {
      throw new Error('File ' + f.file_id + ' has no source and no app fileStrategy set.');
    }
  }
}

Type guard

function fileHasSource(file, fallback) {
  return Boolean(file?.source || fallback);
}

Try / catch

try {
  await imageEditTool.invoke(args);
} catch (e) {
  if (/No source found for image file/.test(e.message)) return 'That file cannot be edited (unknown storage).';
  throw e;
}

Prevention

When it happens

Trigger: Editing an image whose Mongo File document has no `source` field AND the tool was created without `fields.fileStrategy` set (so appFileStrategy is undefined). This happens when file_strategy/app fileStrategy resolution failed upstream.

Common situations: The FileSources enum value was not persisted on the file document (legacy data, partial migration); the agent controller did not resolve and pass fileStrategy into createOpenAIImageTools; a file from an unsupported/unknown source; refactoring that stopped forwarding fileStrategy from app config.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/eae983e8ca5a2dee. Report an issue: GitHub.