Back to top

Judge0 API docs

About

Judge0 API is an open source API for code compilation and execution. Source code is available on GitHub.

We have included dummy client which can be used to try and test features of Judge0 API.

Date and time formats

ISO 8601 standard is used.

Example: 2016-09-11T10:19:35Z

License

License: GPL v3


Submissions

Submission

Submission has following attributes:

1. source_code

  • Type: string

  • Required/Optional: required

  • Description: Source code of submission.

2. language_id

  • Type: integer

  • Required/Optional: required

  • Description: Language ID.

3. input

  • Type: string

  • Required/Optional: optional

  • Description: Input for submission.

  • Default Value: null. Submission won’t recieve anything to standard input.

4. expected_output

  • Type: string

  • Required/Optional: optional

  • Description: Expected output of submission. Used when you want to compare with stdout.

  • Default Value: null. Submission result stdout won’t be compared with expected_output.

5. cpu_time_limit

  • Type: float

  • Unit: second

  • Required/Optional: optional

  • Description: Runtime limit for submission.

  • Default Value: Depends on configuration.

6. cpu_extra_time

  • Type: float

  • Unit: second

  • Required/Optional: optional

  • Description: Extra wait time after cpu_time_limit has been exceeded.

  • Default Value: Depends on configuration.

7. wall_time_limit

  • Type: float

  • Unit: second

  • Required/Optional: optional

  • Description: Wall-clock time limit for submission.

  • Default Value: Depends on configuration.

8. memory_limit

  • Type: integer

  • Unit: kilobyte

  • Required/Optional: optional

  • Description: Address space limit for submission.

  • Default Value: Depends on configuration.

9. stack_limit

  • Type: ineger

  • Unit: kilobyte

  • Required/Optional: optional

  • Description: Stack limit for submission.

  • Default Value: Depends on configuration.

10. max_processes_and_or_threads

  • Type: integer

  • Required/Optional: optional

  • Description: Maximum number of processes and/or threads submission can create.

  • Default Value: Depends on configuration.

11. enable_per_process_and_thread_time_limit

  • Type: boolean

  • Required/Optional: optional

  • Description: If true then cpu_time_limit will be used as per process and thread.

  • Default Value: Depends on configuration.

12. enable_per_process_and_thread_memory_limit

  • Type: boolean

  • Required/Optional: optional

  • Description: If true then memory_limit will be used as per process and thread.

  • Default Value: Depends on configuration.

13. max_file_size

  • Type: integer

  • Unit: kilobyte

  • Required/Optional: optional

  • Description: Limit file size created or modified by submission.

  • Default Value: Depends on configuration.

14. number_of_runs

  • Type: integer

  • Required/Optional: optional

  • Description: Run each submission number_of_runs times and take average of time and memory.

  • Default Value: Depends on configuration.

15. stdout

  • Type: string

  • Description: Standard output of submission after execution.

16. stderr

  • Type: string

  • Description: Standard error of submission after execution.

17. status

  • Type: object

  • Description: Status of submission.

18. created_at

  • Type: datetime

  • Description: Date and time when submission was created.

19. finished_at

  • Type: datetime

  • Description: Date and time when submission was processed.

  • Default Value: null if submission is still in queue or if submission is processing.

20. token

  • Type: string

  • Description: Unique token of submission. Used to access submission results asynchronically.

21. time

  • Type: float

  • Unit: second

  • Description: Run time of submission.

22. memory

  • Type: float

  • Unit: second

  • Description: Memory used by submission.


Attributes #1 - #14 are used when creating new submissions, and attributes #15 - #22 represent detailed information about runtime of submission.

Attributes #5 - #14 are called configuration attributes or configuration variables. Please read more about them in configuration section.

Create
POST/submissions/{?base64_encoded}

Creates new submission. Created submission waits in queue to be processed. On successful creation, you are returned submission token which can be used to check submission status.

If submission’s source_code, input or expected_output contains non printable characters, or characters which cannot be sent with JSON, then set base64_encoded parameter to true and send these attributes Base64 encoded. Your responsibility is to encode each of mentioned attributes (source_code, input and expected_output) even if just one of them contains non printable characters. By default, this parameter is set to false and Judge0 API assumes you are sending raw data (decoded data).

Example URI

POST https://api.judge0.com/submissions/?base64_encoded=false
URI Parameters
HideShow
base64_encoded
boolean (optional) Example: false

