API to run the code
Users can integrate the API from their backend servers and execute the code programmatically.
Following is the cURL to call the /run
API to execute code
curl --location --request POST 'https://onecompiler.com/api/v1/run?access_token=your_access_token' \
--header 'Content-Type: application/json' \
--data-raw '{
"language": "python",
"stdin": "Peter",
"files": [
{
"name": "HelloWorld.py",
"content": "import sys\nname = sys.stdin.readline()\nprint('\''Hello '\''+ name)"
}
]
}'
Response:
{
"stdout": "Hello Peter\n",
"stderr": null,
"exception": null,
"executionTime": 41,
"limitPerMonthRemaining": 74694
"status": "success",
}
Field | Description |
---|---|
stdout | Standard output of the code execution |
stderr | Standard error of the code execution |
exception | Exception details during the code execution. Ex. Timeout/ Compilation failure etc., |
executionTime | Time taken to execute the code in milliseconds |
limitPerMonthRemaining | Remaining limit of the API calls in the API account |
status | Status of the API call (This does not indicate the code execution status) |
error | Error message in case of API Failure. This field return data when status: failed |
status values: success
/ failed
(ex. API key is invalid/ API quota exceeded/ Invalid language id etc.,)
Common error scenarios and their responses:
API operation timedout:
{
"status": "success",
"error": "E001: operation timed out"
}
Exceeded rate limits:
{
"status": "failed",
"error": "E002: API quota exceeded"
}
Invalid API Token:
{
"status": "failed",
"error": "E003: invalid access_token"
}
Missing API Token:
{
"status": "failed",
"error": "E004: access_token missing"
}
STDIN Too Long*:
{
"status": "failed",
"error": "E005: stdin too long"
}
Unsuppoted language:
{
"status": "failed",
"error": "E006: unsupported language xyz"
}
API to get the list of supported languages
http://onecompiler.com/api/v1/languages
Following are the list of supported languages and their ids
id | name | languageType | Supported Flags |
---|---|---|---|
ada | Ada | programming | |
angular | Angular | web | |
assembly | Assembly | programming | |
backbonejs | BackboneJS | web | |
bash | Bash | programming | |
basic | Basic | programming | |
bootstrap | Bootstrap | web | |
brainfk | BrainFK | programming | |
bulma | Bulma | web | |
bun | Bun | programming | |
c | C | programming | |
csharp | C# | programming | |
cpp | C++ | programming | |
clojure | Clojure | programming | |
cobol | Cobol | programming | |
coffeescript | CoffeeScript | programming | |
commonlisp | CommonLisp | programming | |
d | D | programming | |
dart | Dart | programming | |
deno | Deno | programming | |
ejs | EJS | programming | |
elixir | Elixir | programming | |
erlang | Erlang | programming | |
fsharp | F# | programming | |
fortran | Fortran | programming | |
foundation | Foundation | web | |
go | Go | programming | |
groovy | Groovy | programming | |
haskell | Haskell | programming | |
html | HTML | web | persist |
java | Java | programming | |
javascript | JavaScript | programming | |
jquery | JQuery | web | |
jshell | JShell | programming | |
kotlin | Kotlin | programming | |
lua | Lua | programming | |
mariadb | MariaDB | database | |
materialize | Materialize | web | |
sqlserver | Microsoft SQL Server | database | |
milligram | Milligram | web | |
mongodb | MongoDB | database | |
mysql | MySQL | database | --table, --tabbed, --vertical |
nodejs | NodeJS | programming | |
objectivec | Objective-C | programming | |
ocaml | OCaml | programming | |
octave | Octave | programming | |
oracle | Oracle Database | database | |
plsql | Oracle PL/SQL | database | |
paperCss | PaperCSS | web | |
pascal | Pascal | programming | |
perl | Perl | programming | |
php | PHP | programming | |
postgresql | PostgreSQL | database | |
prolog | Prolog | programming | |
python | Python | programming | |
python2 | Python2 | programming | |
r | R | programming | |
racket | Racket | programming | |
react | React | web | |
redis | Redis | database | |
ruby | Ruby | programming | |
rust | Rust | programming | |
scala | Scala | programming | |
semanticUI | Semantic UI | web | |
skeleton | Skeleton | web | |
sqlite | SQLite | database | |
swift | Swift | programming | |
tcl | Tcl | programming | |
text | Text | programming | |
typescript | TypeScript | programming | |
uikit | Uikit | web | |
vb | Visual Basic (VB.NET) | programming | |
vue | Vue | web |
Flags
persist
: To persist the output URL for 1 hour
--table
: To display the output in table format
--tabbed
: To display the output in tabbed format
--vertical
: To display the output in vertical format
Batch execution
If you plan to run the same code with multiple STDIN values, which is common when executing test cases, the API supports passing stdin as an array. When an array of values is provided, the API executes the code multiple times, once for each stdin value, and returns a list of response objects corresponding to each execution.
- In marketplace APIs, the limit is 2000 characters for STDIN. In OneCompiler APIs, the limit is upto 5000 characters. STDIN between 2000 and 5000 characters will be counted as 2 API calls.