Skip to content
AI Detector

Detect Source Code

POST https://api.copyleaks.com/v2/writer-detector/source-code/{scanId}/check

Use Copyleaks AI Content Detection to differentiate between human-written and AI-written source code.

This endpoint will receive submitted source code to be checked. At the end of the processing stage, the result will be shown as classifications. Source code classification is divided into sections. Each section may have a different classification.

scanId string required

A unique scan id provided by you. We recommend you use the same id in your database to represent the scan in the Copyleaks database. This will help you to debug incidents. Using the same ID for the same file will help you to avoid network problems that may lead to multiple scans for the same file. learn more about the criteria for creating a Scan ID.

>= 3 characters <= 36 characters

Match pattern: [a-z0-9] !@$^&-+%=_(){}<>';:/.",~|

Content-Type: application/json
Authorization: Bearer YOUR_LOGIN_TOKEN

The request body is a JSON object containing the source code to scan.

text string required

A text string. Supported Languages:

  • Ruby
  • javascript
  • typescript
  • python
  • C++
  • C
  • Java
  • C#
  • PHP

>= 255 characters <= 25000 characters

filename string required

The name of the file. Make sure to include the right extension for your file type.

Example: Myfile.py

sandbox boolean default: "false"

Use sandbox mode to test your integration with the Copyleaks API for free.

code object
comments boolean default: "false"

When set to true, the scan will ignore comments in the source code.

200 OK

The command was executed.

Response Schema

The response contains the following fields:

modelVersion string
The version of the AI detection model used.
results array<object>
An array of classification results for different sections of the code. See AI Detection Response for more details.
summary object
A summary of the overall classification (human vs. AI).
scannedDocument object
Metadata about the scan. See Scanned Document for more details.
explain object
Data for the AI Logic feature, explaining the classification. See AI Logic for more details.

Example Response

A typical response from this endpoint:

Show full example (115 lines)
{
"modelVersion": "v5",
"results": [
{
"classification": 2,
"probability": 1,
"matches": [
{
"text": {
"chars": {
"starts": [
0
],
"lengths": [
1509
// ... truncated
400 Bad Request

Bad request.

Example Response

A typical response from this endpoint:

{
"ErrorMessage": "Language not supported",
"ErrorCode": "unsupported-lang"
}
POST https://api.copyleaks.com/v2/writer-detector/source-code/my-scan-123/check
Content-Type: application/json
Authorization: Bearer YOUR_LOGIN_TOKEN
{
"text": "import sqlite3 def connect_to_database(): return sqlite3.connect(\"pharmacy.db\") def retrieve_medication_data(medication_id): connection = connect_to_database() cursor = connection.cursor() cursor.execute(\"SELECT * FROM medications WHERE id=?\", (medication_id,)) medication_data = cursor.fetchone() connection.close() return medication_data # Example usage medication_data = retrieve_medication_data(\"ABC123\") print(medication_data)",
"filename": "MyFile.py"
}