AI Agents

Mercoa currently offers AI agent support for accounts receivable with our Invoicing Agent, MAi. MAi can:

  • Read and understand complex B2B contracts
  • Contact customers to collect overdue payments
  • Contact vendors to send upcoming invoices on time
  • Edit invoices and billing schedules with natural language

To make our agentic workflows fully embeddable, we expose API endpoints you can use to control and respond to these behaviors from within your platform.

Contract Understanding

MAi actions upon B2B contracts by breaking each contract down into contract details and payment schedules.

To start using MAi, you can pass a contract PDF to our Generate Contract endpoint as a Base64 encoded string:

POST
1curl -X POST https://api.mercoa.com/contract/generate \
2 -H "Authorization: Bearer <token>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "document": "data:application/pdf;base64,JVBERi0xLjEKJcKlwrHDqwoKMSAwIG9iagogIDw8IC9UeXBlIC9DYXRhbG9nCiAgICAgL1BhZ2VzIDIgMCBSCiAgPj4KZW5kb2JqCgoyIDAgb2JqCiAgPDwgL1R5cGUgL1BhZ2VzCiAgICAgL0tpZHMgWzMgMCBSXQogICAgIC9Db3VudCAxCiAgICAgL01lZGlhQm94IFswIDAgMzAwIDE0NF0KICA+PgplbmRvYmoKCjMgMCBvYmoKICA8PCAgL1R5cGUgL1BhZ2UKICAgICAgL1BhcmVudCAyIDAgUgogICAgICAvUmVzb3VyY2VzCiAgICAgICA8PCAvRm9udAogICAgICAgICAgIDw8IC9GMQogICAgICAgICAgICAgICA8PCAvVHlwZSAvRm9udAogICAgICAgICAgICAgICAgICAvU3VidHlwZSAvVHlwZTEKICAgICAgICAgICAgICAgICAgL0Jhc2VGb250IC9UaW1lcy1Sb21hbgogICAgICAgICAgICAgICA+PgogICAgICAgICAgID4+CiAgICAgICA+PgogICAgICAvQ29udGVudHMgNCAwIFIKICA+PgplbmRvYmoKCjQgMCBvYmoKICA8PCAvTGVuZ3RoIDU1ID4+CnN0cmVhbQogIEJUCiAgICAvRjEgMTggVGYKICAgIDAgMCBUZAogICAgKEhlbGxvIFdvcmxkKSBUagogIEVUCmVuZHN0cmVhbQplbmRvYmoKCnhyZWYKMCA1CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAxOCAwMDAwMCBuIAowMDAwMDAwMDc3IDAwMDAwIG4gCjAwMDAwMDAxNzggMDAwMDAgbiAKMDAwMDAwMDQ1NyAwMDAwMCBuIAp0cmFpbGVyCiAgPDwgIC9Sb290IDEgMCBSCiAgICAgIC9TaXplIDUKICA+PgpzdGFydHhyZWYKNTY1CiUlRU9GCg==",
6 "creatorEntityId": "ent_8545a84e-a45f-41bf-bdf1-33b42a55812c"
7}'

MAi will respond with a Contract object with the following structure:

Contract Object

FieldDescription
summaryA natural language summary of the contract details
recurrencesA list of ContractRecurrence objects

ContractRecurrence Object

FieldDescription
rruleA string representation of this recurrence rule (as defined by RFC 5545). Note that the DTSTART must be set in this string along with the RRULE fields.

Example: DTSTART:20250201T000000ZRRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=1
justificationA natural language justification for this recurrence
filteredContractSummaryA natural language summary of the contract details, filtered to only include information relevant to this recurrence
invoiceSchemaA schema for all invoices that will be created by this recurrence

You can also create or update a Contract directly via our CRUD endpoints.

PUT
1curl -X PUT https://api.mercoa.com/contract/cnt_3bd62b69-3835-433e-829f-4388a2e46c41 \
2 -H "Authorization: Bearer <token>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "summary": "Contract Start Date: January 29, 2025\nParties to the Agreement:\n- Provider (Vendor): [Vendor Name] - Client (Payer): [Client Name]\nFees and Payment Terms:\n- Monthly Recurring Fee: \\$20.00 - Payment Schedule: Fees are payable in advance on the 1st day of each month. - First Payment Date: February 1, 2025 - Payment Method: Via credit card to the account designated by Provider. - Payment Due Date: Payment is due 5 days after the invoice date.\n",
6 "recurrences": [
7 {
8 "rrule": "DTSTART:20250201T000000ZRRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=1",
9 "justification": "Monthly recurring fee billed in advance on the 1st of each month",
10 "filteredContractSummary": "Contract Start Date: January 29, 2025\nParties to the Agreement:\n- Provider (Vendor): [Vendor Name] - Client (Payer): [Client Name]\nFees and Payment Terms:\n- Monthly Recurring Fee: \\$20.00 - Payment Schedule: Fees are payable in advance on the 1st day of each month. - First Payment Date: February 1, 2025 - Payment Method: Via credit card to the account designated by Provider. - Payment Due Date: Payment is due 5 days after the invoice date.\n",
11 "invoiceSchema": {
12 "lineItems": [
13 {
14 "name": "Monthly Subscription Service Fee",
15 "unitPrice": 20,
16 "currency": "USD",
17 "quantity": 1
18 }
19 ]
20 }
21 }
22 ]
23}'

Automated Invoice Creation + Payment Collection

Once contracts have been set up, MAi automatically creates a draft Mercoa Invoice a week before the invoice should be sent out. You can then edit the created invoice using natural language, and send the invoice out for payment using Mercoa’s Invoice API endpoints or the accounts receivable UI components.

MAi will then continue to monitor the invoice until it is paid, and will automatically send collection emails to the customer if the invoice is overdue.

Natural Language Editing

MAi also supports editing contracts and invoices with natural language.

Contract Editing

Let’s say a user provides a sentence describing a change they would like to make to the Contract MAi initially generated. You can accomplish this with one API call to the Apply Contract Feedback endpoint:

POST
1curl -X POST https://api.mercoa.com/contract/cnt_3bd62b69-3835-433e-829f-4388a2e46c41/apply-contract-feedback \
2 -H "Authorization: Bearer <token>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "feedback": "Change the monthly fee to $20.00"
6}'

Invoice Editing

When MAi doesn’t have all the information it needs (e.g. how many units were sold this month), it may create an incomplete or incorrect Invoice object. When this happens, you can complete the Invoice object with the Apply Invoice Feedback endpoint:

POST
1curl -X POST https://api.mercoa.com/contract/cnt_3bd62b69-3835-433e-829f-4388a2e46c41/apply-invoice-feedback \
2 -H "Authorization: Bearer <token>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "feedback": "There were 2 subscriptions this month",
6 "invoiceId": "in_26e7b5d3-a739-4b23-9ad9-6aaa085f47a9"
7}'