Deploy a Wolfram Language Function as a Web API
Use APIFunction and CloudDeploy to turn a Wolfram Language calculation into an HTTP endpoint, with validation, permissions, and free-tier limits to check first.
13 May 2026, 15:04 UTC

Expose an existing Wolfram Language calculation as an HTTP endpoint
Your team maintains a Wolfram Language notebook that converts units, calculates shipping rates, or evaluates a symbolic expression. A frontend developer needs the same result from a web page or mobile app. Rewriting the logic in JavaScript invites drift, and provisioning a dedicated backend for one function is overkill.
You can publish the existing Wolfram Language code directly as a web API using APIFunction and CloudDeploy. APIFunction defines named parameters with type constraints, and the cloud handler serializes the return value as JSON or XML. CloudDeploy assigns a cloud object URL and a permission level such as Public, Private, or AllAuthenticated. Before you depend on the endpoint, verify input validation, permission scope, and the free-tier compute limits that apply to your account.
Define the API contract with APIFunction
APIFunction takes a list of parameter declarations and a body. Each declaration pairs a parameter name with a type constraint, for example "tempC" -> "Real". When a request arrives, the cloud handler validates the query parameters against those constraints, evaluates the body, and serializes the result. Invalid input produces an HTTP error response with symbolic information rather than an unhandled exception.
The exact way the body accesses validated parameters depends on your Wolfram Language version; consult the reference page for APIFunction before copying the pattern below.
api = APIFunction[{"tempC" -> "Real"},
Function[params,
UnitConvert[Quantity[params["tempC"], "DegreesCelsius"], "DegreesFahrenheit"]
]
];
This declares one real-valued parameter named tempC, converts it from degrees Celsius to degrees Fahrenheit, and returns a Quantity object that the cloud handler serializes for the client.
Deploy the endpoint and choose permissions
Run the deployment in Wolfram Desktop or a Wolfram Cloud notebook. You need a signed-in Wolfram Cloud account with permission to create cloud objects.
CloudDeploy[api, CloudObject["temperature-converter"],
Permissions -> "Public"
];
CloudDeploy creates or overwrites the named cloud object and returns a URL such as https://www.wolframcloud.com/objects/. The permission level controls who can invoke it:
| Permission | Who can invoke |
|---|---|
| Public | Anyone with the URL |
| Private | Only the cloud account owner |
| AllAuthenticated | Any signed-in Wolfram Cloud user |
For an internal experiment, start with Private or AllAuthenticated. A Public endpoint is reachable by anyone and consumes compute credits from the owning account.
Worked example: call the temperature converter
After deployment, call the endpoint from a terminal or any HTTP client. GET requests map query parameters to APIFunction arguments.
curl "https://www.wolframcloud.com/objects/?tempC=25"
Where to run: your local terminal. Required permissions: none beyond network access. Expected check: an HTTP 200 response with a JSON body containing the converted value. Risk: an invalid or missing tempC returns a validation error instead of a result, and a Private endpoint rejects unauthenticated requests.
If the response is not JSON as expected, inspect the response headers and status code. The Wolfram Cloud dashboard shows the cloud object's properties, including its current permission and deployment scope.
Limits and operational trade-offs
- The Wolfram Cloud free tier applies daily compute credits, concurrent request limits, and possible URL inactivity policies. These differ from paid and Enterprise Private Cloud editions.
APIFunctiondoes not provide automatic retry, rate limiting, or authentication beyond cloud permissions. Add those layers yourself if clients need them.- Long computations risk gateway timeouts. Offload heavy tasks or use asynchronous polling for responses that take more than a few seconds.
- Pricing, credit allowances, and endpoint availability change over time. Verify current allowances against Wolfram documentation before budgeting.
Because CloudDeploy changes state by creating or overwriting a cloud object, you can roll back by deleting the object or tightening its permission:
Delete[CloudObject["temperature-converter"]]
Or change the permission through the Wolfram Cloud dashboard.
Verify before you rely on it
- Create a simple
APIFunctionin Wolfram Desktop. - Deploy it to a test cloud account and record the returned URL.
- Call the URL with
curland inspect the HTTP status and body. - Open the Wolfram Cloud dashboard and confirm the cloud object permission matches the intended audience.
- Read the official reference pages for
CloudDeployandAPIFunctionto confirm parameter syntax and version-specific options.
Start with a private endpoint, measure credit burn for a realistic request volume, and only then promote it to a broader permission level or a paid tier.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.