HeyPuter/puter · warning · HttpError

bad_request

bad_request

Error message

`source` is required

What it means

The OCR driver requires a document to process, passed via either args.source or args.file. If both are falsy (undefined, null, empty string), the driver has nothing to send to Textract or Mistral and rejects the request immediately.

Source

Thrown at src/backend/drivers/ai-ocr/OCRDriver.ts:188

    async recognize(args: RecognizeArgs) {
        if (args.test_mode) return sampleResponse();

        const provider = this.#resolveProvider(args);
        if (!provider)
            throw new HttpError(500, 'No OCR provider configured', {
                legacyCode: 'internal_error',
            });

        const actor = Context.get('actor');
        if (!actor)
            throw new HttpError(401, 'Authentication required', {
                legacyCode: 'unauthorized',
            });

        const input = args.source ?? args.file;
        if (!input)
            throw new HttpError(400, '`source` is required', {
                legacyCode: 'bad_request',
            });

        const loaded = await loadFileInput(
            this.stores,
            this.services.fs,
            actor,
            input,
            { acceptWebInput: true },
        );

        if (provider === 'aws-textract') {
            if (!this.#awsConfig)
                throw new HttpError(500, 'AWS credentials not configured', {
                    legacyCode: 'internal_error',
                });
            return this.#textractRecognize(loaded, actor);
        }

View on GitHub (pinned to 908ec23eda)

Solutions

  1. Provide a valid source (URL, file path, FS UID, or base64 data URI) or file object in the recognize() call.
  2. Validate on the client side that a file is selected before submitting.
  3. Check that the SDK method used (puter.ai.ocr or puter.ai.txtrec) receives the file parameter correctly.

Example fix

// before — no source provided
const result = await driver.recognize({ provider: 'aws-textract' });

// after — provide a source
const result = await driver.recognize({
  source: 'https://example.com/document.pdf',
  provider: 'aws-textract',
});
Defensive patterns

Strategy: validation

Validate before calling

function validateOcrSource(args: { source?: unknown; file?: unknown }): unknown {
  const input = args.source ?? args.file;
  if (!input) {
    throw new Error('`source` or `file` is required for OCR');
  }
  return input;
}
// Use before calling recognize:
const input = validateOcrSource(args);

Type guard

function hasOcrInput(args: { source?: unknown; file?: unknown }): boolean {
  return Boolean(args.source ?? args.file);
}

Prevention

When it happens

Trigger: Calling recognize() with neither source nor file in the args object; passing an empty object {}; passing undefined for both fields due to destructuring errors or form submission issues.

Common situations: The client SDK call omits the file/source parameter; a file upload form submitted without selecting a file; the source field is set but to a falsy value (0, false, empty string) that the nullish coalescing (??) and logical-or fallback don't distinguish from missing.

Related errors


AI-assisted analysis of HeyPuter/puter@908ec23eda (2026-08-12). Data as JSON: /api/errors/c4502f06f5cf0e05. Report an issue: GitHub.