Skip to content

Overview

The Genesis API provides programmatic access to Contox's AI-powered codebase analysis. Use these endpoints to start scans, monitor progress, retrieve findings, and cancel running scans.

All Genesis endpoints require authentication via HMAC-SHA256 signatures. See HMAC Signing for details.

Start a scan

Starts a new Genesis Scan for a project. The scan runs asynchronously -- use the status endpoint to poll for progress.

POST /api/v2/genesis/start

Required headers

HeaderDescription
Content-TypeMust be application/json
X-Contox-ProjectYour project ID
X-Contox-TimestampUnix timestamp used in signature
X-Contox-SignatureHMAC-SHA256 signature prefixed with sha256=

Request body

FieldTypeRequiredDescription
projectIdstringYesThe project to scan
branchstringNoGit branch to analyze. Defaults to main.
maxFilesnumberNoMaximum number of files to include. Defaults to 500. Range: 1--5000.
selectivebooleanNoOnly analyze files changed since the last scan. Defaults to false. Requires a previous completed scan.

Example request

bash
curl -X POST https://contox.dev/api/v2/genesis/start \
  -H "Content-Type: application/json" \
  -H "X-Contox-Project: proj_abc123" \
  -H "X-Contox-Timestamp: 1705312200" \
  -H "X-Contox-Signature: sha256=a1b2c3d4..." \
  -d '{
    "projectId": "proj_abc123",
    "branch": "main",
    "maxFiles": 500,
    "selective": false
  }'

Response

json
{
  "scanId": "scan_abc123def456",
  "status": "fetch_tree"
}
FieldTypeDescription
scanIdstringUnique identifier for the scan
statusstringInitial scan phase (fetch_tree)

Error responses

StatusErrorCause
400Invalid request bodyMissing or invalid fields
400No previous scan for selective modeSelective scan requested but no completed scan exists
401Invalid signatureHMAC signature verification failed
404Project not foundInvalid project ID
409Scan already in progressA scan is already running for this project
429Rate limit exceededToo many requests

Get scan status

Returns the current status of the latest scan for a project.

GET /api/v2/genesis/status?projectId=X

Query parameters

ParameterTypeRequiredDescription
projectIdstringYesThe project ID

Example request

bash
curl https://contox.dev/api/v2/genesis/status?projectId=proj_abc123 \
  -H "X-Contox-Project: proj_abc123" \
  -H "X-Contox-Timestamp: 1705312200" \
  -H "X-Contox-Signature: sha256=a1b2c3d4..."

Response

json
{
  "scan": {
    "id": "scan_abc123def456",
    "phase": "analyze",
    "progress": 0.45,
    "filesTotal": 320,
    "filesProcessed": 320,
    "chunksTotal": 87,
    "chunksProcessed": 39,
    "findingsCount": 24,
    "techStack": ["Next.js", "TypeScript", "Tailwind CSS"],
    "error": null,
    "startedAt": "2025-01-20T10:00:00Z",
    "completedAt": null
  }
}
FieldTypeDescription
idstringScan identifier
phasestringCurrent phase: fetch_tree, fetch_files, build_chunks, analyze, synthesize, security_audit, assemble, complete, or failed
progressnumberOverall progress as a float between 0.0 and 1.0
filesTotalnumberTotal number of files in the scan
filesProcessednumberNumber of files downloaded and processed
chunksTotalnumberTotal number of chunks created from files
chunksProcessednumberNumber of chunks analyzed so far
findingsCountnumberRunning count of findings extracted
techStackstring[]Technologies detected so far
errorstring | nullError message if the scan failed, otherwise null
startedAtstringISO 8601 timestamp when the scan started
completedAtstring | nullISO 8601 timestamp when the scan completed, or null if still running

Polling pattern

Poll the status endpoint to track scan progress. A recommended polling interval:

PhaseRecommended interval
fetch_tree, fetch_filesEvery 2 seconds
build_chunksEvery 2 seconds
analyzeEvery 3 seconds
synthesize, security_auditEvery 5 seconds
assembleEvery 3 seconds

Stop polling when phase is complete or failed.

typescript
async function pollScanStatus(projectId: string): Promise<void> {
  let phase = '';
  while (phase !== 'complete' && phase !== 'failed') {
    const res = await fetch(`/api/v2/genesis/status?projectId=${projectId}`);
    const { scan } = await res.json();
    phase = scan.phase;

    // Update UI with scan.progress, scan.filesProcessed, etc.
    updateProgressUI(scan);

    const interval = ['analyze'].includes(phase) ? 3000 : 2000;
    await new Promise((r) => setTimeout(r, interval));
  }
}

