---
title: "Automatic PIX receipt verification with AI"
description: "Flow to automatically identify if a file sent by the lead is a PIX receipt and extract the amount using OpenAI."
url: https://help.datacrazy.io/en/articles/10670785-automatic-pix-receipt-verification-with-ai
collection: "Pagamentos"
updated: 2026-11-18
language: en
alternates: [pt-br, es]
---

# Automatic PIX receipt verification with AI

Flow to automatically identify if a file sent by the lead is a PIX receipt and extract the amount using OpenAI.

## Overview

This flow lets you **automatically verify receipts sent by leads** inside the Datacrazy CRM.

The process works in two parts:

1.  A **flow that captures the receipt that was sent**
    
2.  A **flow that monitors and sends the receipt to OpenIA to analyze (inside your funnel or a third separate flow. Use tags/additional field in the conditions so they can communicate.**
    

OpenIA then returns:

-   If the file **looks like a PIX receipt or not**
    
-   The **payment amount identified**
    

This kind of automation has been requested more and more, especially in **PIX payment funnels**.

* * *

## Solution architecture

The process works like this:

1⃣ Lead sends receipt  
2⃣ CRM captures the attachment  
3⃣ System saves the file URL  
4⃣ A flow monitors the arrival of the receipt using tags  
5⃣ The file is sent to **OpenAI**  
6⃣ OpenAI replies whether it’s valid and what the amount is

* * *

## Flow 1 — Capture sent receipt

Create a separate flow responsible only for capturing files sent by the lead.

## Trigger setup

Flow entry:

**Message received**

Setup:

-   No filters
    
-   Active data source
    

* * *

## First check: Control tag

Add a condition:

Check if the lead has the tag:

```javascript
verificar comprovante
```

If **you don't have it**, the flow can end.

If **you have it**, the flow continues.

* * *

## Second check: Is there an attachment?

Now check if the message has a file attached, click on the var { } , now in data input → Message-1 (this is the default name of the message block). If there are more instances, I name them all with the same name!

Field usually used:

```javascript
attachments.url
```

If **it doesn't exist**, end it.

If **it exists**, move on.

* * *

## Save the receipt

Now we need to save the file.

Recommended options:

-   Additional field from **Lead**
    
-   Additional field from **Deal**
    

Example:

```javascript
url_comprovante
```

⚠ If you use **Deals**, you need to make sure the lead has a deal associated in the CRM.

This depends on your funnel rules.

* * *

## Add confirmation tag

After saving the file:

Add the tag:

```javascript
Receipt sent
```

* * *

## Restriction for PDF files

If the file is **.pdf**, recommend the lead to send:

-   **Image**
    
-   **Screenshot of the receipt**
    

This really improves the AI analysis.

You can say that you weren’t able to open the PDF, then ask them to send it as an image OR screenshot instead. Works 100%.

* * *

✔ At this point, **Flow 1 ends**.

* * *

## Flow 2 — Monitor proof-of-payment submission internally in your funnel

Now we go back to the **main funnel flow**.

In the step where the client has to send the proof of payment, set up:

Add tag:

```javascript
verificar comprovante
```

* * *

## Loop control (avoid infinite loop)

Create an **additional numeric field on the lead**:

```javascript
x_loop_times
```

This field will control how many times we’ll check if the proof of payment was sent.

* * *

## Increment counter with JavaScript

Use a **<> JavaScript** block to control the counter.

The script should:

1.  Read the current value of `x_loop_times`
    
2.  If it’s empty or 0 → save **1**
    
3.  If it has a value → **increase by +1**
    

Example of the finished code

```javascript
let x_loop_times = await session.getAdditionalValue('x_loop_times');

// se for null, vazio ou 0 → vira 1
if (!x_loop_times || Number(x_loop_times) === 0) {
    x_loop_times = 1;
} else {
    // se > 0 → incrementa
    x_loop_times = Number(x_loop_times) + 1;
}

// salva novamente no mesmo campo
await session.setAdditionalValue('x_loop_times', x_loop_times);

return {"x_loop_times": x_loop_times}
```

* * *

## Create limit condition

After the JavaScript, add a condition block field has value between two values

```javascript
//Por exemplo, configure o campo para estar entre 0 e 100. 
x_loop_times entre 0 e 100
```

This limits the maximum number of checks.

* * *

## Wait between checks

Add a wait block:

```javascript
Aguardar 30 segundos ou 
```

After that, check:

```javascript
Lead possui tag "Comprovante enviado"
```

* * *

## Flow behavior

If it **doesn't have the tag**:

→ the flow keeps waiting and testing again.

If it **has the tag**:

→ it sends the receipt for AI analysis.

* * *

## Total wait time

Current setup:

```javascript
100 verificações
x
30 segundos
```

Approximate total time:

**50 minutes**

If you want to increase the time, just increase the limit.

Example:

```javascript
1000 loops
```

* * *

## API call to OpenAI

Method:

```javascript
POST
```

URL:

```javascript
https://api.openai.com/v1/responses
```

* * *

## Request JSON body

```javascript
{
   "model":"gpt-4.1",
   "input":[
      {
         "role":"user",
         "content":[
            {
               "type":"input_text",
               "text":"I want to know if this looks like a Pix receipt. Answer valido-nao if it doesn't look like a Pix receipt or valido-sim if it looks like a Pix receipt.\n\nAnswer with:\nvalido-sim\nor\nvalido-nao\n\nDon't send absolutely anything else besides that. Also bring the deposited/sent amount. always use it. The answer needs to be a valid JSON schema, only with the data that was requested"
            },
            {
               "type":"input_image",
               "image_url":"${urlComprovante}"
            }
         ]
      }
   ]
}
```

Run tests, see if it works for you, adjust if needed.

* * *

## Expected response from the AI

The answer must be a **valid JSON**, containing:

-   If the receipt looks valid
    
-   The amount identified
    

Expected example:

```javascript
{
  "valido": "sim",
  "valor": "150.00"
}
```

Or

```javascript
{
  "valido": "nao",
  "valor": null
}
```

* * *

## Final result

With this flow implemented, the system can:

✔ Detect when the client sends a receipt  
✔ Identify if it’s a PIX receipt  
✔ Extract the amount automatically  
✔ Integrate with funnel automations

This lets you create processes like:

-   **Automatic access release**
    
-   **Automatic payment validation**
    
-   **Automatic order approval**
