API docs
Every published workflow has an endpoint. Inputs are the keys of the “Input” nodes and outputs are the keys of the “Output” nodes.
Base URL: https://api.mlgrid.com
Authentication
Create a key on the “API keys” page and send it in the Authorization header.
Authorization: Bearer mlg_xxxxxxxxxxxxxxxxRun workflow
The request is synchronous and returns the result when the run finishes.
POST https://api.mlgrid.com/v1/workflows/{slug}/run
Content-Type: application/json
{ "input": { "text": "..." } }{
"id": "cm...",
"status": "succeeded",
"output": { "summary": "..." },
"usage": { "tokensIn": 812, "tokensOut": 164, "cost": "38.2", "currency": "IRT" }
}Output files
Outputs such as images, audio, video, PDF, Word and Excel are returned as URLs. These files are deleted 24 hours after they are made; download and store them right away if you need them.
Get the input/output contract
GET https://api.mlgrid.com/v1/workflows/{slug}Run status
GET https://api.mlgrid.com/v1/runs/{id}Memory and sessions
If a workflow has “Read memory” and “Save to memory” nodes, every call with the same session continues the same conversation. Memory is separate per user (API key); different users of a public workflow never see each other’s memory. Messages older than the configured window are handed to the node you connected for summarizing, and the summary replaces them.
POST https://api.mlgrid.com/v1/workflows/{slug}/run
Authorization: Bearer mlg_xxxxxxxx
Content-Type: application/json
{ "input": { "message": "اسم من سارا است" }, "session": "user-42" }DELETE https://api.mlgrid.com/v1/workflows/{slug}/memory?session=user-42Cost calculation
Cost per node = (input tokens × input rate + output tokens × output rate) ÷ 1,000,000 + the flat per-call fee. A run’s total is the sum of all nodes plus the creator fee (if any), deducted from the caller’s wallet.
Tokens are read directly from the model provider’s report. If a run fails midway, only the nodes that ran are charged.
Errors
400Invalid request body (e.g. the input field is missing).401API key missing or revoked.402Insufficient wallet balance.404The workflow doesn’t exist, isn’t published, or is private.422One of the nodes failed; nodeId in the response tells you which.429Too many requests (60 per minute per user).Create a custom model
main.py must define an execute function. It returns either the outputs dict directly or one containing outputs and usage (to report tokens).
def execute(inputs, params):
text = inputs.get("text", "")
return {
"outputs": {"text": text[::-1]},
"usage": {"tokensIn": len(text), "tokensOut": len(text)},
}