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

# Integrations

> Connect your bot to AI backends

Integrations connect your bots to AI backends that generate responses. An integration is a webhook configuration that defines how to communicate with services like OpenAI, Anthropic, or your own custom API.

![Integrations page](https://mintcdn.com/chatbotplatform/QhGUbEN05MzAjt2K/images/screenshots/02-integrations/01_integrations_empty.png?fit=max\&auto=format\&n=QhGUbEN05MzAjt2K\&q=85\&s=aa16a3bbe06e350694b4b49183ed6293)

Empty integrations page

## Overview

An integration consists of:

* **Webhook URL**: The endpoint to send messages to
* **HTTP Headers**: Authentication and custom headers
* **Timeout**: Maximum wait time for responses
* **Weight**: For A/B testing (optional)
* **Payload Format**: The request structure sent to your backend

![Create integration](https://mintcdn.com/chatbotplatform/oGBHbCo1_YwbpmWy/images/screenshots/02-integrations/02_create_integration_form.png?fit=max\&auto=format\&n=oGBHbCo1_YwbpmWy\&q=85\&s=210a0408e49076ce82e28d1047065a6c)

Create integration form

## Creating an Integration

**1. Navigate to Integrations**

From your bot page, click **Integrations** in the sidebar.

**2. Click Create Integration**

Click the **Create Integration** button to open the form.

**3. Configure Basic Settings**

Enter the integration details:

![Basic integration info](https://mintcdn.com/chatbotplatform/IwOyuSig9ydzaHpG/images/screenshots/02-integrations/03_integration_basic_info.png?fit=max\&auto=format\&n=IwOyuSig9ydzaHpG\&q=85\&s=fe9bedac25887b9547a1faf26518a754)

Basic integration information

* **Name**: Friendly name (e.g., "OpenAI GPT-4")
* **Webhook URL**: Your AI backend endpoint
* **Timeout**: Response timeout in seconds (default: 30)

**4. Add Headers (Optional)**

Add authentication or custom headers:

![Custom headers](https://mintcdn.com/chatbotplatform/dChquPcU8U3rTZ0O/images/screenshots/02-integrations/04_integration_with_headers.png?fit=max\&auto=format\&n=dChquPcU8U3rTZ0O\&q=85\&s=952cbcdb5c930534200dac83bdcf0ed2)

Integration with custom headers

Example headers:

```
Authorization: Bearer sk-...
Content-Type: application/json
X-Custom-Header: value
```

**5. Configure Advanced Settings**

Set additional options:

![Advanced settings](https://mintcdn.com/chatbotplatform/dChquPcU8U3rTZ0O/images/screenshots/02-integrations/05_integration_advanced_settings.png?fit=max\&auto=format\&n=dChquPcU8U3rTZ0O\&q=85\&s=4d7968b6bcd649e4e306d32d0a7de122)

Advanced integration settings

* **Weight**: For A/B testing (default: 1)
* **Fallback**: Mark as fallback integration

**6. Preview Payload**

Review the payload format that will be sent:

![Payload preview](https://mintcdn.com/chatbotplatform/QhGUbEN05MzAjt2K/images/screenshots/02-integrations/06_payload_preview.png?fit=max\&auto=format\&n=QhGUbEN05MzAjt2K\&q=85\&s=326f7efa42fedde87be8bb00e90db310)

Payload preview

**7. Save**

Click **Create** to save the integration.

![Integration created](https://mintcdn.com/chatbotplatform/QhGUbEN05MzAjt2K/images/screenshots/02-integrations/07_integration_created.png?fit=max\&auto=format\&n=QhGUbEN05MzAjt2K\&q=85\&s=c468100c685986d613bff8cf173b916d)

Integration created successfully

## Request Payload Format

When a user sends a message, your integration receives a POST request with this structure:

```json theme={null}
{
  "messages": [
    {
      "role": "user",
      "content": "Hello, how are you?"
    }
  ],
  "conversation_id": "conv_123",
  "user": {
    "id": "user_456",
    "platform": "telegram",
    "name": "John Doe"
  },
  "bot": {
    "id": "bot_789",
    "name": "Support Bot"
  },
  "metadata": {
    "channel": "telegram",
    "chat_id": "123456789"
  }
}
```

### Messages Array

The `messages` array contains conversation history based on your configured context window:

```json theme={null}
"messages": [
  {
    "role": "user",
    "content": "What's the weather?"
  },
  {
    "role": "assistant",
    "content": "I'll check the weather for you."
  },
  {
    "role": "user",
    "content": "Thanks"
  }
]
```

This follows the OpenAI/Anthropic message format for easy integration.

## Expected Response

Your backend should return JSON with this structure:

```json theme={null}
{
  "content": "The response message to send to the user"
}
```

Or with metadata:

```json theme={null}
{
  "content": "The response message",
  "metadata": {
    "model": "gpt-4",
    "tokens": 150,
    "custom_field": "value"
  }
}
```

The `content` field is required. Everything else is optional and stored for your reference.

## Integration Types

### OpenAI Compatible

For OpenAI API or compatible services:

```
URL: https://api.openai.com/v1/chat/completions
Headers:
  Authorization: Bearer YOUR_API_KEY
  Content-Type: application/json
```

You'll need to transform the payload or use a proxy that accepts our format.

### Anthropic (Claude)

For Anthropic's API:

```
URL: https://api.anthropic.com/v1/messages
Headers:
  x-api-key: YOUR_API_KEY
  anthropic-version: 2023-06-01
```

Use a proxy to transform our payload to Anthropic's format.

### Custom Backend

For your own API:

```
URL: https://your-domain.com/api/chat
Headers:
  Authorization: Bearer YOUR_TOKEN
  X-Custom: value
```

Your backend receives our payload format and returns content as JSON.

## Fallback Integrations

Mark an integration as "fallback" to use it when the primary integration fails:

![Fallback integration](https://mintcdn.com/chatbotplatform/0mN6wehDmfoGG8-P/images/screenshots/02-integrations/08_fallback_integration.png?fit=max\&auto=format\&n=0mN6wehDmfoGG8-P\&q=85\&s=8e2542b680fe42611456abaf3217d627)

Fallback integration configuration

**Fallback behavior**:

1. Bot tries primary integration (highest weight)
2. If it times out or errors, tries fallback
3. If fallback also fails, sends error message to user

This provides reliability for production bots.

## Related Topics

> [card] [Webhook Setup](https://docs.chatbotplatform.io/bots/integrations/webhook-setup)
>
> Detailed webhook configuration guide

> [card] [A/B Testing](https://docs.chatbotplatform.io/bots/integrations/ab-testing)
>
> Compare multiple AI backends

> [card] [Custom Headers](https://docs.chatbotplatform.io/bots/integrations/custom-headers)
>
> Authentication and custom headers

## Testing Your Integration

Use the built-in test feature:

**1. Go to Integration**

Open the integration you want to test.

**2. Click Test**

Click the **Test** button.

**3. Send Test Message**

Enter a test message and submit.

**4. Review Response**

Check the response from your backend. Look for errors or unexpected behavior.

## Troubleshooting

### Timeout Errors

If requests timeout:

* Increase timeout value
* Optimize your backend for faster responses
* Check network connectivity

### Authentication Errors

If you get 401/403 errors:

* Verify API keys are correct
* Check header format
* Ensure headers include required authentication

### Invalid Response Format

If the bot can't parse responses:

* Ensure response is valid JSON
* Include required `content` field
* Check for encoding issues

## API Access

Manage integrations programmatically using the API.

> [accordion] Create an integration via API
>
> > [tab] cURL
> >
> > ```bash theme={null}
> > curl -X POST https://api.chatbotplatform.io/v1/bots/bot_123/integrations \
> >   -H "Authorization: Bearer YOUR_API_KEY" \
> >   -H "Content-Type: application/json" \
> >   -d '{
> >     "name": "OpenAI GPT-4",
> >     "webhook_url": "https://api.openai.com/v1/chat/completions",
> >     "headers": {
> >       "Authorization": "Bearer sk-...",
> >       "Content-Type": "application/json"
> >     },
> >     "timeout": 30,
> >     "weight": 1
> >   }'
> > ```
>
> > [tab] JavaScript
> >
> > ```javascript theme={null}
> > const response = await fetch('https://api.chatbotplatform.io/v1/bots/bot_123/integrations', {
> >   method: 'POST',
> >   headers: {
> >     'Authorization': 'Bearer YOUR_API_KEY',
> >     'Content-Type': 'application/json'
> >   },
> >   body: JSON.stringify({
> >     name: 'OpenAI GPT-4',
> >     webhook_url: 'https://api.openai.com/v1/chat/completions',
> >     headers: {
> >       'Authorization': 'Bearer sk-...',
> >       'Content-Type': 'application/json'
> >     },
> >     timeout: 30,
> >     weight: 1
> >   })
> > });
> > const data = await response.json();
> > ```
>
> > [tab] PHP
> >
> > ```php theme={null}
> > $response = Http::withToken('YOUR_API_KEY')
> >     ->post('https://api.chatbotplatform.io/v1/bots/bot_123/integrations', [
> >         'name' => 'OpenAI GPT-4',
> >         'webhook_url' => 'https://api.openai.com/v1/chat/completions',
> >         'headers' => [
> >             'Authorization' => 'Bearer sk-...',
> >             'Content-Type' => 'application/json'
> >         ],
> >         'timeout' => 30,
> >         'weight' => 1
> >     ]);
> >
> > $integration = $response->json();
> > ```
>
> > [tab] Python
> >
> > ```python theme={null}
> > response = requests.post(
> >     'https://api.chatbotplatform.io/v1/bots/bot_123/integrations',
> >     headers={'Authorization': 'Bearer YOUR_API_KEY'},
> >     json={
> >         'name': 'OpenAI GPT-4',
> >         'webhook_url': 'https://api.openai.com/v1/chat/completions',
> >         'headers': {
> >             'Authorization': 'Bearer sk-...',
> >             'Content-Type': 'application/json'
> >         },
> >         'timeout': 30,
> >         'weight': 1
> >     }
> > )
> > integration = response.json()
> > ```

> [accordion] List bot integrations
>
> > [tab] cURL
> >
> > ```bash theme={null}
> > curl https://api.chatbotplatform.io/v1/bots/bot_123/integrations \
> >   -H "Authorization: Bearer YOUR_API_KEY"
> > ```
>
> > [tab] JavaScript
> >
> > ```javascript theme={null}
> > const response = await fetch('https://api.chatbotplatform.io/v1/bots/bot_123/integrations', {
> >   headers: {
> >     'Authorization': 'Bearer YOUR_API_KEY'
> >   }
> > });
> > const { data } = await response.json();
> > ```
>
> > [tab] PHP
> >
> > ```php theme={null}
> > $response = Http::withToken('YOUR_API_KEY')
> >     ->get('https://api.chatbotplatform.io/v1/bots/bot_123/integrations');
> >
> > $integrations = $response->json('data');
> > ```
>
> > [tab] Python
> >
> > ```python theme={null}
> > response = requests.get(
> >     'https://api.chatbotplatform.io/v1/bots/bot_123/integrations',
> >     headers={'Authorization': 'Bearer YOUR_API_KEY'}
> > )
> > integrations = response.json()['data']
> > ```

> [accordion] Update an integration
>
> > [tab] cURL
> >
> > ```bash theme={null}
> > curl -X PATCH https://api.chatbotplatform.io/v1/integrations/int_123 \
> >   -H "Authorization: Bearer YOUR_API_KEY" \
> >   -H "Content-Type: application/json" \
> >   -d '{
> >     "timeout": 60,
> >     "weight": 2
> >   }'
> > ```
>
> > [tab] JavaScript
> >
> > ```javascript theme={null}
> > await fetch('https://api.chatbotplatform.io/v1/integrations/int_123', {
> >   method: 'PATCH',
> >   headers: {
> >     'Authorization': 'Bearer YOUR_API_KEY',
> >     'Content-Type': 'application/json'
> >   },
> >   body: JSON.stringify({
> >     timeout: 60,
> >     weight: 2
> >   })
> > });
> > ```
>
> > [tab] PHP
> >
> > ```php theme={null}
> > Http::withToken('YOUR_API_KEY')
> >     ->patch('https://api.chatbotplatform.io/v1/integrations/int_123', [
> >         'timeout' => 60,
> >         'weight' => 2
> >     ]);
> > ```
>
> > [tab] Python
> >
> > ```python theme={null}
> > requests.patch(
> >     'https://api.chatbotplatform.io/v1/integrations/int_123',
> >     headers={'Authorization': 'Bearer YOUR_API_KEY'},
> >     json={'timeout': 60, 'weight': 2}
> > )
> > ```

> [card] [Complete API Reference](https://app.chatbotplatform.io/openapi)
>
> View the full API specification with all endpoints, parameters, and response schemas.

## Next Steps

> [card] [Webhook Setup Guide](https://docs.chatbotplatform.io/bots/integrations/webhook-setup)
>
> Detailed setup instructions

> [card] [A/B Testing](https://docs.chatbotplatform.io/bots/integrations/ab-testing)
>
> Configure multiple integrations


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.