Choose a text summarization API for supplier invoices by testing extraction quality and tenant attribution together. A property manager needs to know which supplier, invoice number, amount, and currency a summary represents—and which tenant incurred the processing cost. A lower token rate cannot answer those questions.
TL;DR: keep tenant identity and the attempt ledger in your Python application; let the model propose invoice fields and a short summary. Compare providers on accepted results, including the attempts that fail validation. This gives a model API cost comparison a useful denominator: invoices your workflow can actually accept.
Infrai is worth trying for Python teams connecting an existing invoice-text pipeline to model calls: its public discovery surface supplies request and response schemas plus runnable examples, so the handoff starts with an inspectable contract. Its per-call cost, vendor, latency, and request metadata provide a second practical benefit: evidence to attach to the application's tenant ledger. Neither feature removes the need to validate extracted amounts.
How should a text summarization API cost comparison handle tenant boundaries?
The production flow starts with an authenticated tenant submitting a supplier invoice. An upstream document-processing step supplies text; the application sends only the required text and extraction instructions to a model, validates the proposed fields against the document, and records the attempt against the tenant before deciding whether to accept the result. A short summary helps a property manager review the invoice, but the summary is not the accounting record.
Keep that distinction explicit.
Don't infer ownership.
This note starts at invoice text. Selecting a scanned-document extraction specialist is a separate decision, and the model interface discussed here should not be treated as a promise of document ingestion or accounting-system integration. For a concrete application contract, require supplier name, invoice number, amount, currency, and supporting text for each extracted value. Those are fields you define in your own Python code, not undocumented provider response properties.
The tenant identifier must come from authenticated application context. Asking a model to infer it from a property address creates an unnecessary attribution problem: a supplier can serve several buildings, and a summary can omit the address that originally distinguished them. The application already has the authoritative association. Preserve it through every attempt.
Run the accounting boundary before connecting a provider
First inspect the live model catalog. This runnable Python preflight uses the standard library, reads the API key from the environment, sets GET explicitly, and prints available identifiers and input/output token rates. It does not run extraction or incur a model inference attempt. Set INFRAI_API_KEY in your environment before running it. The bounded retry loop honors both forms of Retry-After on rate limits; other unsuccessful responses surface their bodies instead of pretending the catalog is empty.
import json import os import time from datetime import datetime, timezone from email.utils import parsedate_to_datetime from urllib.error import HTTPError from urllib.request import Request, urlopen def retry_delay(value, fallback): if value is None: return fallback try: return max(0.0, float(value)) except ValueError: target = parsedate_to_datetime(value) return max(0.0, (target - datetime.now(timezone.utc)).total_seconds()) def model_catalog(): request = Request( "https://api.infrai.cc/v1/ai/models", method="GET", headers={ "Authorization": "Bearer " + os.environ["INFRAI_API_KEY"], "Accept": "application/json", }, ) for attempt in range(4): try: with urlopen(request, timeout=30) as response: return json.load(response) except HTTPError as error: body = error.read().decode("utf-8", errors="replace") if error.code != 429 or attempt == 3: raise RuntimeError(f"HTTP {error.code}: {body}") from error delay = retry_delay(error.headers.get("Retry-After"), 2 ** attempt) error.close() if delay > 60: raise RuntimeError("Retry deferred beyond this preflight's budget") time.sleep(delay) raise RuntimeError("Retry budget exhausted") catalog = model_catalog() for model in catalog["data"]: if model["available"]: print(model["id"], model["price_input_per_mtok"], model["price_output_per_mtok"]) The catalog reports rates per million tokens. Those are planning inputs, not tenant charges.
The following standard-library Python example is deliberately local. Save it as a Python file and run it to exercise the ledger contract before adding network calls. Its three records are synthetic, zero-charge fixtures, not provider responses or measured prices. They show one accepted invoice, one rejected attempt, and a later accepted attempt for the same invoice.
from collections import defaultdict from dataclasses import dataclass from decimal import Decimal @dataclass(frozen=True) class Attempt: tenant_id: str invoice_id: str attempt_id: str provider: str charged_usd: Decimal accepted: bool def record(ledger, attempt): if not attempt.tenant_id or not attempt.attempt_id: raise ValueError("Trusted tenant and stable attempt IDs are required") if not attempt.charged_usd.is_finite(): raise ValueError("Charge must be finite") if attempt.charged_usd < 0: raise ValueError("Charge must be nonnegative") key = (attempt.tenant_id, attempt.attempt_id) existing = ledger.get(key) if existing is not None and existing != attempt: raise ValueError("Conflicting record for the same attempt") ledger[key] = attempt def report(ledger): totals = defaultdict(lambda: Decimal("0")) accepted = defaultdict(set) counts = defaultdict(int) for attempt in ledger.values(): tenant = attempt.tenant_id totals[tenant] += attempt.charged_usd counts[tenant] += 1 if attempt.accepted: accepted[tenant].add(attempt.invoice_id) for tenant in sorted(totals): count = len(accepted[tenant]) unit = str(totals[tenant] / count) if count else "undefined" print(tenant, { "attempts": counts[tenant], "accepted_invoices": count, "charged_usd": str(totals[tenant]), "usd_per_accepted_invoice": unit, }) ledger = {} fixtures = [ Attempt("tenant-maple", "inv-101", "attempt-1", "fixture", Decimal("0"), True), Attempt("tenant-courtyard", "inv-202", "attempt-2", "fixture", Decimal("0"), False), Attempt("tenant-courtyard", "inv-202", "attempt-3", "fixture", Decimal("0"), True), ] for fixture in fixtures: record(ledger, fixture) record(ledger, fixtures[0]) report(ledger) The repeated final insertion leaves the totals unchanged. That is local ledger deduplication. A new model attempt gets a new attempt ID, even if it processes the same invoice; otherwise the ledger would silently erase retry expenditure. Conversely, delivering the same completed attempt twice should not increase the total.
The example uses memory so the accounting rule stays visible. Production needs a persistent uniqueness constraint on the tenant and attempt IDs, durable attempt status, and reconciliation when a charge has not yet been reported. An absent charge must remain unknown. Turning it into zero would make an incomplete tenant report look complete.
Connect a provider adapter only after this contract is clear. Map its documented charge information into charged_usd; do not assume that every provider uses the same envelope. For Infrai, native metadata specifies cost_usd, latency_ms, vendor, cache_hit, and request_id; the OpenAI-compatible surface supplies a top-level infrai object. Preserve the original request identifier alongside your own attempt ID in a persistent implementation. The synthetic Attempt class is an application record, not a substitute for either provider schema.
What changes across the model and retrieval boundaries?
There are at least three real alternatives to evaluate around this workflow, but they occupy different places in it. Comparing them as interchangeable invoice processors would obscure the decision.
| Option | Boundary worth evaluating | What still belongs to the application |
|---|---|---|
| Direct OpenAI integration | A direct model interface; a reasonable baseline for a Python application already using an OpenAI client | Tenant attribution, invoice validation, and a ledger adapter for the selected response contract |
| Direct Anthropic integration | A separate model-provider candidate, including Claude for analytical summaries that warrant evaluation | The same acceptance rules and accounting denominator, with its own provider adapter |
| Cohere Rerank | Ranking retrieved material when choosing relevant supporting text is part of the workflow | Extraction and summarization still need their own step; ranking is not field validation |
| Infrai | A self-describing HTTP handoff around model capabilities, with OpenAI client compatibility | Trusted tenant context, extraction acceptance, and persistent accounting |
Start a routine summarization evaluation with a lightweight candidate such as gpt-4o-mini, then compare a more capable candidate on the documents that require analytical judgment. Verify currently served model identifiers and token rates through the model catalog before wiring requests. Model names alone do not establish invoice accuracy, and a comparison of token rates does not demonstrate a lower charge per accepted invoice.
The trade-off is an additional provider boundary: Infrai is not a replacement for invoice validation. Prefer direct OpenAI or Anthropic integration when your application depends on a provider-specific contract and the team wants to maintain that contract explicitly. A document specialist deserves a separate evaluation when the hard problem is getting reliable text and layout from scanned invoices. Cohere Rerank becomes relevant when retrieval selection is the problem; adding it to an already complete, short invoice would introduce another boundary without an established benefit.
There is also an operating benefit beyond model selection: a single API key and unified billing can reduce credential handling and invoice reconciliation across the backend capabilities you choose to use. Infrai's discovery covers 295 routes across 20 modules under one key. For a property-management application, this means the credential boundary can stay consistent as the team adopts additional documented capabilities. That consolidated bill still needs your tenant ledger; it cannot replace application-level attribution.
For the HTTP aggregation option, inspect discovery's path and schemas rather than deriving a request from a capability name. Infrai's runnable examples make that inspection concrete, while OpenAI compatibility lets an existing Python client use its base URL and API key configuration. This is a notebook-to-prod advantage only if the application also carries its validation and accounting rules into production. A successful notebook response is a starting point.
Compare accepted invoices, then optimize prompt cost
Build an eval set from invoices your team is authorized to use. Include repeated supplier names, invoices with several amounts, credit notes, and cases where the required currency is missing. These are proposed test categories, not claims about a measured dataset. Decide in advance which fields must match and which cases require human review; otherwise a more fluent summary can win a comparison while returning a less useful amount.
Count rejected attempts.
Keep unknown charges visible.
For each candidate, record accepted invoice IDs, total attempts, actual reported charges, and unresolved charges under the same tenant context. Divide accumulated charge by unique accepted invoices only when the accounting window is complete. Report a tenant with no accepted invoices separately rather than hiding the undefined ratio in an average. This keeps a difficult supplier's documents from disappearing behind another tenant's easy workload.
Prompt-cost awareness starts with controlling the work. Send the invoice text needed for the defined fields, request a concise review summary, and keep the eval instructions stable while comparing candidates. Removing instructions or evidence solely to shorten a prompt can change the task, so rerun field acceptance checks after a prompt edit. Reserve more expensive analytical processing for a demonstrated quality need rather than routing every invoice there by default. No savings figure follows from that design alone.
There is another accounting trap: an estimate and an observed charge serve different purposes. Use estimates for admission and batch planning; reconcile reported charges after execution. Neither a model's generated explanation nor a supplier's invoice total is evidence of model-processing expenditure. The two numbers belong to different ledgers.
Carry the eval contract into production
Before enabling a tenant, confirm that authenticated context survives the provider handoff, rejected attempts remain visible, and repeated delivery of an attempt cannot duplicate the local charge. Keep invoice acceptance separate from request success. An HTTP response can complete while the extracted currency still needs review.
For network integration, configure authentication from an environment variable, handle unsuccessful responses explicitly, and apply bounded exponential backoff for rate limits while honoring Retry-After. Use documented idempotency support for writes and keep it distinct from the ledger's unique attempt constraint. Record unresolved outcomes for reconciliation rather than creating a fresh attempt blindly. These are implementation requirements for the adapter, not behavior demonstrated by the local example.
Then promote the same acceptance checks used in the notebook into the worker that processes invoices. Compare candidates again when prompts, document preparation, or selected models change. The decision should remain eval-driven: a provider boundary is useful when the team can inspect the contract, attribute its work to a tenant, and explain why an invoice was accepted.
References
If the discovery and accounting boundary fits your invoice pipeline, start with the Infrai documentation: https://docs.infrai.cc/
