When it fires
In every chatbot request and every search answer that is not served from the cache, after the gate and before the message length is checked. KimaAI counts the answered messages per IP address and day: the request goes on while today’s count is below the limit, and counts once its answer is saved. At the limit the visitor gets an error with status 400 and kimaai_chatbot_rate_limited fires.
The filter changes the limit for this request only, not the stored setting: return a higher number for some visitors, or 0 to let nobody through. A value that is not a whole number is cast, and anything below 0 counts as 0. KimaAI’s evaluation runner (wp kimaai eval), wp kimaai chat and the MCP tool that asks the chatbot lift the limit for their own requests through this filter.
Parameters
| Name | Type | Description |
|---|---|---|
max_messages | int | The daily limit of the chatbot settings. |
payload | array | The normalised request payload, with prompt, postId, postSection, lang, sessionId and chatbot_settings, and assistantSurface in a search answer. |
user_ip | string | The visitor’s IP address, as KimaAI resolves it (see kimaai_trusted_proxies). |
Returns
int: The limit for this request; KimaAI makes it an integer of at least 0.
Example
add_filter(
'kimaai_chatbot_daily_message_limit',
function (int $max_messages, array $payload, string $user_ip): int {
// Customers who are logged in get more messages a day.
return is_user_logged_in() ? max($max_messages, 100) : $max_messages;
},
10,
3
);
Related
kimaai_chatbot_rate_limited: fires when a visitor reaches the limit.kimaai_trusted_proxies: the proxies whose forwarded address counts as the visitor’s.