API Endpoints
ExplainThis offers a RESTful interface for source walkthroughs and analysis. All routes are accessible over HTTPS and require authentication.
Below you will find each endpoint, its parameters, and example requests. Use the Explain Code endpoint to send a snippet and get back a plain-English walkthrough. Use the List Explanations endpoint to fetch your saved results.
Explain Code
Get a detailed walkthrough for a code snippet
POST
/api/explainParameters
| Parameter | Type | Required? | Details | Default |
|---|---|---|---|---|
| code | string | Yes | The source snippet to break down | - |
| mode | string | No | Analysis mode (quick, standard, detailed, learning, performance, security, comparative) | standard |
| language | string | No | Programming language of the code | javascript |
| audience | string | No | Target audience level (beginner, intermediate, advanced, expert) | intermediate |
| focus | string[] | No | Pick one or more areas to zero in on (see focus-area list below) | [] |
Example Request
Request Body
{
"code": "function fibonacci(n) {\n if (n <= 1) return n;\n return fibonacci(n - 1) + fibonacci(n - 2);\n}",
"mode": "performance",
"language": "javascript",
"audience": "intermediate",
"focus": [
"performance"
]
}Example Response
Response Body
{
"explanation": "This is a recursive implementation of the Fibonacci sequence...",
"sections": [
{
"title": "Summary",
"content": "..."
}
],
"suggestions": [
{
"type": "Improvement",
"description": "Memoize repeated calls"
}
],
"metadata": {
"tokens": 320,
"complexity": {
"cognitive": 4,
"cyclomatic": 3,
"halstead": 12.5
}
}
}List Explanations
List saved walkthroughs for the signed-in user
GET
/api/explanationsParameters
| Parameter | Type | Required? | Details | Default |
|---|---|---|---|---|
| page | number | No | Pagination page | 1 |
| limit | number | No | Items per page | 10 |
| language | string | No | Filter by language | - |
| mode | string | No | Filter by analysis mode | - |
Focus Areas
When you call the Explain Code endpoint, you can ask the AI to pay extra attention to specific topics. Here is what each focus area covers:
- readability — Is the source easy to read and follow?
- performance — Could it run faster or use less memory?
- security — Are there any security risks?
- best_practices — Does the input follow common standards? Read our best practices guide for tips on getting the most from this focus area.
- architecture — Is the overall design sound?
- testing — Is it easy to test?
- documentation — Are comments and docs clear enough?
- scalability — Will it handle growth well?
- maintainability — Will future developers understand it?
Response Codes
| Code | Description |
|---|---|
| 200 | Successful request |
| 400 | Invalid request parameters |
| 401 | Invalid or missing API key |
| 429 | Rate limit exceeded |
| 500 | Internal server error |