---
name: kimaai_admin_assistant_before_request
type: action
since: 1.5.0
tier: free
feature: admin-assistant
area: admin-assistant
summary: Fires before the admin assistant sends a request to the AI provider.
parameters:
  - name: ai_payload
    type: array
    description: The request to the provider, after kimaai_admin_assistant_ai_payload.
  - name: payload
    type: array
    description: The normalised request payload, with prompt, postId, lang, chatbot_settings, sessionId, assistantSurface (admin_assistant), assistantAllowedRenderables, assistantUserId and selectedTools.
  - name: settings
    type: array
    description: The admin assistant's runtime settings.
surfaces: [admin_assistant]
---

# kimaai_admin_assistant_before_request

## When it fires

Right after `kimaai_admin_assistant_ai_payload`, once the request is prepared and before it runs. It fires for answers that stream and for those that do not, and also for the buttons of the setup workflows and the quick actions, whose callbacks often answer without the provider. It does not fire for a message sent again within 15 seconds, which gets the stored answer.

The action cannot change the request; use `kimaai_admin_assistant_ai_payload` for that. `$payload['assistantUserId']` is the administrator who asked. Pair it with `kimaai_chatbot_after_response` and `kimaai_chatbot_error`, which fire for the admin assistant too, to time or count the requests.

The admin assistant is not released yet: its panel and its routes are switched off in this release, so these requests are not sent.

## Example

```php
add_action(
  'kimaai_admin_assistant_before_request',
  function (array $ai_payload, array $payload): void {
    // How often each administrator asks the assistant, for your own report.
    $user_id = (int) $payload['assistantUserId'];
    $count = (int) get_user_meta($user_id, 'my_assistant_requests', true);
    update_user_meta($user_id, 'my_assistant_requests', $count + 1);
  },
  10,
  2
);
```

## Related

- `kimaai_admin_assistant_ai_payload`: changes the request before this action.
- `kimaai_chatbot_after_response`: fires after the answer, with `assistantSurface` `admin_assistant`.
- `kimaai_chatbot_before_request`: the same action for the chatbot.
