Skip to content
developer · developer · research · code · metrics · complexity · maintainability · static-analysis · python · ast

Code metrics

Measure caller-supplied source code with Python AST analysis or a deterministic lexical fallback, including per-function complexity, a SHA-256 fingerprint, density ratios, syntax status, and actionable maintainability signals without retaining or forwarding the code.

$0.025 USDCBase + Solanax402 v2POSTCustomer-evidenced
Run one free live analysisPay $0.025 USDC and run in your browserView free result sample

Endpoint

https://apiacre.com/v1/developer/code-metrics

Send the JSON body below. An unpaid request returns HTTP 402 with a PAYMENT-REQUIRED header; an x402-compatible buyer signs the requirement and retries with PAYMENT-SIGNATURE.

Pay $0.025 USDC and run in your browser

Official Coinbase agent path

Coinbase Agentic Wallet can satisfy this x402 request in one command. Running it may pay automatically, so --max-amount is fixed to $0.025 USDC in atomic units. Copying the command does not install, authenticate, sign, or pay; review the request and use a separate low-value wallet before running it.

npx --yes awal@latest x402 pay https://apiacre.com/v1/developer/code-metrics \
  -X POST \
  -d '{"code":"def greet(name):\n    return f'"'"'Hello {name}'"'"'","language":"python"}' \
  --max-amount 25000 \
  --json

Coinbase pay-for-service documentation · Buyer setup and wallet safety

Alternative third-party AgentCash commands

Run check first without payment. Its fetch command may automatically pay up to the exact listed price.

npx --yes agentcash@latest check https://apiacre.com/v1/developer/code-metrics
npx --yes agentcash@latest fetch https://apiacre.com/v1/developer/code-metrics \
  --method POST \
  --header 'content-type: application/json' \
  --body '{"code":"def greet(name):\n    return f'"'"'Hello {name}'"'"'","language":"python"}' \
  --payment-protocol x402 \
  --payment-network base \
  --max-amount 0.025

AgentCash CLI documentation

Input example

{
  "code": "def greet(name):\n    return f'Hello {name}'",
  "language": "python"
}

Response shape

View free static sample JSON

{
  "request_id": "018f1f54-7f38-7ba2-8dc3-5f90272d9f1a",
  "service": "developer.code-metrics",
  "version": "1",
  "data": {
    "language": "python",
    "source": {
      "sha256": "d588756864c1c6b9016a1829ea9283915950ef23e5b1c04018413ed71456a34e",
      "characters": 43,
      "utf8Bytes": 43
    },
    "lines": {
      "total": 2,
      "code": 2,
      "comments": 0,
      "blank": 0
    },
    "classes": 0,
    "functions": 1,
    "branchPoints": 0,
    "estimatedCyclomaticComplexity": 1,
    "complexityPerFunction": 1.0,
    "maximumFunctionComplexity": 1,
    "functionMetrics": [
      {
        "name": "greet",
        "kind": "function",
        "line": 1,
        "endLine": 2,
        "lines": 2,
        "parameters": 1,
        "branchPoints": 0,
        "estimatedCyclomaticComplexity": 1
      }
    ],
    "functionsTruncated": false,
    "syntax": {
      "engine": "python-ast",
      "valid": true,
      "error": null
    },
    "maximumLineLength": 26,
    "averageLineLength": 21.0,
    "commentDensity": 0.0,
    "blankLineDensity": 0.0,
    "longLineCount": 0,
    "workMarkerCount": 0,
    "maintainabilitySignal": 95,
    "reviewSignals": [],
    "analysis": {
      "version": "apiacre-code-metrics/3",
      "method": "Python AST with deterministic lexical metrics",
      "limitations": [
        "AST complexity is a static heuristic, not a runtime or control-flow proof.",
        "Comment counts include comment-only lines, not inline comments or block-comment spans."
      ]
    }
  },
  "meta": {
    "duration_ms": 42,
    "cached": false,
    "sources": [],
    "warnings": [],
    "next_actions": [
      {
        "service": "developer.code-change-review",
        "title": "Code change review",
        "reason": "Compare the measured source with a caller-supplied baseline and surface syntax, complexity, function, and maintainability regressions.",
        "method": "POST",
        "path": "/v1/developer/code-change-review",
        "price": "$0.05",
        "input_template": {
          "before": "$baselineSourceCode",
          "after": "$request.code",
          "language": "$request.language",
          "filename": "$filename"
        },
        "use_output": "Inspect result.data.reviewDecision, findings, and functionChanges before approving the change.",
        "handoff_path": "/catalog/developer.code-change-review",
        "checkout_path": "/try/developer.code-change-review",
        "sample_path": "/samples/developer.code-change-review",
        "maximum_atomic_usdc": "50000",
        "handoff_payment_required": false,
        "executes_automatically": false,
        "authorization_required": true
      },
      {
        "service": "data.schema",
        "title": "JSON Schema generator",
        "reason": "Create a reusable validation contract for code-quality metric snapshots.",
        "method": "POST",
        "path": "/v1/data/schema",
        "price": "$0.025",
        "input_template": {
          "content": "$json([$result.data])",
          "format": "json"
        },
        "use_output": "Use result.data.schema to validate future metric snapshots.",
        "handoff_path": "/catalog/data.schema",
        "checkout_path": "/try/data.schema",
        "sample_path": "/samples/data.schema",
        "maximum_atomic_usdc": "25000",
        "handoff_payment_required": false,
        "executes_automatically": false,
        "authorization_required": true
      }
    ]
  }
}

Complete recipes using this API

These buyer-controlled recipes connect this service to compatible API Acre results. Every step has its own exact price and requires separate authorization.

Continue this workflow

These optional follow-ups use this result in a larger workflow. Each call shows a fresh x402 challenge and requires separate buyer authorization.

Try the payment challenge

curl -i -X POST 'https://apiacre.com/v1/developer/code-metrics' \
  -H 'content-type: application/json' \
  --data '{"code":"def greet(name):\n    return f'Hello {name}'","language":"python"}'