@Tradehull_Imran
I am currently integrating the Dhan API for automated trading and encountered an issue in the authentication workflow related to the TOTP verification and consent generation stage. I would appreciate your assistance in understanding and resolving the problem.
Environment Details
Client Platform: Python 3.12
Automation Framework: Playwright (browser automation)
TOTP Generation: pyotp library
Operating System: Windows 10
API Version: Dhan API v2 authentication flow
The login automation script is designed to perform the following sequence:
-
Generate consent URL through the API.
-
Navigate to the Dhan login page.
-
Enter mobile number and verify using TOTP.
-
Enter PIN for final authentication.
-
Capture authorization code and exchange it for an access token.
All environment variables including client_id, mobile number, TOTP secret, and PIN are correctly configured and validated before execution.
Observed Issue
During execution, the script repeatedly fails at the consent generation stage. The logs show the following response:
errorCode: CONSENT_LIMIT_EXCEED
errorMessage: Consent limit Exceeded
Below is the relevant portion of the execution logs:
2026-03-07 00:56:30 | Loaded env | client_id masked mobileno masked
2026-03-07 00:56:32 | LoginAttempt Starting attempt 1/2
2026-03-07 00:56:35 | GenerateConsent HTTP POST attempt 1/3
2026-03-07 00:56:37 | WARNING Consent limit exceeded Waiting 65 seconds before retry
2026-03-07 00:57:42 | GenerateConsent retry
2026-03-07 00:57:43 | WARNING Consent limit exceeded Waiting again
2026-03-07 00:58:48 | ERROR consentAppId missing payload errorCode CONSENT_LIMIT_EXCEED
2026-03-07 00:58:49 | Login failed reason consent_url_generation_failed
Because the consent URL is not generated, the authentication process cannot proceed further, and the access token is never created.
Troubleshooting Already Performed
To ensure the issue was not related to the local implementation, I performed the following checks:
-
Verified that the client_id and API configuration are correct.
-
Confirmed that the TOTP secret is valid and generating correct codes.
-
Tested multiple login attempts with sufficient delay between requests.
-
Implemented retry logic and exponential backoff for the consent API.
-
Ensured that the script is not generating parallel authentication requests.
-
Confirmed that the API payload format matches the documentation.
Despite these checks, the API consistently returns the consent limit exceeded response.
Clarifications Requested
Could you please help clarify the following points:
-
What is the exact rate limit or quota for the consent generation API endpoint?
-
Is the consent limit calculated per client_id, per user account, or per IP address?
-
How long should we wait before retrying once the consent limit is exceeded?
-
Is there any recommended authentication flow for automated trading systems using the Dhan API?
-
Are there any recent changes in the authentication or consent generation process that might affect automated login scripts?
Impact
This issue is preventing automated access token generation, which blocks the ability to run API based trading automation workflows.
If there are recommended best practices or alternative authentication mechanisms for automated systems, I would appreciate your guidance.
Please let me know if you require additional logs or debugging information from my side.
Thank you for your support.