> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sahlfinancial.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Scoring by API

> Read a case's score, run the scoring again, and simulate another loan or policy without saving anything.

Sahl scores a case deterministically from what was read on its documents: individuals on the retail blocks (`retail_v1`), companies on the SME model (`sme_v1`) under your `kyb` policy. The same file under the same policy always gives the same score and the same `inputs_hash`. A block nothing on file feeds is `non calculé` (not computed), never a zero.

These routes find a case by **your `reference`**, in the call's environment (`X-Sahl-Environment` or `?environment=`, `sandbox` by default), in your workspace only. An unknown reference answers 404 `not_found`.

| Endpoint | Scope | Does |
| - | - | - |
| `GET /v1/partner/scoring/{reference}` | `scoring:read` | The score stored on the case. |
| `POST /v1/partner/scoring/{reference}/rescore` | `scoring:write` | Runs the scoring again and stores the result. |
| `POST /v1/partner/scoring/what-if` | `scoring:read` | The score the case would get with other inputs. Stores nothing. |

Production calls need your workspace to be approved for Production API calls (see [Go live](https://docs.sahlfinancial.com/go-live.md#partner-document-apis)). Each key is limited to 60 calls a minute on these routes.

## Get the score

```bash cURL theme={"dark"}
curl https://app.sahlfinancial.com/api/v1/partner/scoring/client-42 \
  -H "Authorization: Bearer $SAHL_API_KEY"
```

```javascript JavaScript theme={"dark"}
const res = await fetch("https://app.sahlfinancial.com/api/v1/partner/scoring/client-42", {
  headers: { Authorization: `Bearer ${process.env.SAHL_API_KEY}` },
});
const score = await res.json();
console.log(score.score, score.risk_level, score.coverage);
```

```python Python theme={"dark"}
import os, requests

score = requests.get(
    "https://app.sahlfinancial.com/api/v1/partner/scoring/client-42",
    headers={"Authorization": f"Bearer {os.environ['SAHL_API_KEY']}"},
).json()
print(score["score"], score["risk_level"], score["coverage"])
```

```json theme={"dark"}
{
  "reference": "client-42",
  "case_id": "a1b2c3d4-0000-4000-8000-000000000002",
  "environment": "sandbox",
  "scored": true,
  "subject_kind": "company",
  "model": "sme_v1",
  "score": 612,
  "max_score": 1000,
  "risk_level": "medium",
  "coverage": 0.78,
  "missing_documents": ["Attestation de régularité fiscale"],
  "blocks": [
    {
      "key": "repayment_capacity",
      "label_fr": "Capacité de remboursement",
      "label_en": "Repayment capacity",
      "points": 140,
      "max": 250,
      "computed": true,
      "status": "calculé",
      "provisional": false,
      "notes": null
    }
  ],
  "fraud_penalty": null,
  "summary": null,
  "sme": null,
  "project_review": null
}
```

| Field | Meaning |
| - | - |
| `scored` | `false` until the case has been scored once. |
| `score`, `max_score` | The score, 0 to 1000 (`max_score` is always 1000). `null` when the file is not assessable. |
| `risk_level` | `low`, `medium`, `high`, or `not_assessable` until the file holds enough to grade. |
| `coverage` | The share (0 to 1) of the model's weight the file could feed. |
| `blocks[]` | In model order: `points` out of `max` (the policy weight, on the 1000 scale), `computed`, and `status` `calculé` or `non calculé` (missing data). `points` is `null` for a block not computed. `provisional` is true while a field it reads awaits review (identity only). `notes` (French) says how points were reached or what is missing. |
| `missing_documents` | Documents that would make the `non calculé` blocks computable (French labels). |
| `fraud_penalty` | Points removed for fraud signals (0 or negative). Individuals only. |
| `summary` | The engine's one-paragraph reading, in French. |
| `sme` | For a company, the full SME model output: factors, gates and thresholds. |
| `project_review` | A crowdfunding project's review, when the case is one. |

A score is a reading of documents, not a decision. See [Scoring](https://docs.sahlfinancial.com/guides/scoring.md) for how the console uses it.

## Re-score

```bash theme={"dark"}
curl -X POST https://app.sahlfinancial.com/api/v1/partner/scoring/client-42/rescore \
  -H "Authorization: Bearer $SAHL_API_KEY"
```

The engine runs again on the case's stored extractions and the active policy, stores the result and returns it. It never reads the documents again. The answer is the same object as above plus:

| Field | Meaning |
| - | - |
| `inputs_hash` | SHA-256 of everything the score was computed from. Equal hashes, equal scores. |
| `normalized_score` | The score renormalised over the computed blocks (individuals). |
| `decision_score` | The score a decision is taken on. `null` until income evidence is on file. |
| `status` | The case's status after the re-score. |

A re-score does not decide. A case a person approved or refused keeps its status, and an approval the new score no longer supports goes back to manual review. It fires the `case.scored` webhook and is written to the audit log (with the inputs hash, never values). A case that cannot be scored yet answers 422 `not_scorable`.

## What-if

`POST /v1/partner/scoring/what-if` runs the real engine with your overrides inside a transaction that is always rolled back: the case, the policy and the audit log are left as they were.

| Field | Rules |
| - | - |
| `reference` | Required. 1 to 64 characters. |
| `environment` | Optional. Must agree with `X-Sahl-Environment` if both are sent. |
| `inputs` | Required object, all optional: `requested_amount` (up to 10,000,000,000), `duration_months` (1 to 360), `monthly_payment` (0 to 1,000,000,000), `annual_rate_pct` (0 to 40). |
| `weights` | Optional map of factor key to weight (at least 0). Merged over the active policy's weights and renormalised. At least one weight must be positive (else 422 `invalid_weights`). |
| `approve_threshold`, `refuse_threshold` | Optional, 0 to 1000. Approve at or above, refuse at or below. `refuse_threshold` must not exceed `approve_threshold` (else 422 `invalid_thresholds`). |

```bash cURL theme={"dark"}
curl -X POST https://app.sahlfinancial.com/api/v1/partner/scoring/what-if \
  -H "Authorization: Bearer $SAHL_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "reference": "client-42",
    "inputs": {"requested_amount": 250000, "duration_months": 36, "annual_rate_pct": 7.5},
    "approve_threshold": 650
  }'
```

```javascript JavaScript theme={"dark"}
const res = await fetch("https://app.sahlfinancial.com/api/v1/partner/scoring/what-if", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SAHL_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    reference: "client-42",
    inputs: { requested_amount: 250000, duration_months: 36, annual_rate_pct: 7.5 },
    approve_threshold: 650,
  }),
});
const result = await res.json();
```

```python Python theme={"dark"}
import os, requests

result = requests.post(
    "https://app.sahlfinancial.com/api/v1/partner/scoring/what-if",
    headers={"Authorization": f"Bearer {os.environ['SAHL_API_KEY']}"},
    json={
        "reference": "client-42",
        "inputs": {"requested_amount": 250000, "duration_months": 36, "annual_rate_pct": 7.5},
        "approve_threshold": 650,
    },
).json()
```

```json theme={"dark"}
{
  "persisted": false,
  "current": {"score": 612, "risk_level": "medium", "decision": null},
  "hypothetical": {"reference": "client-42", "scored": true, "score": 598, "risk_level": "medium", "blocks": ["..."]},
  "decision": "manual_review",
  "applied": {
    "policy_path": "kyb",
    "weights": {"...": 0.0},
    "approve_threshold": 650,
    "refuse_threshold": 500,
    "inputs": {"requested_amount": 250000, "duration_months": 36, "annual_rate_pct": 7.5}
  }
}
```

`persisted` is always `false`. `current` is the case as stored; `hypothetical` has the same shape as the score above; `decision` is what the automatic decision would be (`approved`, `manual_review`, `refused`, or `null` when not assessable); `applied` lists the settings the hypothetical score ran under (`policy_path` is `kyc` or `kyb`).

## Errors

| Status | `detail.code` | Cause |
| - | - | - |
| 404 | `not_found` | No case with this reference in this environment. |
| 422 | `invalid_weights`, `invalid_thresholds`, `not_scorable` | Bad what-if input, or a case that cannot be scored yet. |
| 403 | `production_api_not_approved` and the other Production gates | See [Go live](https://docs.sahlfinancial.com/go-live.md#partner-document-apis). |
| 403 | `insufficient_scope` | Missing `scoring:read` or `scoring:write`. |
| 429 | `rate_limit_exceeded` | More than 60 calls a minute with one key. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.