POST /v1/agent/ap.
This guide walks through the same bill flow as the AP Quick Start, but driven through the agent after the initial upload.
Prerequisites
- A Dolfin API key
- An organisation already provisioned (see Client Integration)
- A valid session token or API key for authentication
- A bill PDF or image file to upload
All requests below require the
x-dolfin-api-key and x-dolfin-organisation-id headers. See Authentication for details.How the Agent Works
Every agent turn is a single POST to/agent/ap with just two body fields:
You do not send the full message history — Dolfin persists the conversation server-side and the agent loads it automatically from
conversationId.
Response format
The response is atext/event-stream (SSE). Read events as they arrive:
On error, the final frame is
{ "error": "message", "done": true }.
Persisting conversationId
On the first request, read the conversation SSE event and save its data.id. Echo that UUID back as conversationId on every follow-up POST to continue the same conversation. See the AR Agent guide for an SSE parser example.
Once the first response returns a
conversationId, the agent type is frozen on that conversation. Sending a request to POST /v1/agent/ar with an AP conversation’s conversationId (or vice versa) returns 409 Conflict.Conversation scoping
Conversations are scoped by:- Organisation — always. A conversation belongs to the organisation in
x-dolfin-organisation-idand can’t be read or continued from another organisation. - User — only when the call is authenticated with a Bearer JWT. API-key calls have no user binding, so any caller with the same API key and organisation can continue an API-key conversation.
Overview
1
Upload the bill (direct API)
Bill uploads are multipart file transfers, so Step 1 uses
POST /v1/bills directly. After this, everything else runs through the agent.2
Ask the agent to review the bill
Start a conversation by sending the bill’s ID to the agent. It loads the extracted fields and walks you through it.
3
Correct any fields (optional)
Tell the agent what’s wrong in natural language; it calls the
patchBill tool to save your edits.4
Submit for review and approve
The agent submits the bill for approval and, once approved, moves it to
Approved.Step 1: Upload the Bill (Direct API)
Bill uploads happen viaPOST /v1/bills as multipart/form-data. The document is read asynchronously.
202 Accepted):
Save the bill
id — you’ll hand it to the agent next. Wait for the state to move to PendingReview — subscribe to the bill.pending_review webhook, or poll GET /v1/bills/{id} — before talking to the agent.Step 2: Ask the Agent to Review the Bill
This is the first turn of the conversation, so omitconversationId. Give the agent the bill ID and ask it to walk you through the extracted fields.
Here’s what was extracted from that bill:Extraction confidence is 0.94. Anything you’d like me to correct before we submit for review?
- Supplier: Acme Supplies Ltd ([email protected])
- Invoice number: ACM-2025-0142
- Invoice date: 15 Jan 2025
- Due date: 14 Feb 2025
- Currency: GBP
- Subtotal: £480.00
- Tax: £96.00
- Total: £576.00
- Line items:
- Bulk stationery order × 10 @ £48.00 (20% tax)
Step 3: Correct Any Fields (Optional)
Tell the agent what’s off. It’ll call thepatchBill tool for you — no need to craft a patch payload by hand.
patchBill, emits an action event, and confirms:
Done — I’ve updated:Ready to submit for review?
- Invoice number: ACM-2025-00142
- Bank details: Acme Supplies Ltd · Account 12345678 · Sort 20-00-00 · GB / GBP
The agent can only edit bills in
PendingReview — matching the direct-API rule. If extraction is still running, ask again in a few seconds.Step 4: Submit for Review and Approve
When the data looks right, have the agent submit the bill and then approve it.Submit for review
submitBillReview:
Submitted. The bill is now in NeedsApproval — Acme Supplies Ltd is linked as the supplier. Ready for you to approve?
Supplier auto-resolution. When the agent submits a bill, Dolfin resolves the supplier in this order: an explicit
supplierId you set → an existing supplier on the organisation whose tax ID or email matches → a new supplier created from the extracted data (requires at minimum supplierName and supplierEmail). If the agent doesn’t have enough data to resolve or create a supplier, submit-review returns 400 Bad Request.Approve
approveBill and confirms:
Approved. The bill is now in Approved and ready for payment scheduling. Want me to schedule the payment now?The agent can also schedule the payment (
schedulePayment) and confirm payment (confirmPaid) via further turns.
Rejecting a bill. The AP agent can’t reject bills — rejection is a direct-API-only call via
POST /v1/bills/{id}/reject. Use the AP Quick Start for that flow.Full Conversation Flow
Managing Conversations
Agent vs Direct API
Next Steps
AP Quick Start (Direct API)
See the same flow using direct API calls, including rejection and re-open.
API Reference
Explore the full Bills API, including payment scheduling and file URLs.