llms.txt
Search Documentation
Search through all documentation pages
Guides

API Custom Eval Examples

Ready-to-use API monitor eval functions for UP, DEGRADED, and DOWN states

Use these snippets directly in an API monitor.

JSONPlaceholder todos threshold eval

API: https://jsonplaceholder.typicode.com/todos
Response: Array of todo objects with completed boolean field.

[
  {
    "userId": 1,
    "id": 1,
    "title": "delectus aut autem",
    "completed": false
  },
	{
		"userId": 1,
		"id": 2,
		"title": "quis ut nam facilis et officia qui",
		"completed": true
	},
	...
]

Eval function:

(async function (statusCode, responseTime, responseRaw) {
    if (statusCode !== 200) {
        return { status: "DOWN", latency: responseTime }
    }

    let todos
    try {
        todos = JSON.parse(responseRaw)
    } catch {
        return { status: "DOWN", latency: responseTime }
    }

    if (!Array.isArray(todos)) {
        return { status: "DOWN", latency: responseTime }
    }

    const completedCount = todos.filter((t) => t && t.completed === true).length

    if (completedCount <= 10) {
        return { status: "UP", latency: responseTime }
    }

    if (completedCount <= 20) {
        return { status: "DEGRADED", latency: responseTime }
    }

    return { status: "DOWN", latency: responseTime }
})

POST request body with $SECRET_PARAM (no eval)

{
    "method": "POST",
    "headers": [{ "key": "Content-Type", "value": "application/json" }],
    "body": "{\"token\":\"$SECRET_PARAM\",\"action\":\"ping\"}"
}
SECRET_PARAM=your_real_secret_value

Important

$SECRET_PARAM is resolved from environment variables at runtime. If SECRET_PARAM is not set in .env (or process env), your request body will not be populated with the secret value.

Cheerio HTML content check

(async function (statusCode, responseTime, responseRaw, modules) {
    if (statusCode !== 200) {
        return { status: "DOWN", latency: responseTime }
    }

    let html = responseRaw
    const $ = modules.cheerio.load(html)
    const header = $('[class^="ContentBox_header"]')

    let status = true
    if (!header.text().includes("We’re fully operational")) {
        status = false
    }

    return {
        status: status ? "UP" : "DOWN",
        latency: responseTime
    }
})