AFAdocs
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/json

Body

FieldTypeRequiredDefaultDescription
codestringYes--Source code to analyze (max 500KB)
languagestringNo"python"Language: python, typescript, go, java, rust
depthstringNo"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

FieldDescription
resultsArray of per-function analysis results
results[].scoresPer-category scores (0.0 to 1.0)
results[].findingsArray of identified issues
results[].enhancement_eligibleWhether AFA can generate improvements
summary.functions_analyzedTotal functions processed
summary.llm_callsNumber of LLM API calls made (4 per function)
summary.enhancement_eligibleCount 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

StatusCause
400Unsupported language or empty code input
401Missing or invalid API key
403rest_api feature not available on your tier
429Rate limit exceeded
500Analysis failed (internal error, details not exposed)

On this page