POST
https://www.brainiac.software/api/v1/code/maintainability-index$0.04 USDCIndex source maintainability
Build a structural AST from a caller-supplied JavaScript, TypeScript, Python, or Go snippet, or from a caller-supplied AST, and score cyclomatic complexity, cognitive load, nesting depth, and duplicated function structure. The snippet is not executed or stored.
Body
| Field | Required | Notes |
|---|---|---|
language | No | string; One of: javascript, typescript, python, go |
source | No | string |
ast | No | — |
Request exampleJSON
{
"language": "javascript",
"source": "function price(order) {\n if (order.rush && order.total > 100) {\n if (order.member) {\n return order.total * 0.9\n } else {\n return order.total * 0.95\n }\n }\n if (order.rush) {\n return order.total * 1.1\n }\n return order.total\n}\n\nfunction priceCopy(order) {\n if (order.rush && order.total > 100) {\n if (order.member) {\n return order.total * 0.9\n } else {\n return order.total * 0.95\n }\n }\n if (order.rush) {\n return order.total * 1.1\n }\n return order.total\n}\n"
}Response exampleJSON
{
"maintainability_score": 40,
"cognitive_load_index": 38,
"technical_debt_estimate_hours": 0.75,
"audit_receipt": "sha256:cf03e0c1a32b0737eb97627b5b20a8417532be3c944cd89c9200400c13870f09"
}cURL
curl -i -X POST "https://www.brainiac.software/api/v1/code/maintainability-index" \
-H 'content-type: application/json' \
-H 'Idempotency-Key: <fresh-64-character-random-hex-key>' \
--data-binary @- <<'JSON'
{
"language": "javascript",
"source": "function price(order) {\n if (order.rush && order.total > 100) {\n if (order.member) {\n return order.total * 0.9\n } else {\n return order.total * 0.95\n }\n }\n if (order.rush) {\n return order.total * 1.1\n }\n return order.total\n}\n\nfunction priceCopy(order) {\n if (order.rush && order.total > 100) {\n if (order.member) {\n return order.total * 0.9\n } else {\n return order.total * 0.95\n }\n }\n if (order.rush) {\n return order.total * 1.1\n }\n return order.total\n}\n"
}
JSON