Docs

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 needed
POST /api/v2/piston/execute
Terminal
curl -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)

Response
{
  "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++ and csharp. Other languages answer 400 with "runtime is unknown".
  • version is accepted and ignored: programs run on the current version that /runtimes lists. run_timeout and run_cpu_time stop 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, base64 or hex. Command-line args are not supported; send input through stdin.
  • There is no separate compile stage: compiler errors arrive in run.stderr with a non-zero run.code.
  • run.output is stdout followed by stderr, not interleaved. wall_time is in milliseconds and memory in bytes; cpu_time is null.
  • run.status is RE for a non-zero exit or too many processes, TO for the 30-second timeout, SG for a signal, OL for an output flood and XX for 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.