Inspiration
Millions of freelancers in Latin America work for clients abroad and get paid through PayPal. Doing the work is the easy part; getting paid is not. Invoices are tedious (usually done on a phone, in English, between other tasks), chasing late payers is awkward, and local rules are invisible to global tools. In Argentina, a monotributista who passes a yearly income cap — measured in pesos at the official exchange rate — is pushed out of the simplified tax regime, and no invoicing tool warns them.
What it does
Cobra is a chat-first collections agent on top of PayPal Invoicing:
- Bill in one sentence or one voice note, in English, Spanish or Portuguese: "Invoice Delta Studio 1,200 USD for the landing page redesign, [email protected]". Cobra turns it into an editable draft with client, email, line items, currency and due date.
- Human in the loop: nothing reaches a client until you press Create & send. Then Cobra gets the next invoice number from PayPal, creates the invoice, sends it, and gives you the payment link and a QR code.
- It chases late payers for you: ask "remind Delta Studio" and the agent writes a warm reminder in the client's language, which you can edit before PayPal sends it. With auto-reminders on, Cobra follows up overdue invoices by itself (at most every 3 days, at most 3 times).
- It knows when you get paid: PayPal webhooks (signature verified through PayPal's API) plus a sync every 10 minutes update the invoice and tell you in the chat. Paid by bank transfer? Just say so and Cobra records the payment in PayPal.
- Money questions in plain language ("who owes me money?") answered from your real data, never invented by the model.
- Local reality built in: income converted to pesos at the official and MEP rates, and a monotributo meter with the 2026 caps: how much of your category you used, when you'd hit it at your current pace, and which category you'll need.
- Cobra Insights (AG Studio): a collections dashboard over your PayPal invoices (outstanding, overdue, collected, days to get paid, who owes you, collected per month, overdue invoices) with a custom Collections scoreboard widget and an AI panel where Cobra is a custom agent: ask "who owes me?" or "chase the most overdue" and it drafts the reminder right in the panel, with a Send via PayPal button. With your own invoices, that button sends the reminder through PayPal; with the built-in sample data you can explore everything without an account. Ask for a new view ("add a bar chart of the collected amount by client") and Cobra hands the job to AG Studio's built-in agents, which add and configure the chart on the canvas.
How we built it
- PayPal Invoicing v2:
generate-next-invoice-number, create draft,send,remind,cancel, record external payment, get and list. - PayPal Webhooks: registers
INVOICING.INVOICE.*once (and moves it if the app URL changes); every delivery is checked withverify-webhook-signaturebefore it is trusted. - Llama 3.3 70B on Cloudflare Workers AI with JSON-schema-constrained output turns free text (including slang like "lucas" or "2k") into one structured action: create, remind, cancel, mark paid or query. It also writes the reminders.
- Whisper (large-v3-turbo) on Workers AI transcribes voice notes.
- Cloudflare Workers + D1 serve the app and the API, keep a local copy of invoices, chat and settings (PayPal stays the source of truth), and run a cron for sync and auto-reminders.
- AG Studio (AG Grid) for Cobra Insights:
- The starting dashboard is built with AG Studio's own AI tools (add_widget, configure_widget, add_widget_filter), so every widget is validated the same way the agents' edits are.
- A custom widget, the Collections scoreboard, built on the widget API (
getData+ display states). - Cobra's theme on the Theming API.
- The Studio Agent Framework: a custom front agent ("Cobra") with its own tools (
who_owes_me,draft_reminder, whose result renders as a reminder card with a Send via PayPal button) anddelegate_to, which hands any dashboard change to AG Studio's built-in lead agent. - An
AgLlmAdapterthat sends each turn to our Worker, which runs gpt-oss-120b on Workers AI with tool calling.
- Vanilla JS front end, strict CSP, CSRF protection, per-workspace rate limits, signed HttpOnly cookies (each browser gets its own workspace, so judges can try it without signing up).
Guardrails: the model proposes, code decides
- Every field is validated in code, and every client-facing action needs a confirmation.
- The client email must appear in the message or in a previous invoice; an email the model invents is discarded and the field is flagged for the user.
- Reminders get a fixed, accurate subject; if the model's text contradicts the facts (for example, calls an invoice "overdue" before its due date) Cobra falls back to a template.
- If the model fails or returns invalid JSON, a deterministic rule-based parser takes over, so the app keeps working.
- Money totals and answers come from the database, not from the LLM.
Challenges we ran into
- Stale permissions: after enabling Invoicing in the PayPal app, the sandbox kept returning the cached access token with the old scopes (for up to 9 hours). We detect the missing scope and request a fresh token.
- Names that disappear: PayPal drops
name.full_nameon recipients, so clients showed up as their email after a sync. Client names now go inbusiness_name, and a sync never overwrites a name with an email. - LLM honesty: in live tests the model sometimes dropped an email that was in the message, or called a not-yet-due invoice "overdue". Both are now caught by deterministic checks, covered by tests.
- Charts that landed off the canvas: AG Studio's agents assume a 24-column grid, and our dashboard had 12, so the charts they added existed in the report state but sat outside the visible canvas. The dashboard now uses the 24-column grid (it looks the same), and any new chart the agents make too small is resized once to a readable size.
- Agents in a loop: with AG Studio's agents, the open model wrote
type: "page"where the delegation schema expectstype: { id: "page" }. Studio rejected the call, the model retried 35 times and burned most of our daily free AI quota. The Worker now repairs that argument. The adapter also stops any request after 30 steps, or when the same call repeats three times.
Accomplishments that we're proud of
- A real, end-to-end flow on the PayPal sandbox: chat → draft → invoice sent → AI reminder → payment → dashboard.
- An automated live test runs after every deploy against the hosted app, with the real PayPal sandbox and Workers AI.
- 32 unit and integration tests, plus a browser walkthrough in Chromium; the whole app also runs locally with no accounts at all.
What we learned
LLMs are great at turning messy human requests into structure, but money needs hard rules around them. Keeping the human in the loop and letting code have the final word made the agent both useful and safe.
What's next
- WhatsApp channel, since freelancers already live there.
- Argentina's Factura E: pre-fill the export invoice ARCA requires for each PayPal payment.
- Country packs for Brazil (MEI) and Mexico (RESICO), and recurring invoices for retainers.
Tools used (AI)
- Llama 3.3 70B Instruct (fp8-fast) on Cloudflare Workers AI: intent and invoice extraction with JSON schema; reminder writing.
- Whisper large-v3-turbo on Cloudflare Workers AI: voice-note transcription.
- gpt-oss-120b on Cloudflare Workers AI: the agents of Cobra Insights (our Cobra agent and AG Studio's built-in lead, page and widget agents), with tool calling.
- AG Studio (AG Grid): embedded analytics dashboard, Studio Agent Framework and custom widget.
- Deepgram Aura 2 on Workers AI: narration of the demo video.
- The project was developed with the help of an AI coding assistant (Claude Code).
Built With
- ag-grid
- ag-studio
- cloudflare-d1
- cloudflare-workers
- gpt-oss
- javascript
- llama
- paypal
- paypal-invoicing-api
- paypal-webhooks
- playwright
- whisper
- workers-ai
Log in or sign up for Devpost to join the conversation.