# Provide topic count via Discourse AI tool API \`discourse.getUser\` function

**URL:** https://meta.discourse.org/t/provide-topic-count-via-discourse-ai-tool-api-discourse-getuser-function/394878
**Category:** Feature
**Tags:** ai
**Created:** [February 1, 2026, 1:23pm UTC](https://meta.discourse.org/t/provide-topic-count-via-discourse-ai-tool-api-discourse-getuser-function/394878 "2026-02-01T13:23:04Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![per1234](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/per1234/32/569645_2.png) [@per1234](https://meta.discourse.org/u/per1234)
#### Post date: [February 1, 2026, 1:23pm UTC](https://meta.discourse.org/t/provide-topic-count-via-discourse-ai-tool-api-discourse-getuser-function/394878/1 "2026-02-01T13:23:04Z")

</div>

### Feature description:

Add a key to the object returned by the Discourse AI tool API `discourse.getUser` function that provides the number of topics created by the user.

### Current behavior:

Additional capabilities can be provided to Discourse AI personas by creating custom “[tools](https://meta.discourse.org/t/ai-bot-custom-tools/314103)” for the LLM to utilize. Discourse provides [an API](https://github.com/discourse/discourse/blob/7e603d43745b42777b6b718bc882aebaaf0a1711/plugins/discourse-ai/lib/ai_tool_scripts/preamble.js) that can be used in the tool code.

Data about a user account can be obtained via [the `discourse.getUser` function](https://github.com/discourse/discourse/blob/7e603d43745b42777b6b718bc882aebaaf0a1711/plugins/discourse-ai/lib/ai_tool_scripts/preamble.js#L134-L137).

The object returned by the function has a `post_count` key. It turns out that, in the context of user stats, “post” actually means “reply”. Thus, the value of this key does not include the number of original posts of topics created by the user.

It would make sense to provide the data for these two distinct types of activity via two separate keys, but inexplicably the function does not return topic count data even though this is one of the primary user stats.

🙁 A complete picture of user activity can not be obtained via the `discourse.getUser` function. It will be inconvenient or infeasible to obtain this information via other means.

#### Reproducible steps:

1. Log into a forum where you have admin privileges.
2. Navigate to the **Admin \> Plugins \> AI \> Tools** page (`/admin/plugins/discourse-ai/ai-tools`).
3. Click the “ **+ New tool** ” button.  
A menu will open.
4. Select “ **Start from blank…** ” from the menu.  
The page for configuration of a new tool will open.
5. Enter any values into the following fields on the page:
  - **Name**
  - **Tool Name**
  - **Description**
  - **Summary**

6. Enter the following code into the “ **Script** ” field:

```javascript
function invoke() {
  return discourse.getUser(-1);
}

```

**ⓘ** User ID `-1` was selected arbitrarily as likely to be present on any forum. Any other user ID or username can be passed to `discourse.getUser` if you prefer.
7. Click the “ **Save** ” button at the bottom of the page.
8. Click the “ **Run test** ” button at the bottom of the page.  
The “ **Test AI tool** ” dialog will open.
9. Click the “ **Run test** ” button in the dialog.

🙁 The test result does not provide the number of topics created by the user.

### Discourse version:

`f8f53ac5e8e4348ae308fcddc078766463d5e5f3`

### Additional context:

I am aware that I can get this information from the `/user-badges/{username}/summary.json` endpoint of the [Discourse API](https://meta.discourse.org/t/discourse-rest-api-documentation/22706), and that API requests can be made via the [`http.get` function](https://github.com/discourse/discourse/blob/7e603d43745b42777b6b718bc882aebaaf0a1711/plugins/discourse-ai/lib/ai_tool_scripts/preamble.js#L30-L35) of the tool API. It is not feasible to do this because the `hide_new_user_profiles` site setting is enabled on the forum I manage, and thus the endpoint for new users is only accessible for authenticated requests. So it would be necessary to store an API key in the tool code in order to utilize the API. I will not do that.

---

_[View the full topic](https://meta.discourse.org/t/provide-topic-count-via-discourse-ai-tool-api-discourse-getuser-function/394878)._
