Functions

Function Review

Analyzes function performance and estimate human review requirements. Calculates sample sizes needed to achieve target accuracy with statistical confidence, finds optimal confidence thresholds within a configurable range, and estimates review effort. Supports custom threshold ranges for focused analysis (e.g., analyze only 0.7-0.9 range).

POST
/v2/functions/review
x-api-key<token>

Authenticate using API Key in request header

In: header

functionNamestring

Name of the function to analyze

evaluationVersion?string

Optional evaluation version to filter evaluations by. Must be one of the supported versions. If not provided, defaults to "0.1.0-gemini".

Default"0.1.0-gemini"
Value in"0.1.0-gemini"
marginOfError?number

Margin of error for statistical calculations

Default0.05
Formatfloat
Range0.001 <= value <= 0.1
thresholdMin?number

Minimum confidence threshold to analyze

Default0.5
Formatfloat
Range0 <= value <= 1
thresholdMax?number

Maximum confidence threshold to analyze

Default1
Formatfloat
Range0 <= value <= 1
thresholdStep?number

Step size for threshold analysis (smaller = more granular)

Default0.01
Formatfloat
Range0.001 <= value <= 0.1
confidenceLevels?array<integer>

Confidence levels for statistical analysis as integers representing percentages (e.g., [90, 95, 99] for 90%, 95%, 99%). IMPORTANT: Only integers are accepted, floats like 0.95 will be rejected.

Default[95]

Response Body

curl -X POST "https://api.bem.ai/v2/functions/review" \
  -H "Content-Type: application/json" \
  -d '{
    "functionName": "invoice-transformer",
    "marginOfError": 0.05,
    "thresholdMin": 0.5,
    "thresholdMax": 1,
    "thresholdStep": 0.01
  }'
{
  "status": "success",
  "functionName": "invoice-transformer",
  "estimate": {
    "totalTransformations": 1000,
    "labeledTransformations": 200,
    "unlabeledTransformations": 800,
    "missingEvaluations": 50,
    "confidenceDistribution": {
      "high": 500,
      "medium": 350,
      "low": 150
    },
    "fieldMetrics": [
      {
        "fieldPath": "/companyName",
        "metrics": {
          "accuracy": 0.85,
          "precision": 0.88,
          "recall": 0.85,
          "f1Score": 0.865,
          "tp": 85,
          "fp": 0,
          "tn": 0,
          "fn": 15
        }
      }
    ],
    "precisionRecallAuc": 0.8542,
    "thresholdMatrix": [
      {
        "threshold": 0.8,
        "accuracyAboveThreshold": {
          "95": {
            "ciLower": 0.8456,
            "mid": 0.875,
            "ciUpper": 0.9044,
            "currentSample": 120,
            "sampleNeeded": 30
          }
        },
        "precision": {
          "90": {
            "ciLower": 0.8837,
            "mid": 0.9041,
            "ciUpper": 0.9244,
            "currentSample": 344,
            "sampleNeeded": 30
          },
          "95": {
            "ciLower": 0.8765,
            "mid": 0.9041,
            "ciUpper": 0.9317,
            "currentSample": 344,
            "sampleNeeded": 30
          }
        },
        "recall": {
          "90": {
            "ciLower": 0.7234,
            "mid": 0.7568,
            "ciUpper": 0.7902,
            "currentSample": 312,
            "sampleNeeded": 30
          }
        },
        "falsePositiveRate": {
          "95": {
            "ciLower": 0.0234,
            "mid": 0.0345,
            "ciUpper": 0.0456,
            "currentSample": 200,
            "sampleNeeded": 30
          }
        },
        "falseDiscoveryRate": {
          "95": {
            "ciLower": 0.0567,
            "mid": 0.075,
            "ciUpper": 0.0933,
            "currentSample": 132,
            "sampleNeeded": 30
          }
        },
        "tp": 85,
        "fp": 12,
        "fn": 15,
        "tn": 88
      }
    ]
  }
}
{
  "message": "invalid request body: missing required field 'transformationIDs'",
  "code": 400,
  "details": {
    "field": "transformationIDs",
    "reason": "required field missing"
  }
}
{
  "message": "invalid request body: missing required field 'transformationIDs'",
  "code": 400,
  "details": {
    "field": "transformationIDs",
    "reason": "required field missing"
  }
}