> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coupons.piixan.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks

> lote.completado: aviso firmado con HMAC cuando termina un lote, y cómo verificarlo.

El operador registra tu URL y un secreto. Cuando un lote termina, el motor envía:

```http theme={null}
POST /webhooks/motor HTTP/1.1
Content-Type: application/json
X-Marca-Tiempo: 1772803200
X-Firma: 5f1c…

{"evento":"lote.completado","job_id":"job_…","campana_id":"camp-2026-11","n_decisiones":48213,"resultado_url":"https://ficheros.coupons.piixan.ai/motor-decision/tenant_id=acme/lotes/job_….jsonl?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=3600&X-Amz-Signature=…"}
```

La firma es `HMAC-SHA256(secreto, "<marca_tiempo>." + cuerpo)`. Verifica la firma y
que la marca de tiempo esté a menos de 5 minutos: así una petición capturada no se
puede repetir. El SDK lo hace por ti:

```python theme={null}
from motor_decision_sdk import verificar_webhook

if not verificar_webhook(SECRETO, request.headers, request.body):
    abort(401)
```

Responde `2xx` rápido; el motor reintenta tres veces con espera y, si no puede
entregar, lo registra: el resultado sigue disponible por la API.
