DEV Community

Cover image for What an eSIM checkout and a paid OCR call taught us about agent payments
Alex
Alex

Posted on Edited on

What an eSIM checkout and a paid OCR call taught us about agent payments

A traveller who asks for a week of mobile data in Japan needs a plan and somewhere to buy it. An agent that has a scanned PDF already has the input and needs a result it can use in the same workflow. On November 26, we put one offer of each kind in the ModelMarket catalogue, with the supplier collecting the payment in both cases.

The distinction shows up in the response the agent gets. Tutu returns a price and a checkout URL. HALOWERK returns a payment challenge for the exact PDF, then accepts a signed retry. Here is where the price, attribution and proof of delivery sit in each flow.

Two flows. Tutu supplies a tagged checkout link for a human buyer. HALOWERK quotes a PDF with HTTP 402, then returns OCR and a payment receipt after the buyer signs and retries.

A quote that ends in checkout

The Tutu pilot lists one Japan data plan, JP-1-7, with 1 GB for seven days. ModelMarket asks Tutu for the current price and returns a provider link carrying the plan and src=aimarket. Tutu handles payment and delivers the eSIM. The quote we checked on November 26 was $3.49.

Run this from a shell with curl and Python 3. It requests the current quote and prints the buy link.

curl -fsS https://modelmarket.dev/ai-market/v2/external-services/tutu-esim/quote \
  | python3 -c 'import json,sys; q=json.load(sys.stdin); print(q["plan_id"], q["price"], q["currency"]); print(q["checkout_url"])'
Enter fullscreen mode Exit fullscreen mode

A quote and a checkout click are early steps in that flow. Tutu's order log is where we can learn how many tagged purchases went through. The Tutu check for this article stopped at the quote and handoff.

A quote tied to the bytes in a PDF

For the OCR pilot, the buyer posts one PDF to ModelMarket. The Hub forwards the body to HALOWERK, sets X-HALOWERK-QUELLE: modelmarket and relays the seller's Payment-Required header. The quote includes the SHA-256 of the file, the page count, and the payment terms for this request. The buyer can inspect those terms before asking its wallet to sign.

The example below downloads the synthetic scan used in the test and reads the challenge. It requires curl and Python 3 and uses no wallet or credentials.

curl -fsSLO https://modelmarket.dev/blog/media/two-supplier-pilots-2026-11-26/sample.pdf

python3 - <<'PY'
import base64, hashlib, json
from pathlib import Path
from urllib.error import HTTPError
from urllib.request import Request, urlopen

pdf = Path("sample.pdf").read_bytes()
body = json.dumps({
    "image_base64": base64.b64encode(pdf).decode(),
    "mime": "application/pdf",
}).encode()
endpoint = (
    "https://modelmarket.dev/ai-market/v2/external-services/"
    "halowerk-ocr/ocr"
)
request = Request(
    endpoint, data=body, headers={"Content-Type": "application/json"},
    method="POST",
)

try:
    with urlopen(request, timeout=20) as response:
        raise SystemExit(f"Expected a quote, got HTTP {response.status}")
except HTTPError as response:
    if response.code != 402:
        raise
    with response:
        quote = json.loads(base64.b64decode(
            response.headers["Payment-Required"]
        ))

assert quote["quote"]["file_sha256"] == hashlib.sha256(pdf).hexdigest()
assert quote["quote"]["pages_priced"] == [1]
offer, = quote["accepts"]
print(offer["network"], offer["amount"], "atomic units")
print(quote["quote"]["total_usdc"], "USDC")
PY
Enter fullscreen mode Exit fullscreen mode

On November 26 that returned eip155:8453, 6000 atomic units, and 0.006 USDC. A buyer proceeding from here signs the quoted terms and repeats the same body with Payment-Signature. The payment goes directly to HALOWERK. ModelMarket forwards the OCR response and receipt, and records a successful paid delivery by transaction hash so a repeated receipt counts once.

Settlement and recognition answer different questions

We ran the paid flow against a local ModelMarket instance connected to the real HALOWERK endpoint. We received HTTP 200, verified the transfer on Base, and matched the returned document hash to the submitted scan. HALOWERK later confirmed the same request in its payment log with our attribution header. After deployment we checked the public catalogue, MCP discovery and the live unpaid quote again.

The OCR output got the reference and total right. It read the synthetic code A0B7 as AOB7, even though the returned block confidence was 0.94. This was one clean test scan, so it tells us what happened to that field on that page. In an invoice workflow I would preserve the raw OCR, then validate identifiers against their expected format or checksum before using them downstream.

For the two-week reconciliation, we're counting successful tagged orders at Tutu and successful paid, tagged OCR calls at HALOWERK. The direct OCR check and the ModelMarket OCR check both settled. We'll exclude both test calls when we compare the pilot totals.

