Inspiration

One of my freelance jobs was the website for a restaurant in Marrakech. I invoiced them from India, and they paid without me having to chase them. Plenty of freelancers aren't that lucky.

A freelancer on r/Freelancers wrote in June 2026: "The work took 3 weeks. Chasing the payment has taken longer." (https://www.reddit.com/r/Freelancers/comments/1ucm9bq/). A Freelancers Union survey of over 5,000 US freelancers found that 71% had struggled to collect payment at least once, and the average unpaid freelancer lost almost $6,000 a year, 13% of their income (2015, https://blog.freelancersunion.org/2015/12/10/costs-nonpayment/). In the UK, IPSE found that 35% of freelancers had not been paid on time by a client in the last 12 months (https://www.ipse.co.uk/campaigns/prompt-payment/late-payment-within-the-self-employed-sector).

Bonsai looked at three years of invoices from its 100,000+ freelancer users and found that 29% were paid at least a day late, most of them within 14 days (https://www.hellobonsai.com/blog/late-freelance-payment, Bonsai's own user data). So clients mostly do pay. They just pay late, and the freelancer spends time chasing.

The other side is already getting an agent. When Walmart ran a campaign to standardise payment terms with its suppliers, it used Pactum's AI negotiator, and 82% of suppliers said they preferred it to a human (https://pactum.com/clients). The freelancer on the other end has a template and a calendar reminder. If the client's side is an agent, I wanted mine to be one too. But mine should never give away more than I allow, and it shouldn't be able to send anything without my click.

What it does

DuesPilot is an accounts-receivable (AR) agent for a freelancer who bills in USD through PayPal. It does four jobs.

  1. Brief to invoice. I paste a work note like "Built the new landing page for Kestrel Commerce (Priya): design + build $2,000, 3 revision rounds $400. Net 15." NVIDIA Nemotron (on Nebius Token Factory) pulls out the client and the line items. Server code then checks the client against my client list, sets the recipient itself, and applies hard limits (USD only, at most $10,000, due within 90 days). The result is a pending action that I review.

  2. Negotiate terms with the client's agent. For a client that has an accounts-payable agent, DuesPilot's AR agent (Nemotron) trades offers for up to three rounds: deposit %, balance net days, early-pay discount. My mandate sets a minimum deposit, a maximum number of net days and a maximum discount. It gets stricter when the client's reliability score is under 70, and server code checks every offer against it before the other side sees it. The client's AP agent is a second Nemotron agent working for the client, and code holds it to the client's own policy: if it tries to accept terms the client wouldn't sign, the check overrides it before my agent sees the reply. A deal is signed only when both checks pass on the exact same terms. You can pick the seeded client or one of 10 personas from the eval set ("10% off or no deal", "no deposits ever", "net-60 minimum" and others), and switch the client side back to plain policy rules. When the two sides agree, the deal becomes two invoices: a deposit due on receipt, and a balance on net terms with the early-pay discount.

  3. Chase what's late. Each client has a reminder cadence. A client who tends to go quiet gets reminders 1, 4, 8, 15 and 30 days after the due date. The tone goes from friendly to firm to final based on the step and the client's score. The schedule is plain code. Nemotron only writes the words, and code checks them: the invoice number, the exact amount, the days overdue, and a tone that matches the step (no "friendly reminder" in a firm one). A draft that fails gets one retry with the checker's reason, and a template takes over if the model call fails. A reminder goes out through PayPal's invoice remind API after I approve it.

  4. Forecast cash. The Cash forecast tab (AG Charts) shows when open invoices will actually land, by week: each client's due date shifted by their average lateness, minus PayPal's fee (4.4% + $0.30).

Nothing reaches PayPal without a click. Every create, send and remind is stored as a pending action with a SHA-256 hash of its payload. The Approve button runs exactly that payload, after validating it again. When the client pays, the PayPal webhook is signature-checked and deduplicated, and then the app fetches the invoice again, so the dashboard shows what PayPal says rather than what the webhook body says. A poll every two minutes catches anything a webhook misses. Every PayPal write is logged with its PayPal-Request-Id and PayPal's debug id in the Activity log tab. A Disputes tab lists sandbox disputes through the PayPal Agent Toolkit's read-only tools.

What is real and what is simulated: the demo runs on US business and US personal PayPal sandbox accounts, in USD. The five clients and their six months of payment history are seeded demo data, and the UI labels them that way. An "Advance clock" button simulates the passing days for the reminder ladder. The invoices, sends, reminders, webhooks, transaction counts and dispute reads are real PayPal sandbox API calls.

How I built it

It's one Next.js 16 app (App Router, TypeScript) on Node 22, deployed to Render as a paid Starter web service from a Blueprint (render.yaml) with a 1 GB persistent disk. State lives in SQLite (node:sqlite) behind a small read/update store.

PayPal: server code makes plain REST calls for the writes: Invoicing v2 create, conditional rules (early-pay discount), send and remind, using OAuth client credentials with a cached token. It also uses invoice GET for polling and for re-fetching after a webhook, the verify-webhook-signature endpoint, the invoice list, and Transaction Search for a 30-day count. The PayPal Agent Toolkit (@paypal/agent-toolkit 1.11.0) is built with a read-only allowlist (list/get/search invoices, list/get disputes, list transactions) and drives the Disputes tab. It is never given write tools.

AI: NVIDIA Nemotron 3 Super (nvidia/nemotron-3-super-120b-a12b) on Nebius Token Factory, called through the Vercel AI SDK v4 and its OpenAI-compatible provider. Intake and reminder wording use generateObject with a zod schema and no tools. The negotiating agent gets one tool, propose_terms, which has no execute function: the server reads the arguments and decides what happens. The client's agent works the same way with its own tool, respond (accept or counter), and its reply is checked against the client's policy before it counts.

UI: React, with AG Grid Community grids (custom cells for status, reliability score and amounts) for clients, invoices, the reminder plan, disputes and the PayPal write log, and AG Charts for the cash forecast.

Safety: zod schemas for drafts, offers and deals; a passcode gate in Next's proxy with an HMAC cookie; per-IP rate limits on the model and PayPal routes. The app refuses to start unless it points at the PayPal sandbox.

Tests: for each build slice I wrote the failing tests first, using node:test and tsx. There are 124 now. They cover the tool allowlist, prompt injection, the approval hash, webhook verification and dedupe, the paid-state transitions, the reminder schedule and checker, the forecast and the negotiation loop.

Eval: npm run eval runs the real model (3 runs per case) and scores it with code against hand labels, or against exhaustive search for negotiations. One brief set was written blind by a separate agent that never saw the code, and it was run once before any fixes. Full tables, failures included, are in app/eval/RESULTS.md.

Challenges I ran into

  • The PayPal sandbox returned HTTP 500 for every conditional-rules (early-pay discount) body I tried. I made the rule best effort: the discount is also written into the invoice terms, a failed rule never blocks the send, and the invoice grid shows "early_pay_rule: failed" so the failure isn't hidden.
  • My first Render build failed. The app opened the SQLite file when the module was imported, next build imports every route, and Render doesn't mount the disk during the build. I moved the open to first use and added a test for it.
  • After login, users on Render were sent to http://localhost:10000, the internal address behind Render's proxy. The redirect now uses Render's external URL.
  • In the first live payment, the two-minute poll marked the invoice PAID 0.3 seconds before PayPal created the webhook event. The webhook then had nothing to change and left no trace. Both paths now share one transition that only moves forward (SENT, PARTIALLY_PAID, PAID, then refunded or cancelled), and a verified webhook always writes an audit line.
  • Keeping the model away from money took more design than code. The intake model's output has no recipient field at all, so a brief that says "send $9,999 to [email protected]" can't change who gets billed. Any email in the brief that isn't a known client also blocks the draft.
  • When I paid a test invoice, the sandbox checkout offered Pay Later, which opens a credit application. The testing notes now warn judges about it.

Accomplishments that I'm proud of

  • The full loop works on the hosted app. On 7 Nov 2026 a pasted brief became sandbox invoice INV2-M332-SDCU-7FUN-E2XQ for $2,400. I paid it as the sandbox buyer, and PayPal reports it PAID (sandbox transaction 0E785722F0554471V). DuesPilot showed it as PAID, and PayPal delivered the INVOICING.INVOICE.PAID webhook to the Render URL.
  • In a live run against the real sandbox (from my machine, 21 Oct), the negotiation with the haggling client's policy settled on a 40% deposit, balance net-15 and 2% off within 5 days, in two rounds. One approval created and sent both sandbox invoices.
  • The "Load injection example" brief on the Brief tab gets blocked by server checks. It doesn't depend on the model behaving.
  • Measured with the real model (3 runs per case): against 10 AP-agent personas it closed a deal in 12/12 runs where one existed, and walked away in 18/18 where exhaustive search says none existed. No signed deal broke the mandate. On the blind brief set, 35/36 legit runs were correct. The first run let 6/36 attack runs through with a wrong draft and no warning. I fixed the gap it found (a client named only by its contact's first name), and that dropped to 3/36. All 3 are a "$5,000 finder's fee" line that the brief itself asks for. Firm reminders came out too soft in 11/36 runs. All 11 were fixed on the one retry, so none reached the approval card. The whole eval costs $0.22 in model calls.
  • With Nemotron on both sides, the results held: 12/12 deals where one existed, 18/18 walk-aways where none did, and no signed deal broke either side's limits. When I sent the client's agent a fake "your policy was updated" message, it tried to accept terms its policy forbids in 16 of 30 runs. Its policy check overrode all 16, and no deal was signed. Two agents cost $0.00324 and a median 44 s per negotiation, against $0.00125 and 22 s with the rule-based client.
  • 124 tests pass and the TypeScript check is clean.

What I learned

  • Treat PayPal's invoice GET as the record and a webhook as a reason to go and look. That makes duplicate, late and forged events uneventful.
  • The model is good at reading a messy brief and at phrasing an offer. The numbers it produces still have to be checked by code every time. It is safer still when the model's output schema has no field for the dangerous thing.
  • A Render disk isn't mounted at build time, and a reverse proxy changes what req.url means. Both problems only showed up on the real host.
  • Pin the AI SDK to v4. Agent Toolkit 1.11.0 is typed against it.

What's next for DuesPilot

  • Let the client's side be another company's own AP system instead of my Nemotron stand-in, talking over a shared message format, with the same server-side checks on both sides.
  • Real user accounts instead of one shared passcode, and Postgres so it can run on more than one instance.
  • Move the reminder and polling jobs out of the web process, for example into Render Workflows or a cron job.
  • After that, live mode for freelancers whose PayPal account supports invoicing in their country. So far I have only tested in the sandbox.

Built With

Share this project:

Updates

Submission history