How it works
To better understand how template exclusion works, consider the following scenario where a teacher wants to scan student exams but exclude the questions.| The Template (indexed beforehand) | Student Submission (the file you scan) | What Copyleaks Scans (the actual analysis) |
|---|---|---|
| Question 1: Explain the process of photosynthesis. | Question 1: Explain the process of photosynthesis. Answer: Photosynthesis is the process used by plants… | Answer: Photosynthesis is the process used by plants… |
Template sourcing
Templates for exclusion can be referenced in two ways:- From a normal submitted scan: Reference any existing
scanIdfrom your submissions (saved short-term which is determined by theexpirationproperty). - From your Private Cloud Hub: Index the template document into your Private Cloud Hub (for recurring or long-term use).
Get started
1
Before you begin
Before you start, ensure you have the following:
- An active Copyleaks account. If you don’t have one, sign up for free.
- You can find your API key on the API Dashboard.
2
Installation
Choose your preferred method for making API calls.
# macOS
brew install curl
# Ubuntu/Debian
sudo apt-get install curl
# Windows - download from https://curl.se
pip install copyleaks
npm install copyleaks
dotnet add package Copyleaks
# Or, in the Visual Studio Package Manager Console:
# Install-Package Copyleaks
composer require copyleaks/copyleaks
gem install copyleaks
<!-- Add to your pom.xml (requires Java 11+) -->
<dependency>
<groupId>com.copyleaks</groupId>
<artifactId>copyleaks</artifactId>
<version>6.0.0</version>
</dependency>
go get github.com/Copyleaks/[email protected]
cargo add copyleaks@2
cargo add tokio --features macros,rt-multi-thread
3
Login
To perform a scan, we first need to generate an access token. For that, we will use the login endpoint.
The API key can be found on the Copyleaks API Dashboard.Upon successful authentication, you will receive a token that must be attached to subsequent API calls via the
Authorization: Bearer <TOKEN> header.
This token remains valid for 48 hours.POST https://id.copyleaks.com/v3/account/login/api
Headers
Content-Type: application/json
Body
{
"email": "[email protected]",
"key": "00000000-0000-0000-0000-000000000000"
}
export COPYLEAKS_EMAIL="[email protected]"
export COPYLEAKS_API_KEY="your-api-key-here"
curl --request POST \
--url https://id.copyleaks.com/v3/account/login/api \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data "{
\"email\": \"${COPYLEAKS_EMAIL}\",
\"key\": \"${COPYLEAKS_API_KEY}\"
}"
from copyleaks.copyleaks import Copyleaks
EMAIL_ADDRESS = "[email protected]"
API_KEY = "your-api-key-here"
# Login to Copyleaks
auth_token = Copyleaks.login(EMAIL_ADDRESS, API_KEY)
print("Logged successfully!\nToken:", auth_token)
const { Copyleaks } = require("copyleaks");
const EMAIL_ADDRESS = "[email protected]";
const API_KEY = "your-api-key-here";
const copyleaks = new Copyleaks();
// Login function
function loginToCopyleaks() {
return copyleaks.loginAsync(EMAIL_ADDRESS, API_KEY).then(
(loginResult) => {
console.log("Login successful!");
console.log("Access Token:", loginResult.access_token);
return loginResult;
},
(err) => {
console.error('Login failed:', err);
throw err;
}
);
}
loginToCopyleaks();
import classes.Copyleaks;
import models.response.CopyleaksAuthToken;
String EMAIL_ADDRESS = "[email protected]";
String API_KEY = "00000000-0000-0000-0000-000000000000";
// Login to Copyleaks
CopyleaksAuthToken authToken = null;
try {
authToken = Copyleaks.login(EMAIL_ADDRESS, API_KEY);
System.out.println("Logged in successfully!");
} catch (Exception e) {
System.out.println("Failed to login: " + e.getMessage());
System.exit(1);
}
using System;
using Copyleaks.SDK.V3.API;
const string EMAIL_ADDRESS = "[email protected]";
const string API_KEY = "your-api-key-here";
// Login to Copyleaks
var identityClient = new CopyleaksIdentityApi();
var loginResponse = await identityClient.LoginAsync(EMAIL_ADDRESS, API_KEY);
string authToken = loginResponse.Token;
Console.WriteLine("Logged in successfully!");
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use Copyleaks\Copyleaks;
$EMAIL_ADDRESS = "[email protected]";
$API_KEY = "your-api-key-here";
// Login to Copyleaks
$copyleaks = new Copyleaks();
$authToken = $copyleaks->login($EMAIL_ADDRESS, $API_KEY);
echo "Logged in successfully!\n";
require 'copyleaks'
EMAIL_ADDRESS = "[email protected]"
API_KEY = "your-api-key-here"
# Login to Copyleaks
copyleaks = Copyleaks::API.new
auth_token = copyleaks.login(EMAIL_ADDRESS, API_KEY)
puts "Logged in successfully!"
Response
{
"access_token": "<ACCESS_TOKEN>",
".issued": "2025-07-31T10:19:40.0690015Z",
".expires": "2025-08-02T10:19:40.0690016Z"
}
4
Create a template (index a document)
First, you need to submit the document that contains the text you want to exclude (the template). You will “index” this document into your Private Cloud Hub or the Shared Data Hub.In this example, we will submit a file with the ID
my-template-index to a Private Cloud Hub with the repository ID 6e870e0bb2264.PUT https://api.copyleaks.com/v3/scans/submit/file/my-template-index
Content-Type: application/json
Authorization: Bearer <YOUR_AUTH_TOKEN>
{
"base64": "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",
"filename": "exam_template.txt",
"properties": {
"action": 2,
"indexing": {
"repositories": [
{
"id": "6e870e0bb2264",
"includeMySubmissions": true,
"includeOthersSubmissions": true
}
],
"copyleaksDb": false
},
"webhooks": {
"status": "https://your-server.com/webhook/{STATUS}"
}
}
}
curl -X PUT "https://api.copyleaks.com/v3/scans/submit/file/my-template-index" \
-H "Authorization: Bearer <YOUR_AUTH_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"base64": "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",
"filename": "exam_template.txt",
"properties": {
"action": 2,
"indexing": {
"repositories": [
{
"id": "6e870e0bb2264",
"includeMySubmissions": true,
"includeOthersSubmissions": true
}
],
"copyleaksDb": false
},
"webhooks": {
"status": "https://your-server.com/webhook/{STATUS}"
},
"sandbox": true
}
}'
import requests
import base64
# Template content
template_content = "This is the exam template text."
base64_content = base64.b64encode(template_content.encode()).decode('utf-8')
url = "https://api.copyleaks.com/v3/scans/submit/file/my-template-index"
payload = {
"base64": base64_content,
"filename": "exam_template.txt",
"properties": {
"action": 2,
"indexing": {
"repositories": [
{
"id": "6e870e0bb2264",
"includeMySubmissions": True,
"includeOthersSubmissions": True
}
],
"copyleaksDb": False
},
"webhooks": {
"status": "https://your-server.com/webhook/{STATUS}"
},
"sandbox": True
}
}
headers = {
"Authorization": "Bearer <YOUR_AUTH_TOKEN>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.json())
const axios = require('axios');
const url = 'https://api.copyleaks.com/v3/scans/submit/file/my-template-index';
const headers = {
'Authorization': 'Bearer <YOUR_AUTH_TOKEN>',
'Content-Type': 'application/json'
};
const data = {
base64: "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",
filename: "exam_template.txt",
properties: {
action: 2,
indexing: {
repositories: [
{
id: "6e870e0bb2264",
includeMySubmissions: true,
includeOthersSubmissions: true
}
],
copyleaksDb: false
},
webhooks: {
status: "https://your-server.com/webhook/{STATUS}"
},
sandbox: true
}
};
axios.put(url, data, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error));
import classes.Copyleaks;
import models.submissions.CopyleaksFileSubmissionModel;
import models.submissions.properties.*;
import java.util.Base64;
import java.nio.charset.StandardCharsets;
String scanId = "my-template-index";
String base64Content = Base64.getEncoder().encodeToString("This is the exam template text.".getBytes(StandardCharsets.UTF_8));
// Create submission properties
SubmissionProperties properties = new SubmissionProperties(new SubmissionWebhooks("https://your-server.com/webhook/{STATUS}"));
properties.setSandbox(true);
// Action 2 is 'Index Only'
properties.setAction(SubmissionActions.IndexOnly);
// Configure indexing to Private Cloud Hub
SubmissionIndexingRepository repo = new SubmissionIndexingRepository();
repo.setId("6e870e0bb2264");
SubmissionIndexing indexing = new SubmissionIndexing();
indexing.setRepositories(new SubmissionIndexingRepository[]{ repo });
properties.setIndexing(indexing);
// Create and submit the file
CopyleaksFileSubmissionModel submission = new CopyleaksFileSubmissionModel(base64Content, "exam_template.txt", properties);
Copyleaks.submitFile(authToken, scanId, submission);
System.out.println("Template indexed successfully.");
using System;
using System.Text;
using Copyleaks.SDK.V3.API;
using Copyleaks.SDK.V3.API.Models.Requests;
using Copyleaks.SDK.V3.API.Models.Requests.Properties;
using Copyleaks.SDK.V3.API.Models.Types;
// authToken comes from the login step
var scanId = "my-template-index";
var base64Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("This is the exam template text."));
// Create submission properties
var properties = new ClientScanProperties();
properties.Webhooks = new Webhooks { Status = new Uri("https://your-server.com/webhook/{STATUS}") };
properties.Sandbox = true;
// Action 2 is 'Index Only'
properties.Action = eSubmitAction.Index;
// Configure indexing to Private Cloud Hub
properties.Indexing = new ClientIndexingEntity
{
Repositories = new[] { new RepositoryIndexing { Id = "6e870e0bb2264" } }
};
// Create and submit the file
var submission = new FileDocument
{
Base64 = base64Content,
Filename = "exam_template.txt",
PropertiesSection = properties
};
var scansClient = new CopyleaksScansApi();
await scansClient.SubmitFileAsync(scanId, submission, authToken);
Console.WriteLine("Template indexed successfully.");
<?php
use Copyleaks\CopyleaksFileSubmissionModel;
use Copyleaks\SubmissionActions;
use Copyleaks\SubmissionIndexing;
use Copyleaks\SubmissionProperties;
use Copyleaks\SubmissionRepository;
use Copyleaks\SubmissionWebhooks;
// $copyleaks and $authToken come from the login step
$scanId = "my-template-index";
$base64Content = base64_encode("This is the exam template text.");
// Create submission properties
$properties = new SubmissionProperties(new SubmissionWebhooks("https://your-server.com/webhook/{STATUS}"));
$properties->sandbox = true;
// Action 2 is 'Index Only'
$properties->action = SubmissionActions::IndexOnly;
// Configure indexing to Private Cloud Hub
$properties->indexing = new SubmissionIndexing([new SubmissionRepository("6e870e0bb2264")]);
// Create and submit the file
$submission = new CopyleaksFileSubmissionModel($base64Content, "exam_template.txt", $properties);
$copyleaks->submitFile($authToken, $scanId, $submission);
echo "Template indexed successfully.\n";
require 'copyleaks'
require 'base64'
# copyleaks and auth_token come from the login step
scan_id = "my-template-index"
base64_content = Base64.strict_encode64("This is the exam template text.")
webhooks = Copyleaks::SubmissionWebhooks.new("https://your-server.com/webhook/{STATUS}")
# Configure indexing to Private Cloud Hub
indexing = Copyleaks::SubmissionIndexing.new([Copyleaks::SubmissionIndexingRepository.new("6e870e0bb2264")])
# The Ruby SDK takes properties positionally; arguments left nil are not sent
properties = Copyleaks::SubmissionProperties.new(
webhooks,
nil, # includeHtml
"my-developer-payload", # developerPayload
true, # sandbox
2880, # expiration, in hours
3, # sensitivityLevel, 1-5
nil, # cheatDetection
Copyleaks::SubmissionActions::INDEXONLY, # action: 2 is 'Index Only'
nil, # author
nil, # filters
nil, # scanning
indexing # indexing
)
# Create and submit the file
submission = Copyleaks::CopyleaksFileSubmissionModel.new(base64_content, "exam_template.txt", properties)
copyleaks.submit_file(auth_token, scan_id, submission)
puts "Template indexed successfully."
5
Scan with template exclusion
Now that you have a template indexed, you can submit a new document for scanning and tell Copyleaks to exclude the content of the template.Use the
properties.exclude.documentTemplateIds field to specify the template ID.PUT https://api.copyleaks.com/v3/scans/submit/file/student-exam-submission
Content-Type: application/json
Authorization: Bearer <YOUR_AUTH_TOKEN>
{
"base64": "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",
"filename": "student_submission.txt",
"properties": {
"action": 0,
"webhooks": {
"status": "https://your-server.com/webhook/{STATUS}"
},
"exclude": {
"documentTemplateIds": ["my-template-index"]
},
"indexing": {
"repositories": [
{
"id": "your-repo-id",
"includeMySubmissions": true,
"includeOthersSubmissions": true
}
],
"copyleaksDb": false
},
"aiGeneratedText": {
"detect": true
},
"sandbox": true
}
}
curl -X PUT "https://api.copyleaks.com/v3/scans/submit/file/student-exam-submission" \
-H "Authorization: Bearer <YOUR_AUTH_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"base64": "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",
"filename": "student_submission.txt",
"properties": {
"action": 0,
"webhooks": {
"status": "https://your-server.com/webhook/{STATUS}"
},
"exclude": {
"documentTemplateIds": ["my-template-index"]
},
"indexing": {
"repositories": [
{
"id": "your-repo-id",
"includeMySubmissions": true,
"includeOthersSubmissions": true
}
],
"copyleaksDb": false
},
"aiGeneratedText": {
"detect": true
},
"sandbox": true
}
}'
import requests
import base64
# Student submission content
student_content = "This is the student's answer mixed with template text."
base64_content = base64.b64encode(student_content.encode()).decode('utf-8')
url = "https://api.copyleaks.com/v3/scans/submit/file/student-exam-submission"
payload = {
"base64": base64_content,
"filename": "student_submission.txt",
"properties": {
"action": 0,
"webhooks": {
"status": "https://your-server.com/webhook/{STATUS}"
},
"exclude": {
"documentTemplateIds": ["my-template-index"]
},
"indexing": {
"repositories": [
{
"id": "your-repo-id",
"includeMySubmissions": True,
"includeOthersSubmissions": True
}
],
"copyleaksDb": False
},
"aiGeneratedText": {
"detect": True
},
"sandbox": True
}
}
headers = {
"Authorization": "Bearer <YOUR_AUTH_TOKEN>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.json())
const axios = require('axios');
const url = 'https://api.copyleaks.com/v3/scans/submit/file/student-exam-submission';
const headers = {
'Authorization': 'Bearer <YOUR_AUTH_TOKEN>',
'Content-Type': 'application/json'
};
const data = {
base64: "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",
filename: "student_template.txt",
properties: {
action: 0,
webhooks: {
status: "https://your-server.com/webhook/{STATUS}"
},
exclude: {
documentTemplateIds: ["my-template-index"]
},
indexing: {
repositories: [
{
id: "your-repo-id",
includeMySubmissions: true,
includeOthersSubmissions: true
}
],
copyleaksDb: false
},
aiGeneratedText: {
detect: true
},
sandbox: true
}
};
axios.put(url, data, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error));
import classes.Copyleaks;
import models.submissions.CopyleaksFileSubmissionModel;
import models.submissions.properties.*;
import java.util.Base64;
import java.nio.charset.StandardCharsets;
String scanId = "student-exam-submission";
String base64Content = Base64.getEncoder().encodeToString("This is the student's answer mixed with template text.".getBytes(StandardCharsets.UTF_8));
// Create submission properties
SubmissionProperties properties = new SubmissionProperties(new SubmissionWebhooks("https://your-server.com/webhook/{STATUS}"));
properties.setSandbox(true);
// Set document templates to exclude
SubmissionExclude exclude = new SubmissionExclude();
exclude.setDocumentTemplateIds(new String[]{"my-template-index"});
properties.setExclude(exclude);
// Create and submit the file
CopyleaksFileSubmissionModel submission = new CopyleaksFileSubmissionModel(base64Content, "student_submission.txt", properties);
Copyleaks.submitFile(authToken, scanId, submission);
System.out.println("Scan submitted with template exclusion.");
using System;
using System.Text;
using Copyleaks.SDK.V3.API;
using Copyleaks.SDK.V3.API.Models.Requests;
using Copyleaks.SDK.V3.API.Models.Requests.Properties;
// authToken comes from the login step
var scanId = "student-exam-submission";
var base64Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("This is the student's answer mixed with template text."));
// Create submission properties
var properties = new ClientScanProperties();
properties.Webhooks = new Webhooks { Status = new Uri("https://your-server.com/webhook/{STATUS}") };
properties.Sandbox = true;
// Set document templates to exclude
properties.Exclude.DocumentTemplateIds = new[] { "my-template-index" };
// Create and submit the file
var submission = new FileDocument
{
Base64 = base64Content,
Filename = "student_submission.txt",
PropertiesSection = properties
};
var scansClient = new CopyleaksScansApi();
await scansClient.SubmitFileAsync(scanId, submission, authToken);
Console.WriteLine("Scan submitted with template exclusion.");
<?php
use Copyleaks\CopyleaksFileSubmissionModel;
use Copyleaks\SubmissionExclude;
use Copyleaks\SubmissionProperties;
use Copyleaks\SubmissionWebhooks;
// $copyleaks and $authToken come from the login step
$scanId = "student-exam-submission";
$base64Content = base64_encode("This is the student's answer mixed with template text.");
// Create submission properties
$properties = new SubmissionProperties(new SubmissionWebhooks("https://your-server.com/webhook/{STATUS}"));
$properties->sandbox = true;
// Set document templates to exclude
$exclude = new SubmissionExclude();
$exclude->documentTemplateIds = ["my-template-index"];
$properties->exclude = $exclude;
// Create and submit the file
$submission = new CopyleaksFileSubmissionModel($base64Content, "student_submission.txt", $properties);
$copyleaks->submitFile($authToken, $scanId, $submission);
echo "Scan submitted with template exclusion.\n";
require 'copyleaks'
require 'base64'
# copyleaks and auth_token come from the login step
scan_id = "student-exam-submission"
base64_content = Base64.strict_encode64("This is the student's answer mixed with template text.")
webhooks = Copyleaks::SubmissionWebhooks.new("https://your-server.com/webhook/{STATUS}")
# Set document templates to exclude
exclude = Copyleaks::SubmissionExclude.new(
false, # quotes
false, # references
false, # tableOfContents
false, # titles
false, # htmlTemplate
nil, # citations
["my-template-index"] # documentTemplateIds
)
# The Ruby SDK takes properties positionally; arguments left nil are not sent
properties = Copyleaks::SubmissionProperties.new(
webhooks,
nil, # includeHtml
"my-developer-payload", # developerPayload
true, # sandbox
2880, # expiration, in hours
3, # sensitivityLevel, 1-5
nil, # cheatDetection
nil, # action
nil, # author
nil, # filters
nil, # scanning
nil, # indexing
exclude # exclude
)
# Create and submit the file
submission = Copyleaks::CopyleaksFileSubmissionModel.new(base64_content, "student_submission.txt", properties)
copyleaks.submit_file(auth_token, scan_id, submission)
puts "Scan submitted with template exclusion."
6
Summary
You have just:
- Created a template document and indexed it
- Submitted a scan with template exclusion
- Excluded template text from your plagiarism analysis
Next steps
Check for Plagiarism
Detect plagiarism in text documents using the Copyleaks API. Search billions of sources to find unoriginal content.
Detect AI-Generated Content
Detect AI-generated text via sync or async API calls. This guide covers sync detection, see the Authenticity API Guide for async.
Assess Grammar and Writing Quality
Get writing and grammar suggestions via API. Authenticate, submit text, and access full details in the docs.
Moderate Text
Scan and moderate text content for unsafe or policy-relevant material across 10+ categories.