Update, 27 November. Two answers that readers' questions led to. Tutu keeps src=aimarket in the browser's local storage with no expiry, so a purchase days or weeks after the quote still counts if it happens in the same browser. It is first touch: a browser that reached Tutu earlier from another source keeps that source on the order, and a different browser or device starts clean. Since this morning the Hub also records every Tutu quote it hands out (time, route, price, nothing about the caller), and each checkout link carries a quote reference as mmq, which Tutu agreed to store with the order. The command above now prints that link with its mmq value.

Both offers are in the ModelMarket catalogue. The supplier references are Tutu's Japan plan and HALOWERK's OCR API.

Disclosure: we operate ModelMarket. AI assistance was used to prepare the test tooling, this article and its illustrations.

Top comments (7)

Collapse
 
userxnom profile image
Abdullah Naseer •

The cleanest distinction in this post is the one in the title of the last section: settlement and recognition answer different questions. A paid OCR call can settle perfectly and still return the wrong characters, and a checkout link can convert without the agent ever knowing it did.

Two details stood out. Tying the HALOWERK quote to the SHA-256 of the PDF, the page count and the payment terms is the right design — the quote cannot be reused for a different file, and the 0.006 USDC / 6000 atomic units on eip155:8453 is quoted for exactly that document. And the A0B7 read as AOB7 at 0.94 block confidence is a useful warning: confidence is not accuracy for structured fields, especially a reference code where one character changes the meaning.

For the two-week reconciliation you mention, how are you attributing a Tutu order that was quoted on one day and bought later — does the src=aimarket tag carry an expiry, or do you count it by the quote that led to it regardless of when the buyer completes checkout?

Collapse
 
alexar76 profile image
Alex •

Follow-up, as promised: I asked Tutu. Their checkout keeps src=aimarket in the browser's local storage with no expiry, so a purchase days or weeks after the quote still counts if it happens in the same browser. It's first touch, though: a browser that reached Tutu earlier from another source keeps that source on the order, and a different browser or device starts clean.

Two changes since my reply. The Hub now records every Tutu quote it hands out (time, route, price, nothing about the caller), so the reconciliation can set Tutu's tagged orders against the links we issued. And each checkout link now carries a quote reference as mmq, which Tutu agreed to store with the order. Once they confirm it's being saved, an order can be matched to the quote that led to it and to how old that quote was, which is the "by the quote that led to it" option from your question.

Collapse
 
alexar76 profile image
Alex •

Thanks, and good question, because the honest answer is "neither, quite".

The link the Hub returns carries two parameters, plan=JP-1-7 and src=aimarket. There is no quote ID and no timestamp in it, and the Hub validates that nothing else is in it. So we can't tie an order back to a specific quote. A buyer who quoted on Monday and bought on Friday shows up only as a tagged order. We can't see which quote led to it.

What we count is what Tutu's order log records with the tag during the pilot window. Whether the tag survives a later visit depends on how Tutu's checkout keeps it. That's Tutu's attribution window, not ours, and I don't know its length yet. I'll ask them and put the answer next to the numbers when we publish the reconciliation.

Your question also showed a gap on our side, so we closed it today: the Hub now records every Tutu quote it hands out, with the time, the route (the REST quote URL or an invoke call), the price and whether Tutu answered. Nothing about the caller. The reconciliation can then put Tutu's tagged orders next to the number of links we actually issued.

HALOWERK doesn't have this gap. The attribution header travels on the paid call itself, so payment and attribution land in the same request.

If the pilot continues, the obvious fix is a quote reference in the link that Tutu stores with the order. Then an order could be matched to its quote and its age.

Collapse
 
junfengzhou01 profile image
Junfeng Zhou •

For the paid OCR case it would help to return a confidence per field next to the receipt, so an agent can send the one misread character to a human check instead of treating a settled payment as a correct result.

Collapse
 
alexar76 profile image
Alex •

Agreed on the direction, and our run shows why block-level confidence isn't enough. HALOWERK reports confidence per page and per block, and flags a block as low_confidence below 0.5. The block with the misread code came back at 0.94, so nothing in the response pointed at A0B7 → AOB7. A per-word value, which Tesseract can produce, would at least narrow the doubt to the token that matters.

Two caveats. First, it belongs in the result, not in the payment receipt. The receipt says the payment settled for this document, and it should stay true whatever the OCR got wrong. Second, O/0 and l/1 swaps can come back with high confidence too, because the engine is confident in the wrong glyph. For identifiers, the check I'd trust more is the one the agent can run itself: expected format, checksum, or a match against a known list. Low confidence or a failed format check would then send the field to a person.

I'll pass the per-word suggestion on to HALOWERK. On our side, the Hub returns their result unchanged, so anything they add reaches the agent without a change from us.

Collapse
 
junfengzhou01 profile image
Junfeng Zhou •

The format check can be cheap too: if the code pattern is known (letter, digit, letter, digit), AOB7 fails on the second character, so the agent can flag it even at 0.94 confidence.

Thread Thread
 
alexar76 profile image
Alex •

Thanks, Junfeng. We shipped the optional format check. With the LDLD pattern, AOB7 flags character 2 even at 0.94 block confidence. The API returns the original OCR text intact and puts the diagnostic in a separate response header.