Set to true if you want to send Base64 encoded data to Judge0 API.

Request
HideShow
Headers
Content-Type: application/json
Body
{
  "source_code": "#include \n\nint main(void) {\n  char name[10];\n  scanf(\"%s\", name);\n  printf(\"hello, %s\n\", name);\n  return 0;\n}",
  "language_id": 3
}
Response  201
HideShow
Headers
Content-Type: application/json
Body
{
  "token": "d85cd024-1548-4165-96c7-7bc88673f194"
}
Request
HideShow
Headers
Content-Type: application/json
Body
{
  "source_code": "#include \n\nint main(void) {\n  char name[10];\n  scanf(\"%s\", name);\n  printf(\"hello, %s\n\", name);\n  return 0;\n}"
}
Response  422
HideShow
Headers
Content-Type: application/json
Body
{
  "language_id": [
    "can't be blank"
  ]
}
Request
HideShow
Headers
Content-Type: application/json
Body
{
  "source_code": "#include <stdio.h>\n\nint main(void) {\n  char name[10];\n  sc(\"%s\", name);\n  printf(\"hello, %s\n\", name);\n  return 0;\n}",
  "language_id": 150000,
  "input": "world",
  "expected_output": "hello, world"
}
Response  422
HideShow
Headers
Content-Type: application/json
Body
{
  "language_id": [
    "language with id 150000 doesn't exist"
  ]
}
Request
HideShow
Headers
Content-Type: application/json
Body
{
  "source_code": "#include \n\nint main(void) {\n  char name[10];\n  scanf(\"%s\", name);\n  printf(\"hello, %s\n\", name);\n  return 0;\n}",
  "language_id": 3,
  "number_of_runs": 1,
  "input": "Judge0",
  "expected_output": "hello, Judge0",
  "cpu_time_limit": 1,
  "cpu_extra_time": 0.5,
  "wall_time_limit": 100000,
  "memory_limit": 128000,
  "stack_limit": 128000,
  "enable_per_process_and_thread_time_limit": false,
  "enable_per_process_and_thread_memory_limit": false,
  "max_file_size": 1024
}
Response  422
HideShow
Headers
Content-Type: application/json
Body
{
  "wall_time_limit": [
    "must be less than or equal to 150"
  ]
}
Request
HideShow

Sending Base64 encoded source_code and input. Note that in this request base64_encoded query parameter must be set to true.

Headers
Content-Type: appliction/json
Body
{
  "source_code": "I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKSB7CiAgY2hhciBuYW1lWzEwXTsKICBzY2FuZigiJXMiLCBuYW1lKTsKICBwcmludGYoImhlbGxvLCAlc1xuIiwgbmFtZSk7CiAgcmV0dXJuIDA7Cn0=",
  "language_id": 3,
  "input": "SnVkZ2Uw"
}
Response  200
HideShow
Headers
Content-Type: application/json
Body
{
  "token": "f3fe0215-72f3-4fe6-97f5-353df6682db4"
}

Show
GET/submissions/{token}{?base64_encoded}

Returns details about submission execution result.

If you expect non printable characters in submission’s stdout or stderr after it’s execution, you can request Judge0 API to return you Base64 encoded stdout and stderr by setting base64_encoded query parametar to true. Your responsibility is to decode each of menitioned attributes (stdout and stderr) on client side. By default, this parameter is set to false and Judge0 API will send you raw data (decoded data).

Example URI

GET https://api.judge0.com/submissions/d85cd024-1548-4165-96c7-7bc88673f194?base64_encoded=false
URI Parameters
HideShow
token
string (required) Example: d85cd024-1548-4165-96c7-7bc88673f194

Token of submission. You got this token when you created submission.

base64_encoded
boolean (optional) Example: false

Set to true if you want to recieve Base64 encoded data from Judge0 API.

