Inspiration
Getting paid late is the most common problem freelancers have. In an Authors Guild and Freelancers Union survey, 91% of New York freelancers had been paid late at least once. A 2016 study found that 58% of freelancers feel uncomfortable chasing payment, for fear of losing the client.
It's sharper for India's estimated 15 million freelancers billing clients abroad. Off-platform, they have no marketplace escrow and no finance team, and they get paid through PayPal because their overseas clients already use it.
Existing tools don't solve it. Reminder bots escalate by days overdue, whatever the client actually said. AI agents that read replies and negotiate a fix exist, but they're priced for corporate finance teams. And nobody builds for the person who decides when money moves: the client.
Where existing approaches stop
| The usual approach | What ClearDue does instead |
|---|---|
| Reminders on a timer that get firmer with days overdue | Reads the reply first and acts on the reason: approval, cash, dispute, wrong contact or a promised date |
| An AI agent that calls payment tools directly | The AI only proposes; a deterministic mandate decides, even for PayPal's own Agent Toolkit tools |
| Tools built only for the freelancer | An assistant for the client too, answering from the agreed scope with quotes and handing anything else to the freelancer |
| Payment plans as a promise in an email | Plans executed as real PayPal invoices, designed around India's partial-payment restriction |
| Smart collections agents priced for finance teams | The same capability for one person, on the payment rail their overseas clients already use |
What it does
ClearDue is a collections agent for one person. The demo follows Aarav, a designer in India with three overseas clients.
- Diagnoses before it escalates. It reads the client's reply and names the reason (forgot, waiting on approval, short on cash, disputing the work, wrong contact, promised date, claims already paid), quoting the client's own words as evidence. Each reason gets a different action, and ambiguous replies go to the freelancer.
- Acts through PayPal within a mandate. The freelancer sets hard limits: autopilot on or off, minimum confidence, tone ceiling, quiet hours and payment-plan limits. Inside them, the agent acts with no click, for example sending a PayPal reminder to the client's accounts team and pausing the chasing. Outside them, the action waits for approval or is blocked, with the reason in plain English.
- Gives the client an assistant. Every invoice has a pay page where the client can ask "what does this line cover?". Answers cite the agreed scope word for word. A discount request, or anything it can't support with a quote, goes to the freelancer instead.
- Turns hard cases into real PayPal actions. A cash-strapped client can accept a payment plan, which ClearDue executes as separate PayPal invoices. That works for India-based freelancers, for whom PayPal's partial-payment option isn't available. Extra work outside the scope becomes a PayPal invoice line, and payments close the case through verified webhooks.
- Answers questions about your receivables. A collections analyst built in AG Studio answers "Who owes me money, and what should I do first?". It can propose actions, and they always go to Approvals.
- Guides new users. A 30-second, skippable tour highlights what matters most: the diagnosis, the mandate decision, Approvals, the client's pay page and the analyst. It's offered once per browser and can be replayed from Start here or the ? in the menu.
How we built it
The rule at the centre: the AI proposes, code decides. The model returns structured proposals; a pure TypeScript mandate engine checks each one and returns allow, needs approval or deny; only then does the PayPal layer run. The mandate engine has 100% test coverage.
PayPal
- Invoicing API v2: create, send, get, update, remind (with extra recipients for the client's accounts contact), silent cancel, delete drafts, record payment.
- PayPal Agent Toolkit: its invoice tools are adapted to the AI SDK, and each tool's execute step runs the mandate check first. The agent really calls PayPal tools, but code stays in front of the money.
- Webhooks: PAID, UPDATED, CANCELLED and REFUNDED events, each verified with verify-webhook-signature before ClearDue re-reads the invoice from PayPal. A polling sync covers missed events.
- Payment plans: drafts first, then a fresh status check, a silent cancel of the original, then send, with retry if a send fails, so the client is never left without a payable invoice.
AI
- Tasks: classifying replies, proposing actions through a tool loop, answering on the pay page, checking requests against the scope, and powering the AG Studio analyst.
- Guardrails: evidence and citations must appear word for word in their sources; low confidence goes to approval; a code rule holds any message that mentions bank details or a different way to pay; drafts can't contain placeholders or text in an unexpected script.
- Models: OpenAI gpt-5.4-mini as primary, Google Gemini 3.5 Flash-Lite as automatic failover, with a time budget per action.
- Evaluation: 30/30 on a synthetic set of client replies and 26/26 on a second set written for India's cross-border context. Both are fully passed, so they confirm the reason definitions rather than serving as a hard benchmark.
Stack: Next.js and TypeScript, Prisma with Postgres on Neon, the Vercel AI SDK and Zod, hosted on Render (web service plus a cron job). The receivables grid uses AG Grid, and the analyst is built in AG Studio with three custom widgets, a matching theme and a custom agent. 228 automated tests.
Challenges we ran into
- India's PayPal limits. Partial payments aren't available for invoicers in India, so plans became separate invoices with a careful, retry-safe order. Thanks to Nikchen (PayPal DevRel) for being there to respond into the matter immediately :)
- Wiring the Agent Toolkit into a current stack. It's built on an older AI SDK, so we adapted its tools and put the mandate check inside each one.
- Webhooks we could trust. Simulator events can't pass signature verification, so we never weakened it; we verified real sandbox events and added polling as a safety net.
- Free-tier AI limits. Quotas and "high demand" errors led to provider failover, a response cache for repeated demo inputs, and per-action time budgets.
- One demo account for every judge. We added a reset button, a daily automatic reset, and cards that say when a story has already been played.
- One demo account for every judge. We added a reset button, a daily automatic reset, cards that say when a story has already been played, and a guided tour that's offered once per browser, not once per account.
Accomplishments that we're proud of
- The whole flow runs against the real PayPal sandbox: invoices, a split payment plan, a buyer checkout, and a verified webhook marking the invoice paid within seconds.
- Our evaluation caught a real gap: a misread reply could have let autopilot agree to a bank transfer. It's now closed by a code rule, with a test.
- The client-side assistant refuses to invent discounts and escalates anything it can't back with a quote.
What we learned
- In collections, diagnosis matters more than persistence: most late payments have a fixable reason that a louder reminder doesn't touch.
- For an agent that handles money, the guardrails belong in code, not in the prompt.
- Being upfront builds trust: cached or replayed answers are labelled, and every PayPal event shows whether it was verified.
What's next for ClearDue
- Evaluation on real, anonymized client replies from freelancers.
- Forwarding from email and WhatsApp, so replies arrive without copy and paste.
- PayPal Pay Later as a plan option for freelancers in supported countries.
- Live PayPal accounts, multi-user support and an overnight sweep of overdue invoices.
Built With
- ag-grid
- ag-studio
- ai
- gemini
- llm
- neon
- next.js
- openai
- paypal
- paypal-agent-toolkit
- paypal-invoicing-api
- paypal-webhooks
- postgresql
- prisma
- react
- render
- typescript
- vercel-ai-sdk
- vitest
- zod