Get scan results

Retrieves the full findings from a completed scan.

GET /api/v2/genesis/results?projectId=X

Query parameters

ParameterTypeRequiredDescription
projectIdstringYesThe project ID

Example request

bash
curl https://contox.dev/api/v2/genesis/results?projectId=proj_abc123 \
  -H "X-Contox-Project: proj_abc123" \
  -H "X-Contox-Timestamp: 1705312200" \
  -H "X-Contox-Signature: sha256=a1b2c3d4..."

Response

json
{
  "findings": [
    {
      "id": "find_abc123",
      "layer": "architecture",
      "title": "Next.js 14 App Router with server components",
      "content": "The application uses Next.js 14 with the App Router...",
      "importance": 5,
      "files": [
        "src/app/layout.tsx",
        "src/app/dashboard/layout.tsx",
        "next.config.ts"
      ],
      "tags": ["next.js", "app-router", "server-components"],
      "createdAt": "2025-01-20T10:15:00Z"
    },
    {
      "id": "find_def456",
      "layer": "security",
      "title": "Missing rate limiting on authentication endpoints",
      "content": "The /api/auth/login and /api/auth/register endpoints...",
      "importance": 4,
      "files": [
        "src/app/api/auth/login/route.ts",
        "src/app/api/auth/register/route.ts"
      ],
      "tags": ["owasp", "rate-limiting", "authentication"],
      "createdAt": "2025-01-20T10:15:00Z"
    }
  ],
  "techStack": [
    { "name": "Next.js", "version": "14.2.0", "category": "framework" },
    { "name": "TypeScript", "version": "5.3.0", "category": "language" },
    { "name": "Tailwind CSS", "version": "4.0.0", "category": "styling" },
    { "name": "Appwrite", "version": "16.0.0", "category": "backend" }
  ],
  "summary": {
    "totalFindings": 47,
    "byLayer": {
      "product": 8,
      "architecture": 7,
      "dependencies": 6,
      "conventions": 9,
      "dataModel": 5,
      "entryPoints": 8,
      "security": 4
    },
    "scanDuration": 142,
    "filesAnalyzed": 320,
    "chunksAnalyzed": 87
  }
}

Finding object

FieldTypeDescription
idstringUnique finding identifier
layerstringAnalysis layer: product, architecture, dependencies, conventions, dataModel, entryPoints, security
titlestringConcise summary of the finding
contentstringFull finding details in markdown
importancenumberSignificance score from 1 (low) to 5 (critical)
filesstring[]Source file paths that contributed to this finding
tagsstring[]Categorization tags
createdAtstringISO 8601 timestamp

Tech stack object

FieldTypeDescription
namestringTechnology name
versionstringDetected version
categorystringClassification: framework, language, styling, backend, database, testing, tooling

Summary object

FieldTypeDescription
totalFindingsnumberTotal number of findings across all layers
byLayerobjectFinding count per analysis layer
scanDurationnumberTotal scan time in seconds
filesAnalyzednumberNumber of files processed
chunksAnalyzednumberNumber of chunks processed

Cancel a scan

Cancels a running scan. The current phase completes before the scan stops. Findings extracted up to the cancellation point are preserved.

POST /api/v2/genesis/cancel

Request body

FieldTypeRequiredDescription
projectIdstringYesThe project to cancel the scan for

Example request

bash
curl -X POST https://contox.dev/api/v2/genesis/cancel \
  -H "Content-Type: application/json" \
  -H "X-Contox-Project: proj_abc123" \
  -H "X-Contox-Timestamp: 1705312200" \
  -H "X-Contox-Signature: sha256=a1b2c3d4..." \
  -d '{
    "projectId": "proj_abc123"
  }'

Response

json
{
  "scanId": "scan_abc123def456",
  "status": "cancelled",
  "findingsPreserved": 24
}
FieldTypeDescription
scanIdstringThe cancelled scan's identifier
statusstringAlways cancelled
findingsPreservednumberNumber of findings preserved from the partial scan

Error responses

StatusErrorCause
400No scan in progressNo active scan exists for this project
401Invalid signatureHMAC signature verification failed
404Project not foundInvalid project ID

Next steps