Piston-compatible API
A Piston v2-compatible API at https://api.onlinecompiler.io/api/v2/piston, for apps built on the public Piston API: the same execute and runtimes endpoints, requests and responses, with your API key in the Authorization header.
Code written for Piston's v2 API runs here with two changes: point its base URL at https://api.onlinecompiler.io/api/v2/piston, and send your API key in the Authorization header. Requests and responses keep Piston's shape, including errors as {"message": "..."}.
GET
/api/v2/piston/runtimes no key neededPOST
/api/v2/piston/executecurl -X POST https://api.onlinecompiler.io/api/v2/piston/execute \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"language": "python",
"version": "*",
"files": [{ "name": "main.py", "content": "print(input())" }],
"stdin": "hello"
}'Response (200)
{
"language": "python",
"version": "3.14",
"run": {
"stdout": "hello\n",
"stderr": "",
"output": "hello\n",
"code": 0,
"signal": null,
"message": null,
"status": null,
"cpu_time": null,
"wall_time": 21,
"memory": 9216000
}
}Differences from Piston
- Piston's language names and aliases for our 45 languages work, such as
py,c++andcsharp. Other languages answer 400 with "runtime is unknown". versionis accepted and ignored: programs run on the current version that/runtimeslists.run_timeoutandrun_cpu_timestop the run at the lower of the two, capped at 30 seconds; compiling does not count, and Java, Groovy and F# get a start-up allowance on top (Java (1 s), Groovy (1.5 s) and F# (2.5 s)). Compile limits and memory limits are ignored, and our memory limit applies.- One file per program, in
utf8,base64orhex. Command-lineargsare not supported; send input throughstdin. - There is no separate
compilestage: compiler errors arrive inrun.stderrwith a non-zerorun.code. run.outputis stdout followed by stderr, not interleaved.wall_timeis in milliseconds andmemoryin bytes;cpu_timeis null.run.statusisREfor a non-zero exit or too many processes,TOfor the 30-second timeout,SGfor a signal,OLfor an output flood andXXfor an internal error.
Moving from Piston's public API? See Piston API alternatives.
Questions
- Do Piston language names work?
- Yes. Piston's names and aliases for our 45 languages work, such as py, c++ and csharp. Other languages answer 400 with "runtime is unknown".
- Can I pick a language version?
- version is accepted and ignored: programs run on the current version that /runtimes lists.
- Are command-line arguments supported?
- No. Send input through stdin instead.