# Exact Ledger Reconciler (`davidcondrey/wl-reconcile-ledger`) Actor

Explains settlements and payouts from ledger lines with an exact solver, not a model: subset-sum over integer minor units (meet-in-the-middle, DP, branch-and-bound) across candidate fee schedules (percentage + fixed, tiers, caps), withholding, FX rates and rounding conventions…

- **URL**: https://apify.com/davidcondrey/wl-reconcile-ledger.md
- **Developed by:** [WritersLogic](https://apify.com/davidcondrey) (community)
- **Categories:** AI, Agents, Business
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1,880.00 / 1,000 exact ledger reconciler runs

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Exact Ledger Reconciler

Explains which charges, refunds and fees make up a Stripe, PayPal or bank payout, with an exact solver instead of a model: subset-sum over integer minor units (meet-in-the-middle, DP, branch-and-bound) across candidate fee schedules (percentage + fixed, tiers, caps), withholding, FX rates and rounding conventions (half-up, half-even, truncate; per line or on the total). Paste a Stripe balance or payout-reconciliation CSV, a PayPal activity CSV or structured rows. verdict.action is RECONCILED, MATCHED_WITH_UNSETTLED_ITEMS (every payout explained, some items belong to a later payout), AMBIGUOUS (with the exact count), UNMATCHED_SETTLEMENTS (missing items, phantom payouts and the closest near-miss) or SEARCH_INCOMPLETE. Reports which rounding convention reconciles and a hash-chained audit trail. Structured input, CSV and plain one-amount-per-line statements make zero LLM calls; other free text is normalized by a fast-tier LLM whose rows must quote the source verbatim. Not accounting or tax advice.

Every result is a **signed, verifiable answer**:

- a W3C Verifiable Credential 2.0, signed with `eddsa-jcs-2022` by `did:web:agents.writerslogic.com`;
- a C2PA-style manifest that lists every source the agent read, each with its SHA-256;
- an EIP-191 co-signature over the same digest.

Change one byte and verification fails, so you can pass the result to a client, an auditor or another agent and they can check it without trusting you or us.

### How to use Exact Ledger Reconciler

1. Fill in the input form. Required fields are marked; the form opens with a working example.
2. Start the run.
3. Read the result in the **Output** tab, or download the dataset as JSON. The full signed envelope is also saved as the `OUTPUT` record in the key-value store.

### Input

| Field | Required | Description |
|---|---|---|
| `items` | no | Ledger lines. Amounts are signed (refunds and disputes negative) strings in major units, e.g. "1234.56". |
| `settlements` | no | Payouts or bank settlement totals to explain. |
| `feeSchedules` | no | Candidate fee schedules; the solver reports which one reconciles each settlement. Omit for no fees. |
| `withholdings` | no |  |
| `fxRates` | no | Direct rates only (1 from = rate to). The latest rate dated on or before the reference date applies; an undated rate is the fallback. |
| `text` | no | Messy source text for collections not given structurally. A CSV with a header (Stripe balance or payout-reconciliation export, PayPal activity export, bank statement) is parsed by code with no model, and so are headerless lines with one amount each (date, id, amount, currency, and wording that names one kind, such as Payment or Refund); anything else goes to a fast-tier LLM that must quote every row verbatim. |
| `defaultCurrency` | no | Currency for text rows that state none. |
| `crossCheck` | no | Run two independent LLM translations and keep only rows both produced (default true). |
| `conventions` | no | Restrict the conventions searched (default: all rounding modes x both scopes x both FX date policies). |
| `toleranceMinor` | no | Accepted |residual| per settlement in minor units (default 0 = exact). |
| `nearMissToleranceMinor` | no | Largest residual searched when reporting the closest near-miss for an unmatched settlement. |
| `maxLagDays` | no | An item may settle at most this many days after its date. |
| `limits` | no |  |

Example input:

```json
{
  "text": {
    "items": "id,Type,Amount,Currency,Created (UTC)\nch_1,charge,100.00,usd,2026-10-01 09:12:44\nch_2,charge,250.00,usd,2026-10-01 14:03:10\nch_3,charge,40.00,usd,2026-10-02 08:45:31\nre_1,refund,25.00,usd,2026-10-02 16:20:05",
    "settlements": "id,Amount,Currency,Arrival Date\npo_1,314.25,usd,2026-10-05"
  },
  "feeSchedules": [
    {
      "id": "stripe_us_card",
      "rules": [
        {
          "percent": "2.9",
          "fixed": "0.30"
        }
      ]
    }
  ]
}
```

### Output

```json
{
  "agent": "reconcile-ledger",
  "priceUsd": 1.88,
  "data": { "...": "the agent's answer" },
  "_provenance": { "credential": {}, "manifest": {}, "ethSignature": "0x..." }
}
```

To check a result for free, POST `{ "data": ..., "_provenance": ... }` to `https://agents.writerslogic.com/api/v1/verify-provenance`, or verify it offline against the public key in the [DID document](https://agents.writerslogic.com/.well-known/did.json).

### Pricing

**$1.88 per successful run**, charged once and only after the agent returns its answer. If the input is rejected or the agent fails, you are not charged for the call.

### Use it from code or an AI assistant

- Apify API and integrations: call this Actor from Make, Zapier, n8n, LangChain or the Apify API like any other Actor.
- MCP: `npx -y @writerslogic/ai-agents-mcp` exposes this agent and the rest of the hub as tools.
- x402: the same agent is available at `POST https://agents.writerslogic.com/api/v1/reconcile-ledger`, paid per call in USDC on Base.

### More verifiable agents

- [Medical Bill Upcoding & Overcharge Slasher](https://apify.com/davidcondrey/wl-medical-bill-auditor)
- [Dark Pattern Contract & Subscription Exit Lawyer](https://apify.com/davidcondrey/wl-contract-terminator)
- [Patent Design-Around & Freedom-to-Operate Architect](https://apify.com/davidcondrey/wl-patent-design-around)
- [Global Prior-Art Patent Invalidator](https://apify.com/davidcondrey/wl-prior-art-invalidator)
- [Abandoned Compound & Uncommercialized Trial Miner](https://apify.com/davidcondrey/wl-abandoned-compound-miner)
- [OnRecord statutory clock & redaction auditor](https://apify.com/davidcondrey/wl-audit-public-record)
- [All agents in one Actor](https://apify.com/davidcondrey/verifiable-ai-agents)

### FAQ

**Who runs this?** [WritersLogic](https://writerslogic.com/agents). The agent runs on the WritersLogic Verifiable AI Agent Hub; this Actor sends your input there and returns the signed result.

**Is my input stored?** The Actor stores your result in your own Apify storage. Ask before sending confidential documents; the hub is a third-party service from your point of view.

# Actor input Schema

## `items` (type: `array`):

Ledger lines. Amounts are signed (refunds and disputes negative) strings in major units, e.g. "1234.56".

## `settlements` (type: `array`):

Payouts or bank settlement totals to explain.

## `feeSchedules` (type: `array`):

Candidate fee schedules; the solver reports which one reconciles each settlement. Omit for no fees.

## `withholdings` (type: `array`):

withholdings

## `fxRates` (type: `array`):

Direct rates only (1 from = rate to). The latest rate dated on or before the reference date applies; an undated rate is the fallback.

## `text` (type: `object`):

Messy source text for collections not given structurally. A CSV with a header (Stripe balance or payout-reconciliation export, PayPal activity export, bank statement) is parsed by code with no model, and so are headerless lines with one amount each (date, id, amount, currency, and wording that names one kind, such as Payment or Refund); anything else goes to a fast-tier LLM that must quote every row verbatim.

## `defaultCurrency` (type: `string`):

Currency for text rows that state none.

## `crossCheck` (type: `boolean`):

Run two independent LLM translations and keep only rows both produced (default true).

## `conventions` (type: `object`):

Restrict the conventions searched (default: all rounding modes x both scopes x both FX date policies).

## `toleranceMinor` (type: `integer`):

Accepted |residual| per settlement in minor units (default 0 = exact).

## `nearMissToleranceMinor` (type: `integer`):

Largest residual searched when reporting the closest near-miss for an unmatched settlement.

## `maxLagDays` (type: `integer`):

An item may settle at most this many days after its date.

## `limits` (type: `object`):

limits

## Actor input object example

```json
{
  "feeSchedules": [
    {
      "id": "stripe_us_card",
      "rules": [
        {
          "percent": "2.9",
          "fixed": "0.30"
        }
      ]
    }
  ],
  "text": {
    "items": "id,Type,Amount,Currency,Created (UTC)\nch_1,charge,100.00,usd,2026-10-01 09:12:44\nch_2,charge,250.00,usd,2026-10-01 14:03:10\nch_3,charge,40.00,usd,2026-10-02 08:45:31\nre_1,refund,25.00,usd,2026-10-02 16:20:05",
    "settlements": "id,Amount,Currency,Arrival Date\npo_1,314.25,usd,2026-10-05"
  }
}
```

# Actor output Schema

## `results` (type: `string`):

One dataset item per call: the agent id, the price charged, the agent's result (data) and its signed provenance record (\_provenance).

## `credential` (type: `string`):

The full hub response as a W3C Verifiable Credential with a C2PA-style manifest; verify it at https://agents.writerslogic.com/api/v1/verify-provenance.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "feeSchedules": [
        {
            "id": "stripe_us_card",
            "rules": [
                {
                    "percent": "2.9",
                    "fixed": "0.30"
                }
            ]
        }
    ],
    "text": {
        "items": "id,Type,Amount,Currency,Created (UTC)\nch_1,charge,100.00,usd,2026-10-01 09:12:44\nch_2,charge,250.00,usd,2026-10-01 14:03:10\nch_3,charge,40.00,usd,2026-10-02 08:45:31\nre_1,refund,25.00,usd,2026-10-02 16:20:05",
        "settlements": "id,Amount,Currency,Arrival Date\npo_1,314.25,usd,2026-10-05"
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("davidcondrey/wl-reconcile-ledger").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "feeSchedules": [{
            "id": "stripe_us_card",
            "rules": [{
                    "percent": "2.9",
                    "fixed": "0.30",
                }],
        }],
    "text": {
        "items": """id,Type,Amount,Currency,Created (UTC)
ch_1,charge,100.00,usd,2026-10-01 09:12:44
ch_2,charge,250.00,usd,2026-10-01 14:03:10
ch_3,charge,40.00,usd,2026-10-02 08:45:31
re_1,refund,25.00,usd,2026-10-02 16:20:05""",
        "settlements": """id,Amount,Currency,Arrival Date
po_1,314.25,usd,2026-10-05""",
    },
}

# Run the Actor and wait for it to finish
run = client.actor("davidcondrey/wl-reconcile-ledger").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "feeSchedules": [
    {
      "id": "stripe_us_card",
      "rules": [
        {
          "percent": "2.9",
          "fixed": "0.30"
        }
      ]
    }
  ],
  "text": {
    "items": "id,Type,Amount,Currency,Created (UTC)\\nch_1,charge,100.00,usd,2026-10-01 09:12:44\\nch_2,charge,250.00,usd,2026-10-01 14:03:10\\nch_3,charge,40.00,usd,2026-10-02 08:45:31\\nre_1,refund,25.00,usd,2026-10-02 16:20:05",
    "settlements": "id,Amount,Currency,Arrival Date\\npo_1,314.25,usd,2026-10-05"
  }
}' |
apify call davidcondrey/wl-reconcile-ledger --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,davidcondrey/wl-reconcile-ledger"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/JUVy6TduxNUscbykw/builds/f5761ddls86CGA2hg/openapi.json
