Receipt Scanning
Extract purchase data from receipt photos (PNG, JPG) including store details, totals, and payment method.
Workflow Fields
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.
Field Type Description store_namestring Name of the store or merchant store_addressstring Store location receipt_datedate Date of purchase total_amountfloat Total amount charged tax_amountfloat Tax amount number_of_itemsinteger Number of items purchased payment_methodenum How the purchase was paid contains_alcoholboolean Whether alcohol was purchased
Field Configuration
{
"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"
}
]
}
Process a Document
curl -X POST 'https://api.anyformat.ai/v2/workflows/YOUR_WORKFLOW_ID/run/' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-F 'file=@receipt.jpg'
Get Results
Poll for extraction results using the file ID returned from the upload step.
# Poll for results
max_attempts = 60
base_delay = 5
for attempt in range (max_attempts):
response = requests.get(
f "https://api.anyformat.ai/v2/files/ { file_id } /extraction/" ,
headers = headers
)
if response.status_code == 200 :
results = response.json()
break
elif response.status_code == 412 :
delay = min (base_delay * ( 1.5 ** min (attempt, 5 )), 30 )
time.sleep(delay)
else :
raise Exception ( f "Error: { response.json()[ 'detail' ] } " )
else :
raise TimeoutError ( "Processing timed out" )
store = results[ "store_name" ][ "value" ]
total = results[ "total_amount" ][ "value" ]
has_alcohol = results[ "contains_alcohol" ][ "value" ]
print ( f " { store } : $ { total } (alcohol: { has_alcohol } )" )
Example Response
{
"store_name" : { "value" : "Whole Foods Market" , "confidence" : 96 },
"store_address" : { "value" : "123 Main St, Austin, TX 78701" , "confidence" : 88 },
"receipt_date" : { "value" : "2024-03-22" , "confidence" : 93 },
"total_amount" : { "value" : 47.83 , "confidence" : 94 },
"tax_amount" : { "value" : 3.65 , "confidence" : 91 },
"number_of_items" : { "value" : 12 , "confidence" : 87 },
"payment_method" : { "value" : "credit_card" , "confidence" : 92 },
"contains_alcohol" : { "value" : false , "confidence" : 89 }
}
Tips
The boolean field type is useful for compliance checks. Ask a clear yes/no question in the description for best results.
For receipt photos, good lighting and a flat surface produce significantly better results.
Use float for monetary amounts and integer for counts.
PNG images generally extract better than compressed JPG. If quality matters, prefer PNG.
enum with explicit options constrains the output to known values, preventing free-text variations like “Visa” vs “credit card” vs “CC”.
Next Steps
Response Formats Learn about the unified JSON response format
Error Handling Handle rate limits and retries in production