Integration with API
Waterflai API Documentation
This comprehensive guide explains how to integrate your Waterflai chatbots with external applications using our API. You'll learn how to manage API keys, understand different endpoints, handle various content types, and implement best practices for integration.
API Overview
Waterflai provides different API endpoints based on your chatbot type:
Simple Chatbots: OpenAI-compatible endpoint for basic chat interactions
Dream Builder (Chatflows): Specialized endpoints for complex conversational flows
Workflow Builder: Dedicated endpoints for automated workflow execution
Managing API Keys
API keys are essential for authenticating your requests to the Waterflai API. Here's how to manage them:
Viewing API Keys
In the Studio page, click the "API Keys" button
A modal will open, displaying a list of your existing API keys
Each key shows its name and the actual key value
Creating a New API Key
Click the "API Keys" button, then select "New API Key" from the dropdown
In the Create API Key modal:
Enter a name for your new key
Click "Create API Key"
The new key will be displayed. Copy it immediately, as you won't be able to see it again
Important: Store your API key securely. It won't be displayed again after you close the modal.
Deleting an API Key
In the API Keys list, click the trash icon next to the key you want to delete
Confirm the deletion in the popup
Note: Deleting an API key will immediately revoke access for any applications using that key.
API Endpoints
Dream Builder (Chatflow) Endpoints
Execute Chatflow
Endpoint:
POST https://api.waterflai.ai/execute_chatflow/{chatflow_id}/execute
Purpose: Execute a chatflow and receive the complete response
Headers:
Request Body (option 1: string message):
Response Format:
Stream Execute Chatflow
Endpoint:
POST https://api.waterflai.ai/execute_chatflow/{chatflow_id}/stream_execute
Purpose: Execute a chatflow with real-time streaming updates (adequat for long time execution flows)
Headers: Same as non-streaming endpoint
Request Body: Same as non-streaming endpoint
Response: Server-Sent Events (SSE) stream with the following events:
Workflow Builder Endpoints
Execute Workflow
Endpoint:
POST https://api.waterflai.ai/execute_workflow/{workflow_id}/execute
Purpose: Execute a workflow and receive the complete response
Headers: Same as chatflow endpoints
Request Body (option 1: string message):
Response: JSON object containing workflow execution results
Stream Execute Workflow
Endpoint:
POST https://api.waterflai.ai/execute_workflow/{workflow_id}/stream_execute
Purpose: Execute a workflow with streaming updates
Headers: Same as non-streaming endpoint
Request Body: Same as non-streaming endpoint
Response: SSE stream with execution updates
Content Types and Message Handling
Text Messages
For simple text messages, use a string directly:
Image Messages
For messages containing images, use the multimodal content format with base64-encoded images:
Mixed Content Messages
You can combine multiple content types in a single message:
File Handling
Text Files
Upload text files using base64-encoded data with metadata:
Examples:
Image Files
Two options for image files:
Base64-encoded data:
Direct URL:
Code Examples
Python
JavaScript
Best Practices
Security
Store API keys securely and never expose them in client-side code
Regularly rotate API keys
Monitor API usage for suspicious activity
Performance
Use streaming endpoints for real-time updates (and for long duration flow execution to avoid Timeout error)
Implement proper timeout handling
Cache responses when appropriate
Troubleshooting
Common Issues
Authentication Errors
Verify API key is valid and active
Check Authorization header format
Verify proper encoding of the Authorization header
Request Format Errors
Validate JSON structure
Verify required fields are present
Ensure proper encoding of special characters
File Upload Issues
Check file format support
Ensure proper base64 encoding
Validate file metadata format
Last updated