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

# Outbound Webhooks (Postback)

> Receive AI responses via postback

## What is a Postback?

Postback is how the API notifies your system when AI processing is complete in debounce mode.

## Configuration

When calling `/ai/process` with `debounce: true`, you must provide a `postback_url`:

```json theme={null}
{
  "tenant_id": "uuid",
  "lead_id": "uuid",
  "content": "Hello",
  "message_type": "text",
  "debounce": true,
  "postback_url": "https://your-app.com/ai-callback"
}
```

## Payload Received

Your endpoint will receive a POST with:

```json theme={null}
{
  "lead_id": "lead-uuid",
  "tenant_id": "tenant-uuid",
  "response": "AI response here...",
  "timestamp": "2024-01-15T10:30:00Z",
  "messages_processed": 3
}
```

## Endpoint Example

<CodeGroup>
  ```javascript Express.js theme={null}
  app.post('/ai-callback', express.json(), (req, res) => {
    const { lead_id, response, timestamp } = req.body;

    // Respond quickly
    res.status(200).send('OK');

    // Process in background
    processAIResponse(lead_id, response);
  });

  async function processAIResponse(leadId, response) {
    // Send response to user via WhatsApp, etc.
    await sendWhatsAppMessage(leadId, response);
  }
  ```

  ```python Flask theme={null}
  from flask import Flask, request

  app = Flask(__name__)

  @app.route('/ai-callback', methods=['POST'])
  def ai_callback():
      data = request.json
      lead_id = data['lead_id']
      response = data['response']

      # Process in background (use Celery, RQ, etc.)
      process_ai_response.delay(lead_id, response)

      return 'OK', 200
  ```
</CodeGroup>

## Requirements

<CardGroup cols={2}>
  <Card title="HTTPS" icon="lock">
    URL must be HTTPS
  </Card>

  <Card title="Status 2xx" icon="check">
    Return status 200-299
  </Card>

  <Card title="Timeout 30s" icon="clock">
    Respond within 30 seconds
  </Card>

  <Card title="Idempotent" icon="rotate">
    Handle potential duplicates
  </Card>
</CardGroup>