Response  200
HideShow
Headers
Content-Type: application/json
Body
{
  "token": "d85cd024-1548-4165-96c7-7bc88673f194",
  "status": {
    "id": 1,
    "description": "In Queue"
  },
  "stdout": null,
  "stderr": null,
  "created_at": "2017-02-04T22:11:05.590Z",
  "finished_at": null,
  "time": null,
  "memory": null,
  "number_of_runs": 1,
  "cpu_time_limit": "1.0",
  "cpu_extra_time": "0.5",
  "wall_time_limit": "10.0",
  "memory_limit": 128000,
  "stack_limit": 128000,
  "enable_per_process_and_thread_time_limit": false,
  "enable_per_process_and_thread_memory_limit": false,
  "max_file_size": 1024
}
Response  200
HideShow
Headers
Content-Type: application/json
Body
{
  "token": "d85cd024-1548-4165-96c7-7bc88673f194",
  "status": {
    "id": 3,
    "description": "Accepted"
  },
  "stdout": "hello, Judge0\n",
  "stderr": "",
  "created_at": "2017-02-04T22:11:05.590Z",
  "finished_at": "2017-02-04T22:11:08.564Z",
  "time": "0.002",
  "memory": 248,
  "number_of_runs": 1,
  "cpu_time_limit": "1.0",
  "cpu_extra_time": "0.5",
  "wall_time_limit": "10.0",
  "memory_limit": 128000,
  "stack_limit": 128000,
  "enable_per_process_and_thread_time_limit": false,
  "enable_per_process_and_thread_memory_limit": false,
  "max_file_size": 1024
}
Response  200
HideShow

Recieving Base64 encoded stdout and stderr. Note that in this request base64_encoded query parameter must be set to true.

Headers
Content-Type: application/json
Body
{
  "token": "f3fe0215-72f3-4fe6-97f5-353df6682db4",
  "status": {
    "id": 3,
    "description": "Accepted"
  },
  "stdout": "aGVsbG8sIEp1ZGdlMAo=\n",
  "stderr": "",
  "created_at": "2017-04-22T23:42:34.451Z",
  "finished_at": "2017-04-22T23:42:34.770Z",
  "time": "0.002",
  "memory": 288,
  "number_of_runs": 1,
  "cpu_time_limit": "1.0",
  "cpu_extra_time": "0.5",
  "wall_time_limit": "10.0",
  "memory_limit": 128000,
  "stack_limit": 128000,
  "max_processes_and_or_threads": 30,
  "enable_per_process_and_thread_time_limit": true,
  "enable_per_process_and_thread_memory_limit": true,
  "max_file_size": 1024
}
Response  500
HideShow

If you get status 500 on this request, it is probably because your submission stdout or stderr contains some non printable characters which cannot be used in JSON. In that case, set base64_encoded query parameter to true, and decode stdout and stderr on client side.

Headers
Content-Type: application/json
Body
{
  "status": 500,
  "error": "Internal Server Error",
  "exception": "#<Encoding::UndefinedConversionError: \"\x80\" from ASCII-8BIT to UTF-8>",
  ...
}

Statuses and Languages

Languages

List all languages
GET/languages

Example URI

GET https://api.judge0.com/languages
Response  200
HideShow
Headers
Content-Type: application/json
Body
[
  {
    "id": 1,
    "name": "Bash (4.4)"
  },
  {
    "id": 2,
    "name": "Bash (4.0)"
  },
  {
    "id": 3,
    "name": "C (gcc 6.3.0)"
  },
  {
    "id": 4,
    "name": "C (gcc 5.4.0)"
  },
  {
    "id": 5,
    "name": "C (gcc 4.9.4)"
  },
  {
    "id": 6,
    "name": "C (gcc 4.8.5)"
  },
  {
    "id": 7,
    "name": "C++ (g++ 6.3.0)"
  },
  {
    "id": 8,
    "name": "C++ (g++ 5.4.0)"
  },
  {
    "id": 9,
    "name": "C++ (g++ 4.9.4)"
  },
  {
    "id": 10,
    "name": "C++ (g++ 4.8.5)"
  },
  {
    "id": 11,
    "name": "C# (mono 4.8.0.472)"
  },
  {
    "id": 12,
    "name": "Haskell (ghc 8.0.2)"
  },
  {
    "id": 13,
    "name": "Java (OpenJDK 8)"
  },
  {
    "id": 14,
    "name": "Java (OpenJDK 7)"
  },
  {
    "id": 15,
    "name": "Octave (4.2.0)"
  },
  {
    "id": 16,
    "name": "Pascal (fpc 3.0.0)"
  },
  {
    "id": 17,
    "name": "Python (3.6.0)"
  },
  {
    "id": 18,
    "name": "Python (3.5.3)"
  },
  {
    "id": 19,
    "name": "Python (2.7.9)"
  },
  {
    "id": 20,
    "name": "Python (2.6.9)"
  },
  {
    "id": 21,
    "name": "Ruby (2.4.0)"
  },
  {
    "id": 22,
    "name": "Ruby (2.3.3)"
  },
  {
    "id": 23,
    "name": "Ruby (2.2.6)"
  },
  {
    "id": 24,
    "name": "Ruby (2.1.9)"
  }
]

