Skip to main content
With a Custom Endpoint scanner, Dify sends your scanning service the files uploaded to a knowledge base that scans with it. Your service returns a verdict for each file: a clean file is indexed as usual, and an infected one is blocked. For turning on scanning in a knowledge base, see Scan Uploaded Files for Malware.
This scanner type is separate from the Custom Endpoint section of Integrations, which holds API-based extensions with a different request format.

Receive the File

Dify sends each file in its own request:
Make up a secret string as the API key, enter it in Dify when you add the scanner, and have your service check it on every request. When the key doesn’t match, return 401. The form carries the file and five text fields:
file
The file to scan.
string
An ID for this scan. Dify’s automatic retries of a scan send the same ID, so you can answer a repeated request from the first scan instead of scanning again. Retrying the file in the knowledge base later starts a new scan with a new ID.
string
The file’s name, such as report.docx.
string
The file’s size in bytes, as a decimal string, such as 482113.
string
The file’s MIME type, or empty when Dify doesn’t know it.
string
The SHA3-256 hash of the file content, in hex. It can be empty. If your service needs a hash every time, compute one from the content.

Return a Verdict

Answer with any 2xx status and a JSON object:
string
required
clean, infected, or unscannable.
string[]
Names of the threats found, shown to users in the message that says why the file was blocked. Without them, the message says unknown was detected.Dify keeps up to 20 names, each cut to 200 characters.
string
Your engine’s name or version. Dify doesn’t show it in the product.
string
Why your service couldn’t scan the file, sent with unscannable. Dify keeps up to 500 characters and doesn’t show it in the product.
When your service can’t judge a file, the knowledge base’s When a file cannot be scanned (encrypted or too large) choice decides whether it’s blocked (the default) or let in unscanned. What you return sets the error message users see on a blocked file:
  • Too large: return 413. The error message says the file exceeds the scanner’s size limit.
  • Encrypted, an unsupported format, or any other reason: return unscannable. The error message says the scanner doesn’t support the file, whatever your reason was.

Choose the Right Status Code

Dify decides what to do with the file from your status code and body.
For a brief overload that a retry would get past, return 503, not 429.

Answer Within the Timeout

Dify waits a limited time for each answer. Keep scans fast: in an agent knowledge base, the person uploading waits in the upload dialog until your endpoint answers. When your service knows it can’t finish a file in time, answer at once with 413 or unscannable instead of letting the request time out.

Start from an Example

Replace my_scanner in this Flask endpoint with your own scanning logic:
scanner.py
Save the code as scanner.py, then install Flask and start the endpoint with the API key you’ll enter in Dify:

Test the Endpoint Locally

Send your endpoint a request shaped like Dify’s, from the machine it runs on:
Once your scanning logic is in place, send this request twice: once with a clean file and once with the EICAR test file, updating file_name, file_size, and mime_type to match each. Your endpoint should answer clean for the first and infected for the second.
The EICAR test file is a harmless file that every antivirus engine reports as malware, available from eicar.org.
Also send a sample of your real files, to catch false alarms before a knowledge base uses your scanner. Dify remembers verdicts. When the same content is checked again in the workspace by the same scanner, Dify reuses the earlier verdict instead of calling your endpoint:
  • infected: reused for good, so a clean file your service wrongly flags stays blocked even after you fix the scanner.
  • clean: reused for a limited time. During that time, the same file passes even if you’ve updated the scanner to catch it.

Make the Endpoint Reachable

Before you add the endpoint in Dify, make sure it:
  • Runs at a public address. A private or internal address is blocked, and so is a hostname that resolves to one.
  • Serves https with a valid TLS certificate. Dify accepts http too, but then each file and your API key cross the internet unencrypted.

Add the Scanner in Dify

In Integrations > File Security Scan, click Add scanner > Custom Endpoint, and enter your endpoint’s full URL as the Endpoint URL, path included, such as https://scanner.example.com/scan. Redirects aren’t followed, so if http redirects to https, enter the https URL. When you save the scanner, and whenever you click Test, Dify checks the connection by sending one file:
  • file: clean-test.txt, as text/plain
  • scan_id: connectivity-check
  • file_hash: empty
Any valid verdict passes, and so does 413. Dify saves the scanner only when the check passes. Once a knowledge base uses the scanner, upload the EICAR test file there to check the whole path.
Last modified on November 26, 2026