---
name: kimaai_chatbot_response_payload
type: filter
since: 1.3.5
tier: free
feature: chatbot
area: chatbot
summary: Changes the JSON answer of a chatbot request that does not stream.
parameters:
  - name: response
    type: array
    description: The JSON answer, with message, session_id, sessionId, history and, when there are any, renderables and sources.
  - name: ai_payload
    type: array
    description: The request to the provider, after kimaai_chatbot_ai_payload.
  - name: payload
    type: array
    description: The normalised request payload, with prompt, sessionId and chatbot_settings among others, and assistantSurface (admin_assistant or search) outside the chat.
  - name: chatbot_settings
    type: array
    description: The chatbot settings, or the admin assistant's in its requests.
returns:
  type: array
  description: The JSON answer to send.
surfaces: [chatbot, admin_assistant, search]
---

# kimaai_chatbot_response_payload

## When it fires

Only when the answer does not stream: after the provider answered and the answer was saved, right before `kimaai_chatbot_after_response` and before the JSON goes back with status 200. A streamed answer has no JSON body to filter, so the filter does not run then; use `kimaai_chatbot_final_message` for the answer text on both paths. It does not run for an error either, nor for a quick action whose callback answers without the provider.

The chatbot, the admin assistant and the search answer share this request runner, so the filter fires for all three; `$payload['assistantSurface']` is `admin_assistant` or `search` outside the chat. KimaAI's widget reads `message`, `sessionId`, `history` and `renderables`: add keys of your own for a client of your own, and leave those as they are unless you mean to change what the widget shows. The search answer box builds its answer, and the cached copy, from the filtered response.

## Example

```php
add_filter(
  'kimaai_chatbot_response_payload',
  function (array $response, array $ai_payload): array {
    // A headless front end shows which model answered.
    $response['model'] = (string) ($ai_payload['aiModel'] ?? '');

    return $response;
  },
  10,
  2
);
```

## Related

- `kimaai_chatbot_after_response`: fires after the answer, streamed or not.
- `kimaai_chatbot_final_message`: changes the answer text on both paths.