Statuses

List all statuses
GET/statuses

Example URI

GET https://api.judge0.com/statuses
Response  200
HideShow
Headers
Content-Type: application/json
Body
[
  {
    "id": 1,
    "description": "In Queue"
  },
  {
    "id": 2,
    "description": "Processing"
  },
  {
    "id": 3,
    "description": "Accepted"
  },
  {
    "id": 4,
    "description": "Wrong Answer"
  },
  {
    "id": 5,
    "description": "Time Limit Exceeded"
  },
  {
    "id": 6,
    "description": "Compilation Error"
  },
  {
    "id": 7,
    "description": "Runtime Error (SIGSEGV)"
  },
  {
    "id": 8,
    "description": "Runtime Error (SIGXFSZ)"
  },
  {
    "id": 9,
    "description": "Runtime Error (SIGFPE)"
  },
  {
    "id": 10,
    "description": "Runtime Error (SIGABRT)"
  },
  {
    "id": 11,
    "description": "Runtime Error (NZEC)"
  },
  {
    "id": 12,
    "description": "Runtime Error (Other)"
  },
  {
    "id": 13,
    "description": "Internal Error"
  }
]

System and Configuration

System Info

System information gives you detailed information about system on which Judge0 API is running.

This information is result of two commands on a host system:

  • lscpu

  • free -h

Please note that Judge0 API consists of two systems: web and worker. Web system is the one who provides you the API, and Worker is the one who runs (processes) your submissions. They can be placed on two or more different hosts with different system configurations. Result of this API request is always from web system. This means that this request might be irrelevant to you if you as user don’t know if web and worker are hosted on the same machine. To find that out, please contact admins who host Judge0 API you are using.

System Info
GET/system_info

Example URI

GET https://api.judge0.com/system_info
Response  200
HideShow
Headers
Content-Type: application/json
Body
{
  "Architecture": "x86_64",
  "CPU op-mode(s)": "32-bit, 64-bit",
  "Byte Order": "Little Endian",
  "CPU(s)": "4",
  "On-line CPU(s) list": "0-3",
  "Thread(s) per core": "2",
  "Core(s) per socket": "2",
  "Socket(s)": "1",
  "NUMA node(s)": "1",
  "Vendor ID": "GenuineIntel",
  "CPU family": "6",
  "Model": "61",
  "Model name": "Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz",
  "Stepping": "4",
  "CPU MHz": "2508.703",
  "CPU max MHz": "2700.0000",
  "CPU min MHz": "500.0000",
  "BogoMIPS": "4392.12",
  "Virtualization": "VT-x",
  "L1d cache": "32K",
  "L1i cache": "32K",
  "L2 cache": "256K",
  "L3 cache": "3072K",
  "NUMA node0 CPU(s)": "0-3",
  "Mem": "7.7G",
  "Swap": "8.0G"
}

Configuration Info

Configuration information gives you detailed information about configuration of Judge0 API. This configuration can be changed through judge0-api.conf file by admin who hosts Judge0 API instance.

This configuration gives every admin a flexibility to configure Judge0 API according to server abilities and needs. It also gives users insight on some default configuration values which are used when their submission is run.

Each of these configuration variables have default values which we consider as recommended in case you are not sure should you change them.

We will refer to default values as values which Judge0 API automatically assigns to each of these configuration variables, if admin didn’t set them. For example default value of configuration variable cpu_time_limit is 1.

Following configuration variables are available:

1. cpu_time_limit

  • Type: float

  • Unit: second

  • Description: Default runtime limit for every submission. Time in which the OS assigns the processor to different tasks is not counted.

  • Default Value: 1

2. cpu_extra_time

  • Type: float

  • Unit: second

  • Description: Extra wait time after cpu_time_limit has been exceeded. This has the advantage that the real execution time is reported, even though it slightly exceeds time limit.

  • Default Value: 0.5

3. wall_time_limit

  • Type: float

  • Unit: second

  • Description: Wall-clock time limit for submission. This clock measures time from the start of the submission to its exit, so it does not stop when submission lost the CPU or when it is waiting for an external event. We recommend to use cpu_time_limit as the main limit, but set wall_time_limit to a much higher value as a precaution against sleeping programs.

  • Default Value: 10

