# Generate & regenerate evidence (https://docs.chargeflow.io/docs/platforms/eaas/generate-and-regenerate)



Generating evidence is the core EaaS action: you hand Chargeflow a dispute - by `dispute_id` or inline - and it returns an AI-composed, versioned evidence package. This page covers the call, its error codes, and how to regenerate as new data arrives.

## Generate evidence [#generate-evidence]

Use the Generate Evidence API to kick off AI-powered evidence creation for a dispute.

```
POST /public/2025-04-01/evidence
```

The endpoint accepts either an existing Chargeflow `dispute_id` **or** a full inline dispute object. You do not need to create the dispute separately first.

### Integration patterns [#integration-patterns]

**Option A, reference an existing dispute:**

```bash title="Terminal"
curl -X POST https://api.chargeflow.io/public/2025-04-01/evidence \
  -H "x-api-key: YOUR_PLATFORM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "66e6ea9ecd94925a9f8060d9",
    "dispute": {
      "dispute_id": "66e6ea9ecd94925a9f8060d9"
    }
  }'
```

**Option B, submit dispute data inline:**

```bash title="Terminal"
curl -X POST https://api.chargeflow.io/public/2025-04-01/evidence \
  -H "x-api-key: YOUR_PLATFORM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "66e6ea9ecd94925a9f8060d9",
    "dispute": {
      "dispute_data": {
        "source_id": "du_123456789",
        "created_at": "2024-02-10T12:00:00Z",
        "reason": "fraud",
        "due_by": "2024-02-20T12:00:00Z",
        "amount": 150.00,
        "currency": "USD",
        "status": "needs_response",
        "transaction": {
          "source_id": "tx_1234567890",
          "created_at": "2024-02-08T10:00:00Z",
          "type": "paid",
          "amount": 150.00,
          "currency": "USD"
        }
      }
    }
  }'
```

### Response [#response]

The API responds immediately with an `in_progress` status. Evidence generation is asynchronous; the PDF is not included in the response. Listen for the `evidence.ready` or `evidence.error` webhooks to know when it completes.

```json title="Response"
{
  "id": "ev_abc123456789",
  "account_id": "acct_9876543210",
  "ext_account_id": "ext_acct_54321",
  "dispute": "dp_1122334455",
  "created_at": "2025-07-29T14:35:00Z",
  "status": "in_progress",
  "file_url": null,
  "file_version": 1
}
```

Generation typically completes in \~30 seconds, with a maximum of \~3 minutes.

### Error codes [#error-codes]

| Error Code                   | HTTP Status | Description                                                                                                                      |
| ---------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `422_dispute_invalid_state`  | 422         | Dispute must have status `needs_response` to generate evidence.                                                                  |
| `409_generation_in_progress` | 409         | Evidence generation is already in progress for this dispute. Do not retry - wait for the completion webhook (see warning below). |
| `404_*_not_found`            | 404         | The dispute was not found. Verify the `dispute_id` is correct and belongs to the given `account_id`.                             |
| `403_eaas_not_enabled`       | 403         | Your API key is not entitled to EaaS. Contact your account manager to enable it.                                                 |
| `504_generation_timeout`     | 504         | The generation operation timed out. Retry the request.                                                                           |

<Callout type="warn" title="Warning">
  Do not retry on `409_generation_in_progress`. Wait for the `evidence.ready` or `evidence.error`
  webhook before taking further action.
</Callout>

## Regenerate evidence [#regenerate-evidence]

Evidence can be regenerated at any time while the dispute remains in `needs_response` status. Each regeneration attempt increments `file_version`, giving you a full history of evidence revisions.

```bash title="Terminal"
curl -X POST https://api.chargeflow.io/public/2025-04-01/evidence \
  -H "x-api-key: YOUR_PLATFORM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "66e6ea9ecd94925a9f8060d9",
    "dispute": {
      "dispute_id": "66e6ea9ecd94925a9f8060d9"
    }
  }'
```

The response will show `file_version: 2` (or higher) once the new PDF is ready.

**When to regenerate:**

* New order data has become available (tracking, fulfillment, etc.)
* The merchant has added communication logs or policy context
* You received an `evidence.error` and have resolved the underlying issue

<Callout type="idea" title="Tip">
  More data equals stronger narratives. Missing pieces won't block generation; the AI agent
  prioritizes the most impactful evidence available. But richer context consistently produces more
  persuasive evidence packages.
</Callout>

## Report dispute outcomes [#report-dispute-outcomes]

When disputes are resolved (won or lost), share the outcome with Chargeflow. This data helps the AI continuously refine dispute strategies and improve win rates across all merchants on your platform.

Contact your account manager for the preferred method of submitting outcome data for your integration.

## Next steps [#next-steps]

<Cards>
  <Card title="evidence.ready" href="../webhook-events#evidence-ready">
    Download the PDF once generation completes.
  </Card>

  <Card title="evidence.error" href="../webhook-events#evidence-error">
    Diagnose and retry a failed generation.
  </Card>

  <Card title="Privacy and security" href="./compliance">
    How download links and data residency work.
  </Card>

  <Card title="Submit platform disputes" href="./submit-platform-disputes">
    Create the dispute you generate evidence for.
  </Card>
</Cards>
