Detect Source Code
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.
Request
Section titled “Request”Path Parameters
Section titled “Path Parameters”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] !@$^&-+%=_(){}<>';:/.",~
|
Headers
Section titled “Headers”Content-Type: application/jsonAuthorization: Bearer YOUR_LOGIN_TOKEN
Request Body
Section titled “Request Body”The request body is a JSON object containing the source code to scan.
A text string. Supported Languages:
- Ruby
- javascript
- typescript
- python
- C++
- C
- Java
- C#
- PHP
>= 255 characters
<= 25000 characters
The name of the file. Make sure to include the right extension for your file type.
Example: Myfile.py
Use sandbox mode to test your integration with the Copyleaks API for free.
code object
When set to true, the scan will ignore comments in the source code.
Responses
Section titled “Responses”The command was executed.
Response Schema
The response contains the following fields:
summary object
scannedDocument object
explain object
Example Response
A typical response from this endpoint:
{ "modelVersion": "v5", "results": [ { "classification": 2, "probability": 1, "matches": [ { "text": { "chars": { "starts": [ 0 ], "lengths": [ 1509// ... truncated
Bad request.
Example Response
A typical response from this endpoint:
{ "ErrorMessage": "Language not supported", "ErrorCode": "unsupported-lang"}
Authorization has been denied for this request.
Example Response
A typical response from this endpoint:
{ "type": "https://tools.ietf.org/html/rfc9110#section-15.5.2", "title": "Unauthorized", "status": 401, "traceId": "00-ef0db7690ced98431ac97782051edc77-2c4194d74ae6c08b-00"}
Too many requests have been sent. The request has been rejected.
Example Response
A typical response from this endpoint:
{ "error": "Rate limit exceeded",}
Examples
Section titled “Examples”POST https://api.copyleaks.com/v2/writer-detector/source-code/my-scan-123/checkContent-Type: application/jsonAuthorization: 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"}
curl --request POST \ --url https://api.copyleaks.com/v2/writer-detector/source-code/my-scan-123/check \ --header 'Authorization: Bearer YOUR_LOGIN_TOKEN' \ --header 'Content-Type: application/json' \ --data '{ "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" }'