guage|string| No | Programming language identifier. Supported values:typescript, javascript, python, go, rust. Defaults to typescript` if omitted or unrecognized. |
Request Body Example:
{
"code": "var x = 10;\nconsole.log(x);\nlet y = x == null;",
"language": "javascript"
}
Integration Notes:
- Ensure the
code string preserves original indentation and line breaks. Line numbers in the response are 1-based and directly correspond to the newline-separated input.
- If the
language field contains an unsupported value, the endpoint silently falls back to the typescript rule set. Validate language strings client-side to avoid unexpected rule matching.
The endpoint returns a structured JSON response containing the analysis results. All responses use standard HTTP status codes and include a consistent error envelope.
Success Response (200 OK)
| Field | Type | Description |
|---|
score | number | Quality score from 0 to 100. Calculated as Math.max(0, 100 - issues.length * 10). Each detected issue deducts exactly 10 points. |
summary | string | Human-readable overview of the review results. Returns "Great code! No issues found." when the issues array is empty. |
issues | array | List of detected problems. Each object contains:<br>β’ line (number): 1-based line number where the pattern matched.<br>β’ severity (string): Issue classification (defaults to warning).<br>β’ message (string): Description of the problem.<br>β’ suggestion (string, optional): Recommended fix or best practice. |
Success Response Example:
{
"score": 70,
"summary": "Found 3 issues. Review the suggestions below.",
"issues": [
{
"line": 1,
"severity": "warning",
"message": "Avoid \"var\", use \"let\" or \"const\"",
"suggestion": "Use const for immutable values, let for mutable"
},
{
"line": 2,
"severity": "warning",
"message": "Remove console.log in production",
"suggestion": "Use a proper logging library"
},
{
"line": 3,
"severity": "warning",
"message": "Use === instead of ==",
"suggestion": "Always use strict equality"
}
]
}
Error Responses
| Status Code | Description | Response Body |
|---|
400 | Bad Request | { "error": "Code is required" } β Returned when the code field is missing, null, or an empty string. |
500 | Internal Server Error | { "error": "Failed to review code" } β Returned if the server encounters an unexpected exception during JSON parsing or rule execution. |
401 / 404 | Not Applicable | This endpoint is public and does not require authentication. 401 responses are never returned. 404 responses only occur if the base URL or path is mistyped. |
Usage Example
Use the following curl command to submit a TypeScript snippet for review:
curl -X POST https://codcompass.com/api/ai/review \
-H "Content-Type: application/json" \
-d '{
"code": "function fetchData(): any {\n // TODO: Implement error handling\n return fetch(\"/api/data\");\n}",
"language": "typescript"
}'
Expected Output:
{
"score": 80,
"summary": "Found 2 issues. Review the suggestions below.",
"issues": [
{
"line": 1,
"severity": "warning",
"message": "Avoid using \"any\" type",
"suggestion": "Use \"unknown\" or specific types instead"
},
{
"line": 2,
"severity": "warning",
"message": "TODO comment found",
"suggestion": "Create a ticket for this task"
}
]
}
Common Pitfalls
- Case-Sensitive Language Keys: The
language parameter must exactly match the supported keys (typescript, javascript, python, go, rust). Passing TypeScript, JS, or py will cause the endpoint to fall back to the default typescript ruleset, potentially missing language-specific patterns or generating irrelevant warnings.
- Regex-Based False Positives: This endpoint uses pattern matching rather than AST parsing. It may flag matches inside string literals, comments, or dynamically generated code. For example, a string containing
"console.log" will still trigger the production logging rule. Filter or escape known acceptable patterns client-side if precision is critical.
- Scoring Thresholds & Line Alignment: Each detected issue deducts exactly 10 points from the base score of 100. If your code contains 10 or more flagged patterns, the score will clamp to
0. Additionally, line numbers are strictly tied to \n delimiters. If your input uses \r\n or lacks trailing newlines, line numbers may shift by one. Normalize line endings before submission for accurate mapping.
/api/ai/format β Automatically reformats submitted code according to language-specific style guides. Pairs well with /api/ai/review to programmatically fix linting issues after analysis.
/api/ai/explain β Generates detailed explanations of complex code blocks. Use this after reviewing to understand why certain patterns were flagged or to generate documentation for legacy code.
/api/docs/search β Queries the codcompass.com knowledge base for best practices, migration guides, and documentation related to the languages and patterns identified in your review results.
For integration support, payload size limits, or to report false positives in the rule engine, refer to the platformβs developer portal or submit feedback through the standard support channels.