Judge0-compatible API
A Judge0 CE-compatible API at https://api.onlinecompiler.io/api/judge0, with the same submissions, batches, languages and statuses endpoints, so a Judge0 client moves by changing its base URL and key. The differences from Judge0 are listed below.
Code written for Judge0 CE runs here with two changes: point its base URL at https://api.onlinecompiler.io/api/judge0, and send your API key in X-Auth-Token (or Authorization; code written for Judge0 CE on RapidAPI can keep sending it in x-rapidapi-key, and x-rapidapi-host is ignored). Submissions, tokens, batches, base64_encoded, fields, expected_output, callbacks and status ids work as on Judge0, and wait=true works too.
| Method | Path under /api/judge0 | What it does |
|---|---|---|
| POST | /submissions | Runs one submission. With ?wait=true the result comes back in the response; without it, a token to poll. |
| GET | /submissions/{token} | The submission and its result, with ?fields= and ?base64_encoded= as on Judge0. |
| POST | /submissions/batch | Up to 20 submissions at once, and no more than your account's pending limit. |
| GET | /submissions/batch?tokens= | Several submissions by token, in the order asked. |
| GET | /languages, /languages/all, /languages/{id} | Judge0 language ids for our compilers. No key needed. |
| GET | /statuses | Judge0's 14 statuses. No key needed. |
curl -X POST "https://api.onlinecompiler.io/api/judge0/submissions?wait=true" \
-H "X-Auth-Token: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"language_id": 71,
"source_code": "print(int(input()) * 2)",
"stdin": "21",
"expected_output": "42"
}'Response (201)
{
"token": "6f1c2b9e-0d4a-4a53-9f7e-2b8c1d3e4f50",
"time": "0.0213",
"memory": 9216,
"stdout": "42\n",
"stderr": null,
"compile_output": null,
"message": null,
"status": { "id": 3, "description": "Accepted" }
}Differences from Judge0
- Older language ids, such as 71 for Python 3.8 and 62 for Java 13, run on the current version. Judge0 CE ids we don't run answer 422 (
language with id N doesn't exist), so check them before switching: Executable (44), Python 2.7 (70), Multi-file program (89) and JavaFX (96). Plain Text (43) answers with the source as its output, as on Judge0: nothing runs. - Judge0 Extra CE's ids work at the same base URL for the languages we run, since they never clash with CE's: Python for ML (33, 32, 31, 25, 10), C (1, 13), C++ (2, 14), Java (4), C# (30, 29, 21, 22), F# (24), Visual Basic.Net (20) and Nim (9). Python for ML runs on
python-3.14-pandas2, set to Judge0's own Python for ML: numpy 2.3.5, pandas 2.3.3, scipy 1.16.3, scikit-learn 1.7.2 and matplotlib 3.10.7, the same versions apart from numpy (Judge0's 2.2.6 has no Python 3.14 build). A call that only warns on Judge0 only warns here too, exceptndarray.tostring(), which numpy 2.3 removed. It has seaborn and statsmodels too, but not PyTorch, TensorFlow or Keras. Not run: C3 (3), the Java, C++ and C# test runners (5, 12, 15 and 23), MPI (6, 7 and 8), Bosque (11), PyPy (26, 27 and 28) and Multi-file program (89)./languagesstays Judge0 CE's list;/languages/alland/languages/{id}include the Extra CE ids. - The lower of
cpu_time_limitandwall_time_limit, capped at 30 seconds, stops the run and gives Time Limit Exceeded; compiling does not count, Java, Groovy and F# get a start-up allowance on top (Java (1 s), Groovy (1.5 s) and F# (2.5 s)), and 0 means no limit of your own.timeis wall-clock seconds. The other limits are accepted and ignored, except a highermemory_limit(below). memory_limitabove 524288 KB raises the run's memory on Pro and above, up to 2097152 KB (2 GB), and the response reports what the run got. A lower value keeps our 512 MB, because many Judge0 clients send 128000 KB, less than a Java, Kotlin or F# program uses just to start. For a lower limit of your own, sendmemory_limitto the native run-code API.timeis the run command's wall-clock seconds, which for Java, F#, TypeScript, Dart, Erlang, Elixir, Clojure and Groovy includes compiling as they start.- Compilation Error (6) comes with
compile_outputfor C, C++, C#, Go, Rust, Haskell, Fortran, Visual Basic, Kotlin, Swift, COBOL, Pascal, Assembly, OCaml, D, FreeBASIC, Scala and Objective-C. The other languages compile or check code as they run, so their compile errors are Runtime Error (NZEC) with the message instderr. command_line_argumentsis split like a shell command line, so quotes group words ("two words"is one argument), and the program receives the result after its command: up to 32 arguments and 4,096 bytes in all. It stays plain text withbase64_encoded=true, as on Judge0. A string that cannot be split, such as one with an unclosed quote, answers 422, and so do arguments for sqlite-3, duckdb-1.5 or erlang-29, which cannot take them. The submission returns the string as sent.- A non-empty
compiler_optionsandenable_networkanswer 422; an emptycompiler_optionsis accepted. additional_files, a base64-encoded zip, is unpacked into the program's working directory, so it can carry data files such as a CSV. It follows the input file limits: up to 20 files and 1 MB once unpacked. The zip may hold folders. Files in the submission's language are compiled or loaded with the program, as with several source files, where Judge0 compiles only the main file. A file the program includes, such as#include "util.c", is compiled as part of it, as on Judge0; one it does not include is compiled too, so it must not define a secondmain. Judge0's Multi-file program language (89) is not offered. A zip with links, absolute paths or..in its names, or one that is too large, is refused.- Responses never include output files. To get charts and other files back, use the run endpoints.
- A batch is admitted whole or not at all. Account limits answer 429 and a queue failure 503, both as
{"error": "..."}. - There is no listing or deleting submissions, and
compile_cmdandrun_cmdare null; our commands are listed above.
Calling from a web page
Your API key has to stay secret, so a page doesn't call the API itself, and the API sends no CORS headers, so a page on your site can't read its answers anyway. Instead the page posts the same request to a short route on your own server, which adds the key. On Vercel, or any host that runs Next.js, that is one file:
// app/api/run/route.ts: the page posts here, and the key stays on the server.
export async function POST(request: Request) {
// Browsers send the page's Origin with a POST, and pages can't change it.
if (request.headers.get('origin') !== process.env.SITE_ORIGIN) {
return new Response('Forbidden', { status: 403 });
}
const res = await fetch('https://api.onlinecompiler.io/api/judge0/submissions?wait=true', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: process.env.ONLINECOMPILER_API_KEY!,
},
body: await request.text(),
});
return new Response(res.body, {
status: res.status,
headers: { 'Content-Type': 'application/json' },
});
}On Netlify the same code goes in netlify/functions/run.mts as export default async (request: Request) => { ... }, with export const config = { path: '/api/run' }. For a static site hosted elsewhere,
such as GitHub Pages, a Cloudflare Worker does the same and answers the browser's CORS check:
// A Cloudflare Worker. Set SITE_ORIGIN (such as https://example.com) as a
// variable and ONLINECOMPILER_API_KEY as a secret.
export default {
async fetch(request, env) {
if (request.headers.get('Origin') !== env.SITE_ORIGIN) {
return new Response('Forbidden', { status: 403 });
}
const cors = {
'Access-Control-Allow-Origin': env.SITE_ORIGIN,
'Access-Control-Allow-Methods': 'POST',
'Access-Control-Allow-Headers': 'Content-Type',
};
if (request.method === 'OPTIONS') return new Response(null, { headers: cors });
if (request.method !== 'POST') return new Response('Method not allowed', { status: 405, headers: cors });
const res = await fetch('https://api.onlinecompiler.io/api/judge0/submissions?wait=true', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: env.ONLINECOMPILER_API_KEY },
body: await request.text(),
});
return new Response(res.body, {
status: res.status,
headers: { ...cors, 'Content-Type': 'application/json' },
});
},
};The page then sends the request it sent before, to the route:
// In the page: '/api/run' for the Next.js route, or the Worker's URL.
const res = await fetch('/api/run', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ language_id: 71, source_code: code, stdin }),
});
const submission = await res.json(); // submission.stdout, submission.status.descriptionThe Origin check keeps other websites from using your route from their visitors' browsers. A script outside a browser can send any Origin, so also give the key a monthly limit on the API keys page, and turn on your host's rate limiting for a busy public page.
New to the calls themselves? The Judge0 API guide explains submissions, status ids, language ids and errors with examples. Moving a Judge0 integration? See the Judge0 migration guide.
Questions
- Do old Judge0 language ids work?
- Yes. Older ids, such as 71 for Python 3.8 and 62 for Java 13, run on the current version. Ids for languages we don't run answer 422.
- Do Judge0 Extra CE ids work?
- Yes, at the same base URL, for the languages we run: Python for ML (33, 32, 31, 25, 10), C (1, 13), C++ (2, 14), Java (4), C# (30, 29, 21, 22), F# (24), Visual Basic.Net (20) and Nim (9). Python for ML runs on python-3.14-pandas2, set to Judge0's own Python for ML: numpy 2.3.5, pandas 2.3.3, scipy 1.16.3, scikit-learn 1.7.2 and matplotlib 3.10.7, the same versions apart from numpy (Judge0's 2.2.6 has no Python 3.14 build), with seaborn but not PyTorch or TensorFlow. A call that only warns on Judge0 only warns here too, except ndarray.tostring(), which numpy 2.3 removed.
- Does wait=true work?
- Yes. POST /submissions?wait=true returns the result in the response; without it you get a token to poll with GET /submissions/{token}.
- How many submissions fit in a batch?
- Up to 20, and no more than your account's pending limit. A batch is admitted whole or not at all.
- Are memory_limit and command_line_arguments honoured?
- Both are. command_line_arguments is split like a shell command line and passed to the program. A memory_limit above 524288 KB raises the run's memory on Pro and above, up to 2097152 KB (2 GB), as on Judge0's own servers (Free and Starter keep 512 MB); a lower value keeps our 512 MB, because many Judge0 clients send 128000 KB, less than a Java, Kotlin or F# program uses just to start. For a lower limit of your own, send memory_limit to the native run-code API.