Wolfram Language Computation API Reference
An evaluator for Wolfram Language inputs
The Wolfram Language Computation API evaluates Wolfram Language code to give reliable, computationally driven results suitable for use by an LLM.
Request API AccessUsing the API
Basic Usage
A basic request to the API takes the following form:
curl -X POST https://services.wolfram.com/api/apis/v1/WolframLanguageCompute \ -H "Content-Type: application/json" \ -H "Authorization: YOUR-API-KEY" \ -d '{ "code": "Sin[Pi]" }'
which yields the following response:
"{
"result":"Out[1]=0",
"code":200,
"success":true,
"uuid":"c071f090-de3a-437b-92e3-f0c3a5f540fa"
}"
Request Parameters
The following parameters can be passed in the body of an API request:
"code"
"line"
1
"maxChars"
10000
"timeConstraint"
60
code (required)
The code to be evaluated is passed to the API using the "code" parameter:
curl -X POST https://services.wolfram.com/api/apis/v1/WolframLanguageCompute \ -H "Content-Type: application/json" \ -H "Authorization: YOUR-API-KEY" \ -d '{ "code": "TrigExpand@Sin[2x]" }'
"{
"result":"Out[1]= 2*Cos[x]*Sin[x]",
"code":200,
"success":true,
"uuid":"ce174714-440e-4555-ab43-03063519d387"
}"
Images and graphics are returned via a Markdown image URL:
curl -X POST https://services.wolfram.com/api/apis/v1/WolframLanguageCompute \ -H "Content-Type: application/json" \ -H "Authorization: YOUR-API-KEY" \ -d '{ "code": "Graphics[{Red, Circle[]}]" }'
"{
"result":"Out[1]=",
"code":200,
"success":true,
"uuid":"05742275-377b-4844-8e5f-55a4fade45b4"
}"
View the image:
The free-form prompt character, =, can be used to represent ctrl-= in inputs to retrieve curated data through natural language:
curl -X POST https://services.wolfram.com/api/apis/v1/WolframLanguageCompute \ -H "Content-Type: application/json" \ -H "Authorization: YOUR-API-KEY" \ -d '{ "code" = "\[FreeformPrompt]["France population"]" }'
"{
"result":"During evaluation of In[1]:= [INFO] Interpreted "France population" as: Entity["Country", "France"][EntityProperty["Country", "Population"]]
Out[1]= Quantity[66438822, "People"]",
"code":200,
"success":true,
"uuid":"8f4cbebd-d08d-4c2d-9745-583e22668ebf"
}"
line (optional)
The integer appearing in the output label can be overridden with the "line" parameter:
curl -X POST https://services.wolfram.com/api/apis/v1/WolframLanguageCompute \ -H "Content-Type: application/json" \ -H "Authorization: YOUR-API-KEY" \ -d '{ "code": "Integrate[x, {x, 0, 1}]", "line": "50" }'
"{
"result":"Out[50]= 1/2",
"code":200,
"success":true,
"uuid":"f0098737-8194-4a4c-b71b-019534fac2f1"
}"
maxChars (optional)
The size of the output can be limited using the "maxChars" parameter:
curl -X POST https://services.wolfram.com/api/apis/v1/WolframLanguageCompute \ -H "Content-Type: application/json" \ -H "Authorization: YOUR-API-KEY" \ -d '{ "code": "ExampleData[{\"Text\", \"AliceInWonderland\"}]", "maxChars": 1000 }'
Elision markers << and >> indicate where the output was shortened and by how much:
{
result:"Out[1]= I--DOWN THE RABBIT-HOLE
Alice was beginning to get very tired of sitting by her sister on the bank,
> and of having nothing to do. Once or twice she had peeped into
the book her sister was
> reading, but it had no pictures or conversations in it, "and
what is the use of a book,"
> thought Alice, "without pictures or conversations?" So she was
considering in her own mind (as
> well as she could, for the day made her feel very sleepy and
stupid), whether the pleasure of
> making a daisy-chain would be worth the trouble of getting up
and picking the daisies, when
> suddenly <<50875>>ve had such a curious dream!" said Alice. And
she told her sister, as well
> as she could remember them, all these strange adventures of hers
that you have just been
> reading about. Alice got up and ran off, thinking while she ran,
as well she might, what a
> wonderful dream it had been.",
"code":200,
"success":true,
"uuid":"91b35aad-50d4-4e4b-a650-20ed368dee0b"
}
timeConstraint (optional)
Evaluation time can be limited using the "timeConstraint" parameter:
curl -X POST https://services.wolfram.com/api/apis/v1/WolframLanguageCompute \ -H "Content-Type: application/json" \ -H "Authorization: YOUR-API-KEY" \ -d '{ "code": "Pause[60]", "timeConstraint": "10" }'
When the time constraint is exceeded, "result" is a Failure expression:
{
"result":"
Failure["EvaluationTimeExceeded",
<|"MessageTemplate" -> "Evaluation exceeded the `1` second time limit.",
"MessageParameters" -> {10}|>]",
"code":200,
"success":true,
"uuid":"a83f98f1-6a88-4e16-860a-833d8369bd48"
}
Response
The returned JSON contains the following fields:
result(string) The result of evaluating the Wolfram Language expression passed in via the"code"body parametercode(integer) API status code (e.g.200,400,403,501, ...)success(Boolean)trueorfalsedepending on whether the request completed successfullyuuid(string) A unique ID labeling the response
Status Codes
200
This status indicates a success.
HTTP Status400
This status indicates that the API did not find an input parameter while parsing. In most cases, this can be fixed by checking that you have used the correct syntax for including the input parameter.
HTTP Status403
This status is returned when a request contains a missing or invalid API key in the authorization header. Double-check that your AppID is typed correctly and is using the correct syntax.
HTTP Status501
This status is returned if a given input value cannot be interpreted by this API. This is commonly caused by input that is misspelled, poorly formatted or otherwise unintelligible. Because this API is designed to return results for use in LLMs, the body of the 501 message may contain suggested inputs. You may occasionally receive this status when requesting information on topics that are restricted or not covered.
Use of these APIs is subject to the API Terms of Use and Commercial Terms of Use.