Code execution API documentation
Get an API key, send it in the Authorization header, and POST source code to https://api.onlinecompiler.io/api/run-code-sync/ to get its output back. The pages below cover every endpoint, in 46 languages.
Também em portuguêsTambién en español
Moving from another service? See replacing the Piston API, migrating from Judge0, replacing Trinket embeds, moving from JDoodle's API, moving from Sphere Engine, running Moodle CodeRunner without Jobe or how Judge0 and the alternatives compare. Building a grader? See how to build an online judge or the autograder API.
https://api.onlinecompiler.ioTry it without an API key
Edit the program or its input and press Run. It runs for real, and below you get the request your code would send and the response it would get back.
name = input()
print(f"Hello, {name}!") World
The request
curl -X POST https://api.onlinecompiler.io/api/run-code-sync/ \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"compiler": "python-3.14",
"code": "name = input()\nprint(f\"Hello, {name}!\")",
"input": "World"
}'The response
Press Run in the editor to see it.
To send it from your own code, get a free API key: 100,000 runs a month, no credit card.
Authentication
All API requests require an API key passed in the Authorization header.
Key Types
There are two types of API keys, each scoped to specific endpoints:
| Key Type | Created From | Allowed Endpoints | Use Case |
|---|---|---|---|
| API | API Keys page | REST API (sync & async) | Server-side integrations, scripts, AI agents |
| WebSocket | Widgets page | WebSocket & embeddable widget | Embedded editors, browser-based apps |
Run your first program
With your API key in place of YOUR_API_KEY, this runs a Python program with one line of input and waits for the result:
curl -X POST https://api.onlinecompiler.io/api/run-code-sync/ \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"compiler": "python-3.14",
"code": "name = input()\nprint(f\"Hello, {name}!\")",
"input": "World"
}'The response has the program's output, errors, exit code, run time in seconds and memory in KB:
{
"output": "Hello, World!\n",
"error": "",
"status": "success",
"exit_code": 0,
"signal": null,
"truncated": false,
"time": "0.0248",
"total": "0.0330",
"memory": "8192"
}No key yet? Send the same request with no Authorization header to /api/guest/run-code/ to try it. Guest runs take the compiler, the code, up to 64 KB of input and up to 5 seconds; each address gets 20 an hour, and the answer adds a guest object with the runs left. For anything more, the free key above has 100,000 runs a month.
curl -X POST https://api.onlinecompiler.io/api/guest/run-code/ \
-H "Content-Type: application/json" \
-d '{"compiler": "python-3.14", "code": "print(sum(range(10)))"}'Every field, the async endpoint and the exit codes are in Run code. Other languages take their own compiler id, listed in Compilers.
A request over one of your account's limits gets HTTP 429 and nothing runs. When the limit clears by itself (per minute, pending, runs at once, busy sandboxes), the answer has a Retry-After header with the seconds to wait before sending it again; a spent monthly allowance has none.
An OpenAPI 3.1 description of the REST API is at https://api.onlinecompiler.io/openapi.json, for Postman, Swagger UI or an agent's tool builder. It covers run-code-sync, run-code, run-tests, stored problems, submissions (list, look up, delete and share), receipts, compilers, limits, usage and health.
Node.js client
The official client, onlinecompiler on npm, covers the REST API: runs, run-tests and test suites, background judging, stored problems, widget sessions, submissions, and webhook and receipt verification. It has no dependencies (it uses the global fetch and Web Crypto), includes TypeScript types, and works on Node 22.13+, Deno, Bun and Cloudflare Workers.
npm install onlinecompilerIt reads your API key from ONLINECOMPILER_API_KEY, or takes it as apiKey. This runs the program above, then judges another against two tests:
import { OnlineCompiler } from 'onlinecompiler';
const client = new OnlineCompiler(); // reads ONLINECOMPILER_API_KEY
const result = await client.run({
compiler: 'python-3.14',
code: 'name = input()\nprint(f"Hello, {name}!")',
input: 'World',
});
console.log(result.output); // Hello, World!
const judged = await client.runTests({
compiler: 'python-3.14',
code: 'a, b = map(int, input().split())\nprint(a + b)',
tests: [
{ input: '1 2', expected_output: '3' },
{ input: '10 20', expected_output: '30', hidden: true },
],
});
console.log(judged.verdict, judged.score); // accepted 100Request and response fields keep the API's own snake_case names, so these docs apply as written: client.iterSubmissions({ external_ref: 'student-42' }) goes through one candidate's submissions, every page of them. Use the client on your server: an API key in a browser bundle can be copied. To run code in the browser, use the widget, whose keys can be restricted to your domain. Every method is described in the README on npm, and the source is on GitHub. For models built with the Vercel AI SDK, the package also has runCode and runTests tools.
Python client
The official client, onlinecompiler on PyPI, covers the same REST API as the Node.js client. It uses only the standard library, includes type hints, and needs Python 3.10 or newer. Verifying receipts needs one extra, pip install "onlinecompiler[receipts]", which adds cryptography.
pip install onlinecompilerIt reads your API key from ONLINECOMPILER_API_KEY, or takes it as OnlineCompiler(api_key). The same two calls in Python:
from onlinecompiler import OnlineCompiler
client = OnlineCompiler() # reads ONLINECOMPILER_API_KEY
result = client.run("python-3.14", 'name = input()\nprint(f"Hello, {name}!")', input="World")
print(result["output"]) # Hello, World!
judged = client.run_tests(
"python-3.14",
"a, b = map(int, input().split())\nprint(a + b)",
tests=[
{"input": "1 2", "expected_output": "3"},
{"input": "10 20", "expected_output": "30", "hidden": True},
],
)
print(judged["verdict"], judged["score"]) # accepted 100Results are dicts with the API's own field names, and client.iter_submissions(external_ref="student-42") goes through one candidate's submissions, every page of them. Every method is described in the README on PyPI, and the source is on GitHub. Code written for the old runcode package runs again after pip install -U runcode, which now works through this client.
All docs pages
- Run code Run a program and get its output, errors, exit code, run time and memory, in the response or by callback.
- Run tests Judge a program against test cases: a verdict per test, hidden tests, checkers and scoring.
- Stored problems Keep tests, drivers and a checker on the server and judge code against a problem by id, with versions and a reference check.
- Webhooks Signed results for async run-tests submissions: the payload, how to verify it, retries and secret rotation.
- Receipts Signed proof of a verdict: what a receipt holds, what it proves and how to verify it offline.
- Compilers Compiler ids and versions, how each language is compiled and run, and how long a run takes.
- WebSocket Stream results to a browser app over Socket.IO, with a widget key.
- Widget and iframe Embed a runnable code editor with a script tag or an iframe, and control it from JavaScript.
- MCP server Let Claude, ChatGPT, Cursor and VS Code agents run and test code. Sign in or use an API key.
- Vercel AI SDK runCode and runTests tools for models built with the Vercel AI SDK, from the onlinecompiler npm package.
- VS Code extension Run the current file in any language from VS Code, with no compiler installed.
- LangChain Run code and run tests tools for LangChain agents, from the langchain-onlinecompiler package on PyPI.
- Node-RED Run code and judge it against test cases from a Node-RED flow, with the node from the Flow Library.
- Judge0 API Judge0 CE-compatible endpoints: change the base URL and the key.
- Piston API Piston's execute and runtimes endpoints, with your API key.
- Jobe API (CodeRunner) Jobe's REST API for Moodle CodeRunner: set the Jobe server and key.
- Limits and usage Time, memory and rate limits, the usage endpoint, and monthly limits per key.
Questions
- Which endpoint should I use?
- To run a program and wait for its output, /api/run-code-sync/. To queue many runs and get each result by callback, /api/run-code/. To judge a program against test cases, /api/run-tests/. To keep a problem's tests on the server and judge code against it by id, the stored problems API at /api/problems/ (see /docs/problems). To run code from a browser page, the WebSocket or the widget, with a widget key. Code written for Judge0 or Piston can keep its requests and use the compatible endpoints, and Moodle CodeRunner can use the Jobe-compatible endpoints in place of a Jobe server.
- Can I run code with a GET request, or without an API key?
- No. A run is a POST request with a JSON body and your API key in the Authorization header; there is no GET or keyless endpoint, so code never travels in a URL, where it would be cut short and kept in browser history and server logs. The key is free: sign in with Google at https://api.onlinecompiler.io/compilers/api-keys/ and your first key is made for you, with 100,000 runs a month on the Free plan, commercial use allowed and no card. To try a run before signing up, use "Try it without an API key" on this page. AI assistants can run code through the MCP server at https://api.onlinecompiler.io/mcp, which signs in with OAuth or takes an API key.
- Do I need an SDK?
- No. The API is HTTPS and JSON, so curl, fetch, requests or any HTTP client works, and each page has examples. For Node.js and Python there are official clients, npm install onlinecompiler and pip install onlinecompiler, with types and no dependencies. The WebSocket uses Socket.IO, and AI agents connect through the MCP server, which takes an OAuth sign-in or an API key.
- How long does a run take?
- A small Python program comes back in a median 0.56 seconds from request to response, and a Java one in 2.25, most of it compiling. Each run is limited to 30 seconds. The compilers page has the measured time for every language.