4. memory_limit

  • Type: integer

  • Unit: kilobyte

  • Description: Address space limit for submission.

  • Default Value: 128000

5. stack_limit

  • Type: integer

  • Unit: kilobyte

  • Description: Stack space limit for submission.

6. max_processes_and_or_threads

  • Type: integer

  • Description: Maximum number of processes and/or threads submission can create.

  • Default Value: 15

7. enable_per_process_and_thread_time_limit

  • Type: boolean

  • Description: If true then cpu_time_limit will be used as per process and thread.

  • Default Value: false

8. enable_per_process_and_thread_memory_limit

  • Type: boolean

  • Description: If true then memory_limit will be used as per process and thread.

  • Default Value: false

9. max_file_size

  • Type: integer

  • Description: Limit file size created or modified by submission

  • Default Value: 1024

10. number_of_runs

  • Type: integer

  • Description: Run each submission number_of_runs times and take average of time and memory.

  • Default Value: 1

Default configuration value for each variable is given to you as response of this API call. For example default configuration value for variable cpu_extra_time might be 2, and if admin didn’t set this, then it is 0.5 (default value). This means that admin set cpu_extra_time configuration variable to value 2 and we say it is now default configuration value for this variable cpu_extra_time.

Every submission can change each of the configuration variables according to its needs. For example, user might create submission which has cpu_time_limit of 5 seconds. For security reasons we need to limit values of each of these configuration variables. For example, we don’t want user to create a submission which has cpu_time_limit of 100000 seconds.

For this security reason we are introducing limit configuration variables for each configuration variable.

1. max_cpu_time_limit

  • Type: float

  • Unit: second

  • Description: Maximum custom cpu_time_limit.

  • Default Value: 15

2. max_cpu_extra_time

  • Type: float

  • Unit: second

  • Description: Maximum custom cpu_extra_time.

  • Default Value: 5

3. max_wall_time_limit

  • Type: float

  • Unit: second

  • Description: Maximum custom wall_time_limit.

  • Default Value: 150

4. max_memory_limit

  • Type: integer

  • Unit: kilobyte

  • Description: Maximum custom memory_limit.

  • Default Value: 512000

5. max_stack_limit

  • Type: integer

  • Unit: kilobyte

  • Description: Maximum custom stack_limit.

  • Default Value: 512000

6. max_max_processes_and_or_threads

  • Type: integer

  • Description: Maximum custom max_processes_and_or_threads.

  • Default Value: 30

7. allow_enable_per_process_and_thread_time_limit

  • Type: integer

  • Description: If false, user won’t be able to set enable_per_process_and_thread_time_limit.

  • Default Value: true

8. allow_enable_per_process_and_thread_memory_limit

  • Type: integer

  • Description: If false, user won’t be able to set enable_per_process_and_thread_memory_limit.

  • Default Value: true

9. max_max_file_size

  • Type: integer

  • Unit: kilobyte

  • Description: Maximum custom max_file_size

  • Default Value: 4096

10. max_number_of_runs

  • Type: integer

  • Description: Maximum custom number_of_runs

  • Default Value: 20

For example, max_cpu_time_limit with value 20 means that user cannot create new submission which has cpu_time_limit greater than 20.

Configuration Info
GET/config_info

Example URI

GET https://api.judge0.com/config_info
Response  200
HideShow
Headers
Content-Type: application/json
Body
{
  "cpu_time_limit": 1,
  "max_cpu_time_limit": 15,
  "cpu_extra_time": 0.5,
  "max_cpu_extra_time": 5,
  "wall_time_limit": 10,
  "max_wall_time_limit": 150,
  "memory_limit": 128000,
  "max_memory_limit": 512000,
  "stack_limit": 128000,
  "max_stack_limit": 512000,
  "max_processes_and_or_threads": 15,
  "max_max_processes_and_or_threads": 30,
  "enable_per_process_and_thread_time_limit": false,
  "allow_enable_per_process_and_thread_time_limit": true,
  "enable_per_process_and_thread_memory_limit": false,
  "allow_enable_per_process_and_thread_memory_limit": true,
  "max_file_size": 1024,
  "max_max_file_size": 4096,
  "number_of_runs": 1,
  "max_number_of_runs": 20
}

Generated by aglio on 23 Apr 2017