Getting Started
API Quickstart
Get an API key, install the Python SDK, and run your first analysis in under a minute.
API Quickstart
Set up programmatic access to AFA using the Python SDK or raw HTTP calls.
1. Get your API key
Sign up at portal.undercurrentholdings.com, navigate to AFA > Keys, and create a key. It looks like uk_afa_....
Set it as an environment variable:
export AFA_API_KEY="uk_afa_..."2. Install the SDK
pip install afa-clientThe SDK has one dependency (httpx) and supports Python 3.9+.
3. Analyze code
from afa_client import AFA
client = AFA() # reads AFA_API_KEY from environment
result = client.analyze(
code="""
def process_payment(amount, currency):
total = amount * 1.1
print("Processing " + str(total))
return total
""",
language="python",
)
for fn in result.results:
print(f"Scores: {fn['scores']}")
for finding in fn["findings"]:
print(f" [{finding['severity']}] {finding['message']}")4. Generate an enhancement
enhanced = client.enhance(
code="def add(a, b):\n return a + b",
language="python",
dry_run=True, # evaluate without committing
)
print(enhanced.status) # "pass" if all 9 gates passed
if enhanced.candidate:
print(enhanced.candidate["enhanced_code"])5. Check gate results directly
result = client.gate_check(
metrics={
"baseline_risk": 0.08,
"proposed_risk": 0.02,
"complexity_score": 0.75,
"quality_score": 0.82,
"quality_subscores": [0.85, 0.80, 0.75, 0.90],
"new_concepts": 4,
"entropy_score": 0.45,
"utility_lcb": 3.2,
"business_kpi_impact": 0.72,
"slsa_verified": True,
}
)
print(result.overall) # "PASS" or "FAIL"Using curl instead
If you prefer raw HTTP:
curl -X POST https://api.afa.undercurrentholdings.com/v1/analyze \
-H "Authorization: Bearer $AFA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"code": "def hello(name):\n print(\"Hello \" + name)",
"language": "python"
}'Async support
The SDK provides an async client for use with FastAPI, asyncio, or other async frameworks:
from afa_client import AsyncAFA
async with AsyncAFA() as client:
result = await client.analyze(code="def foo(): pass")Error handling
from afa_client import AFA, RateLimitError, AuthenticationError
client = AFA()
try:
result = client.analyze(code="def foo(): pass")
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after}s")
except AuthenticationError:
print("Invalid API key")Next steps
- Full API reference with all endpoints and response schemas
- Authentication details including rate limits and feature gating
- Nine gates explained with thresholds and formulas
- Billing and tiers for quota details