REST API
POST /v1/analyze
Submit code for analysis by four AI agents -- security, performance, maintainability, documentation.
POST /v1/analyze
Analyze code for security, performance, maintainability, and documentation issues.
Requires the rest_api feature (Developer tier and above).
Request
POST /v1/analyze
Authorization: Bearer uk_afa_...
Content-Type: application/jsonBody
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
code | string | Yes | -- | Source code to analyze (max 500KB) |
language | string | No | "python" | Language: python, typescript, go, java, rust |
depth | string | No | "comprehensive" | Analysis depth: quick or comprehensive |
{
"code": "def process_data(items):\n result = []\n for item in items:\n if item > 0:\n result.append(item * 2)\n return result",
"language": "python",
"depth": "comprehensive"
}Response
{
"results": [
{
"function": "api_input",
"file": "api",
"scores": {
"security": 0.90,
"performance": 0.75,
"maintainability": 0.80,
"documentation": 0.40
},
"findings": [
{
"category": "performance",
"severity": "medium",
"message": "List comprehension would be more idiomatic and faster",
"line": 3
},
{
"category": "documentation",
"severity": "high",
"message": "Missing docstring with parameter and return type documentation",
"line": 1
}
],
"enhancement_eligible": true
}
],
"summary": {
"functions_analyzed": 1,
"llm_calls": 4,
"enhancement_eligible": 1
}
}Response fields
| Field | Description |
|---|---|
results | Array of per-function analysis results |
results[].scores | Per-category scores (0.0 to 1.0) |
results[].findings | Array of identified issues |
results[].enhancement_eligible | Whether AFA can generate improvements |
summary.functions_analyzed | Total functions processed |
summary.llm_calls | Number of LLM API calls made (4 per function) |
summary.enhancement_eligible | Count of functions eligible for enhancement |
Examples
curl
curl -X POST https://api.afa.undercurrentholdings.com/v1/analyze \
-H "Authorization: Bearer uk_afa_..." \
-H "Content-Type: application/json" \
-d '{
"code": "def hello(name):\n print(\"Hello \" + name)",
"language": "python"
}'Python (httpx)
import httpx
response = httpx.post(
"https://api.afa.undercurrentholdings.com/v1/analyze",
headers={"Authorization": "Bearer uk_afa_..."},
json={
"code": "def hello(name):\n print('Hello ' + name)",
"language": "python",
"depth": "comprehensive",
},
)
data = response.json()
for result in data["results"]:
print(f"Score: {result['scores']}")
for finding in result["findings"]:
print(f" [{finding['severity']}] {finding['message']}")Errors
| Status | Cause |
|---|---|
| 400 | Unsupported language or empty code input |
| 401 | Missing or invalid API key |
| 403 | rest_api feature not available on your tier |
| 429 | Rate limit exceeded |
| 500 | Analysis failed (internal error, details not exposed) |