AFAdocs
REST API

POST /v1/enhance

Generate an enhancement candidate and validate it through nine quantitative gates.

POST /v1/enhance

Generate an enhancement candidate for the provided code and run it through all nine quantitative gates.

Requires the rest_api feature (Developer tier and above).

Request

POST /v1/enhance
Authorization: Bearer uk_afa_...
Content-Type: application/json

Body

FieldTypeRequiredDefaultDescription
codestringYes--Source code to enhance (max 500KB)
languagestringNo"python"Language: python, typescript, go, java, rust
dry_runbooleanNotrueIf true, evaluate but don't commit
{
  "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",
  "dry_run": true
}

Response

{
  "status": "pass",
  "candidate": {
    "enhanced_code": "def process_data(items: list[int]) -> list[int]:\n    \"\"\"Filter positive items and double them.\"\"\"\n    return [item * 2 for item in items if item > 0]",
    "explanation": "Replaced explicit loop with list comprehension, added type hints and docstring",
    "diff": "..."
  },
  "gate_results": {
    "overall": "PASS",
    "gates": {
      "complexity": {"status": "PASS", "score": 0.85},
      "risk": {"status": "PASS", "score": 0.92},
      "profit": {"status": "PASS", "score": 0.88},
      "novelty": {"status": "PASS", "score": 0.81},
      "quality": {"status": "PASS", "score": 0.78},
      "utility": {"status": "PASS", "score": 2.3},
      "entropy": {"status": "PASS", "score": 0.45},
      "supply_chain": {"status": "PASS"},
      "kpi": {"status": "PASS", "score": 0.72}
    },
    "recommendation": "Enhancement improves maintainability and documentation with minimal complexity increase"
  },
  "dry_run": true
}

Status values

StatusMeaning
passAll gates passed -- enhancement is valid
failOne or more gates failed
skippedNo viable candidate could be generated
completedProcessing finished (check gate_results for details)

Examples

curl

curl -X POST https://api.afa.undercurrentholdings.com/v1/enhance \
  -H "Authorization: Bearer uk_afa_..." \
  -H "Content-Type: application/json" \
  -d '{
    "code": "def add(a, b):\n    return a + b",
    "language": "python",
    "dry_run": true
  }'

Python (httpx)

import httpx

response = httpx.post(
    "https://api.afa.undercurrentholdings.com/v1/enhance",
    headers={"Authorization": "Bearer uk_afa_..."},
    json={
        "code": "def add(a, b):\n    return a + b",
        "language": "python",
        "dry_run": True,
    },
)

data = response.json()
print(f"Status: {data['status']}")

if data.get("gate_results"):
    print(f"Overall: {data['gate_results']['overall']}")

if data.get("candidate"):
    print(f"Enhanced:\n{data['candidate']['enhanced_code']}")

Errors

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

On this page