We recommend creating this workflow in the anyformat platform where you can test with sample receipt photos and iterate on field descriptions. Copy the workflow ID to use with the API.
Python package + class names are provisional.pip install anyformat-sdk and from anyformat.sdk import Client work today, but both are expected to change before the official launch — pin the version you ship with.
curl
TypeScript
Python
# 1. Create the workflowcurl -X POST 'https://api.anyformat.ai/v2/workflows/' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $ANYFORMAT_API_KEY" \ -d '{ "name": "Receipt Scanner", "description": "Extract receipt details from photos and scans", "nodes": [ {"id": "parse_1", "type": "parse"}, { "id": "extract_1", "type": "extract", "extraction_schema": { "fields": [ {"name": "store_name", "description": "Name of the store or merchant", "data_type": "string"}, {"name": "store_address", "description": "Full address of the store location", "data_type": "string"}, {"name": "receipt_date", "description": "Date of the purchase transaction", "data_type": "date"}, {"name": "total_amount", "description": "Total amount charged including tax", "data_type": "float"}, {"name": "tax_amount", "description": "Total tax amount", "data_type": "float"}, {"name": "number_of_items", "description": "Total number of items purchased", "data_type": "integer"}, { "name": "payment_method", "description": "Payment method used for the transaction", "data_type": "enum", "enum_options": [ {"name": "cash", "description": "Cash payment"}, {"name": "credit_card", "description": "Credit card payment"}, {"name": "debit_card", "description": "Debit card payment"}, {"name": "mobile_payment", "description": "Mobile or digital wallet payment"} ] }, {"name": "contains_alcohol", "description": "Whether any alcoholic beverage was included in the purchase", "data_type": "boolean"} ] } } ], "edges": [{"source": "parse_1", "target": "extract_1"}] }'# 2. Run a receipt photocurl -X POST 'https://api.anyformat.ai/v2/workflows/WORKFLOW_ID/run/' \ -H "Authorization: Bearer $ANYFORMAT_API_KEY" \ -F 'file=@receipt.jpg'# 3. Poll for resultscurl -H "Authorization: Bearer $ANYFORMAT_API_KEY" \ 'https://api.anyformat.ai/v2/workflows/WORKFLOW_ID/files/COLLECTION_ID/results/'
import { Anyformat, Schema } from "@anyformat/sdk";const af = new Anyformat({ apiKey: process.env.ANYFORMAT_API_KEY! });const file: File = /* a File with .name set, e.g. new File([bytes], "receipt.jpg") */;const workflow = await af .workflow("Receipt Scanner", "Extract receipt details from photos and scans") .parse() .extract([ Schema.string("store_name", "Name of the store or merchant"), Schema.string("store_address", "Full address of the store location"), Schema.date("receipt_date", "Date of the purchase transaction"), Schema.float("total_amount", "Total amount charged including tax"), Schema.float("tax_amount", "Total tax amount"), Schema.integer("number_of_items", "Total number of items purchased"), Schema.enum("payment_method", "Payment method used for the transaction", [ Schema.option("cash", "Cash payment"), Schema.option("credit_card", "Credit card payment"), Schema.option("debit_card", "Debit card payment"), Schema.option("mobile_payment", "Mobile or digital wallet payment"), ]), Schema.boolean("contains_alcohol", "Whether any alcoholic beverage was included"), ]) .create();const run = await workflow.run(file);const result = await run.wait();console.log(result.field("store_name")?.value);console.log(result.field("total_amount")?.value);console.log(result.field("contains_alcohol")?.value);
import osfrom anyformat.sdk import Clientfrom anyformat.workflow import Schemaclient = Client(api_key=os.environ["ANYFORMAT_API_KEY"])workflow = ( client.workflow("Receipt Scanner") .parse() .extract([ Schema.string("store_name", "Name of the store or merchant"), Schema.string("store_address", "Full address of the store location"), Schema.date("receipt_date", "Date of the purchase transaction"), Schema.float("total_amount", "Total amount charged including tax"), Schema.float("tax_amount", "Total tax amount"), Schema.integer("number_of_items", "Total number of items purchased"), Schema.enum("payment_method", "Payment method used for the transaction", options=[ Schema.option("cash", "Cash payment"), Schema.option("credit_card", "Credit card payment"), Schema.option("debit_card", "Debit card payment"), Schema.option("mobile_payment", "Mobile or digital wallet payment"), ]), Schema.boolean("contains_alcohol", "Whether any alcoholic beverage was included"), ]) .create())result = workflow.run("receipt.jpg").wait()print(result.fields["store_name"].value)print(result.fields["total_amount"].value)print(result.fields["contains_alcohol"].value)