[GH-ISSUE #4973] [Feature]: Add a parameter of the used traffic in API #3493

Closed
opened 2026-10-31 20:32:50 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @moonshinem on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4973

When viewing the panel, you can find out how many GB of traffic is used out of the limit. At the same time, the API returns only the limit, without the amount of traffic spent.

Describe the solution you'd like

Client information API returns this:

{
"success": true,
"msg": "",
"obj": {
"client": {
"totalGB": 132070244352,
"usedGB": 2147483648,
}

Alternatives you've considered

Concrete use case

I need to transmit the values of the used traffic and the traffic limit in the Happ subscription, but I can't receive it correctly from the API because the API doesn't transmit it.

Mockups, screenshots, or examples

Current api returns:

{
    "success": true,
    "msg": "",
    "obj": {
        "client": {
            "id": 94,
            "email": "123",
            "subId": "123",
            "uuid": "123",
            "password": "",
            "auth": "123",
            "flow": "xtls-rprx-vision",
            "security": "auto",
            "limitIp": 0,
            "totalGB": 132070244352,
            "expiryTime": 0,
            "enable": true,
            "tgId": 123,
            "group": "",
            "comment": "",
            "reset": 0,
            "createdAt": 1780070335614,
            "updatedAt": 1780669258451,
            "reverse": null
        },
        "inboundIds": [
            1,
            12,
            16,
            19,
            20
        ]
    }
}

And you can add the usedGB option:

{
    "success": true,
    "msg": "",
    "obj": {
        "client": {
            "id": 94,
            "email": "123",
            "subId": "123",
            "uuid": "123",
            "password": "",
            "auth": "123",
            "flow": "xtls-rprx-vision",
            "security": "auto",
            "limitIp": 0,
            "totalGB": 132070244352,
            "usedGB": 123123123123,
            "expiryTime": 0,
            "enable": true,
            "tgId": 123,
            "group": "",
            "comment": "",
            "reset": 0,
            "createdAt": 1780070335614,
            "updatedAt": 1780669258451,
            "reverse": null
        },
        "inboundIds": [
            1,
            12,
            16,
            19,
            20
        ]
    }
}

Which parts of the panel would this affect?

Backend (API endpoints, login, settings)

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @moonshinem on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4973 ### Is your feature request related to a problem? When viewing the panel, you can find out how many GB of traffic is used out of the limit. At the same time, the API returns only the limit, without the amount of traffic spent. ### Describe the solution you'd like Client information API returns this: { "success": true, "msg": "", "obj": { "client": { "totalGB": 132070244352, **"usedGB": 2147483648,** } ### Alternatives you've considered ### Concrete use case I need to transmit the values of the used traffic and the traffic limit in the Happ subscription, but I can't receive it correctly from the API because the API doesn't transmit it. ### Mockups, screenshots, or examples Current api returns: ``` { "success": true, "msg": "", "obj": { "client": { "id": 94, "email": "123", "subId": "123", "uuid": "123", "password": "", "auth": "123", "flow": "xtls-rprx-vision", "security": "auto", "limitIp": 0, "totalGB": 132070244352, "expiryTime": 0, "enable": true, "tgId": 123, "group": "", "comment": "", "reset": 0, "createdAt": 1780070335614, "updatedAt": 1780669258451, "reverse": null }, "inboundIds": [ 1, 12, 16, 19, 20 ] } } ``` And you can add the usedGB option: ``` { "success": true, "msg": "", "obj": { "client": { "id": 94, "email": "123", "subId": "123", "uuid": "123", "password": "", "auth": "123", "flow": "xtls-rprx-vision", "security": "auto", "limitIp": 0, "totalGB": 132070244352, "usedGB": 123123123123, "expiryTime": 0, "enable": true, "tgId": 123, "group": "", "comment": "", "reset": 0, "createdAt": 1780070335614, "updatedAt": 1780669258451, "reverse": null }, "inboundIds": [ 1, 12, 16, 19, 20 ] } } ``` ### Which parts of the panel would this affect? Backend (API endpoints, login, settings) ### Are you willing to help? - [ ] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Jun 5, 2026):

Thanks for the clear write-up and example JSON!

Workaround available right now

There is already a dedicated endpoint that returns the traffic counters for a client:

GET /panel/api/clients/traffic/:email

It returns a ClientTraffic object with these fields (all byte values):

{
  "id": 12,
  "inboundId": 1,
  "enable": true,
  "email": "123",
  "uuid": "...",
  "subId": "...",
  "up": 500000000,
  "down": 1647483648,
  "total": 132070244352,
  "expiryTime": 0,
  "reset": 0,
  "lastOnline": 1780669258000
}

Used traffic in bytes = up + down.
(Note: totalGB in the /get response and total here are both stored in bytes despite the totalGB field name.)

The enhancement

The feature request here is to fold those traffic counters into the GET /panel/api/clients/get/:email response so one call returns everything. That is a reasonable convenience improvement — right now you need two calls: one to /get/:email for configuration and one to /traffic/:email for usage stats.

Concretely, what would need to change:

  • In web/controller/client.go → get handler: after fetching the ClientRecord, also call inboundService.GetClientTrafficByEmail(email) and include the result (or just the computed sum up+down) in the response object.
  • The ClientRecord model itself (in database/model/model.go) does not store traffic — it would be enriched at the handler level, similar to how inboundIds is already appended to the same response today.

If you'd like to open a PR, the relevant handler is at web/controller/client.go lines 103–122.

<!-- gh-comment-id:4632655202 --> @github-actions[bot] commented on GitHub (Jun 5, 2026): Thanks for the clear write-up and example JSON\! ## Workaround available right now There is already a dedicated endpoint that returns the traffic counters for a client: ``` GET /panel/api/clients/traffic/:email ``` It returns a `ClientTraffic` object with these fields (all byte values): ```json { "id": 12, "inboundId": 1, "enable": true, "email": "123", "uuid": "...", "subId": "...", "up": 500000000, "down": 1647483648, "total": 132070244352, "expiryTime": 0, "reset": 0, "lastOnline": 1780669258000 } ``` Used traffic in bytes = **`up + down`**. (Note: `totalGB` in the `/get` response and `total` here are both stored in **bytes** despite the `totalGB` field name.) ## The enhancement The feature request here is to fold those traffic counters into the `GET /panel/api/clients/get/:email` response so one call returns everything. That is a reasonable convenience improvement — right now you need two calls: one to `/get/:email` for configuration and one to `/traffic/:email` for usage stats. Concretely, what would need to change: - In `web/controller/client.go` → `get` handler: after fetching the `ClientRecord`, also call `inboundService.GetClientTrafficByEmail(email)` and include the result (or just the computed sum `up+down`) in the response object. - The `ClientRecord` model itself (in `database/model/model.go`) does **not** store traffic — it would be enriched at the handler level, similar to how `inboundIds` is already appended to the same response today. If you'd like to open a PR, the relevant handler is at `web/controller/client.go` lines 103–122.
Author
Owner

@MHSanaei commented on GitHub (Jun 12, 2026):

Implemented in d1a13844. The client-get endpoint now returns the consumed bytes alongside the record:

{ "obj": { "client": {...}, "inboundIds": [...], "usedTraffic": 123456789 } }

usedTraffic is up+down in bytes (same unit as totalGB) and includes cross-node usage in multi-node setups, so you can pair it directly with the quota for the Happ subscription headers. It''s a sibling key rather than a field inside client to keep the stored model unchanged. Will be in the next release.

<!-- gh-comment-id:4688344851 --> @MHSanaei commented on GitHub (Jun 12, 2026): Implemented in d1a13844. The client-get endpoint now returns the consumed bytes alongside the record: { "obj": { "client": {...}, "inboundIds": [...], "usedTraffic": 123456789 } } `usedTraffic` is up+down in bytes (same unit as totalGB) and includes cross-node usage in multi-node setups, so you can pair it directly with the quota for the Happ subscription headers. It''s a sibling key rather than a field inside `client` to keep the stored model unchanged. Will be in the next release.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3493
No description provided.