The Dolfin AP Agent lets your users review bills, correct OCR output, manage suppliers, and approve payments through natural language. You upload the bill document via the direct API, then drive the rest of the workflow throughDocumentation Index
Fetch the complete documentation index at: https://docs.dolfinai.co/llms.txt
Use this file to discover all available pages before exploring further.
POST /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:
| Field | Type | Notes |
|---|---|---|
message | string, required | The user’s message for this turn |
conversationId | UUID, optional | Omit on the first turn. Supply on every subsequent turn to continue the same thread |
conversationId.
Response format
The response is atext/event-stream (SSE). Read events as they arrive:
| Event | Payload | When |
|---|---|---|
conversation | { "id": "uuid" } | Fired once, on the first turn only, before any content |
| (unnamed) | { "content": "text chunk" } | Streamed assistant text, one chunk per data frame |
action | Tool action object | When the agent runs a tool (e.g. patched a bill) |
| (unnamed) | { "done": true } | Final frame — stream is complete |
{ "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 /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
Upload the bill (direct API)
Bill uploads are multipart file transfers, so Step 1 uses
POST /bills directly. After this, everything else runs through the agent.Ask the agent to review the bill
Start a conversation by sending the bill’s ID to the agent. It loads the OCR output and walks you through it.
Correct any fields (optional)
Tell the agent what’s wrong in natural language; it calls the
patchBill tool to save your edits.Step 1: Upload the Bill (Direct API)
Bill uploads happen viaPOST /bills as multipart/form-data. OCR runs asynchronously.
202 Accepted):
Save the bill
id — you’ll hand it to the agent next. Wait for the state to move to PendingReview (poll GET /bills/{id} or subscribe to the /hubs/bills SignalR hub) 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 OCR output.
Here’s what OCR extracted from that bill:OCR confidence is 0.94. Anything you’d like me to correct before we submit for review?
- Supplier: Acme Supplies Ltd (billing@acme.co.uk)
- 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 OCR 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 OCR 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 /bills/{id}/reject. Use the AP Quick Start for that flow.Full Conversation Flow
| Turn | conversationId sent? | User message |
|---|---|---|
| 1 | No (first turn) | “I just uploaded bill {id} — walk me through what OCR extracted.” |
| 2 | Yes | ”Invoice number should be ACM-2025-00142, and add bank details…“ |
| 3 | Yes | ”Yes, submit for review.” |
| 4 | Yes | ”Approve it.” |
Managing Conversations
| Endpoint | Purpose |
|---|---|
GET /agent/conversations?agentType=Ap | List the caller’s AP conversations |
GET /agent/conversations/{id} | Get metadata for a single conversation |
GET /agent/conversations/{id}/messages | Paged message history |
PATCH /agent/conversations/{id} | Rename a conversation |
DELETE /agent/conversations/{id} | Delete a conversation and its messages |
Agent vs Direct API
| Direct API | AP Agent | |
|---|---|---|
| Upload | POST /bills (multipart) | Same — agent doesn’t handle file upload |
| Review / patch | Craft a PATCH /bills/{id} body by hand | Describe the changes in plain English |
| Submit / approve | Sequential endpoint calls | Single-turn natural language requests |
| Reject | POST /bills/{id}/reject | Direct API only |
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.