AIWU Developer API
The AIWU Plugin offers developer-friendly APIs to build custom AI-powered experiences directly in your WordPress site. You can interact with AI models and chatbots via three different interfaces:
- Client-Side JavaScript API
- Public REST API
- PHP Helper Functions
This guide provides a full breakdown of each.
1. Client-Side API
The Client-Side API allows you to control chatbot behavior directly from the browser — no server-side setup required.
🔄 Event Listeners (JavaScript Filters)
You can modify chatbot replies or inject custom UI using the aiwuModifyReply
event.
Modify the response text:
document.addEventListener('aiwuModifyReply', function(event) {
let data = event.detail.original;
data.answer += ' For more information visit https://aiwuplugin.com/.';
event.detail.setResult(data);
});
Add a custom button to the chatbot reply:
document.addEventListener('aiwuModifyReply', function(event) {
let data = event.detail.original;
if (!data.btn) data.btn = [];
data.btn.push({
class: "waic-message-button my-custom-class",
link: "#",
name: "My custom button"
});
event.detail.setResult(data);
});
🔧 Public JS Methods
Use these methods to control the chatbot programmatically:
// Open the chatbot window
aiwuChatbot.openChatbot();
// Close the chatbot
aiwuChatbot.closeChatbot();
// Send a message to the chatbot
aiwuChatbot.askChatbot("Hi!");
If you have multiple chatbots on the page, you can pass the
botId
as the second argument.
2. Public REST API
The REST API allows server-to-server or headless integration with AIWU. It’s ideal for external applications or automation workflows.
⚠️ By default, access to these endpoints is restricted to WordPress administrators.
You can override this via theaiwu_allow_public_api
filter.
Endpoint: /wp-json/aiwu/v1/simple-text-query
Use this to send a direct prompt to the model.
Request:
POST https://yourdomain.com/wp-json/aiwu/v1/simple-text-query
Content-Type: application/json
Body:
{
"prompt": "Give me five facts about France.",
"options": { "tokens": 1500 }
}
Endpoint: /wp-json/aiwu/v1/ask-chatbot
Use this to send a message to a specific chatbot.
Request:
POST https://yourdomain.com/wp-json/aiwu/v1/ask-chatbot
Content-Type: application/json
Body:
{
"message": "Can you help me?",
"bot_id": 14,
"options": { "user_id": 1 }
}
3. PHP Helper Functions
Use these inside your plugin or theme to interact with AI models or chatbots without writing HTTP requests manually.
aiwuSimpleTextQuery( $prompt, $options = false )
Sends a prompt to the default model.
$response = aiwuSimpleTextQuery("Tell me a joke.");
You can optionally override default settings via $options
.
aiwuAskChatbot( $botId, $message, $options = false )
Sends a message to a specific chatbot instance.
$response = aiwuAskChatbot(14, "Hi there!", [
'user_id' => 1
]);
You can also use 'uniq'
in options to track custom sessions.
Customization & Access Control
🔐 aiwu_allow_public_api
Filter
If you want to allow public access to REST API endpoints for non-admin users, you can override the default behavior:
add_filter('aiwu_allow_public_api', '__return_true');
Use with caution.