How to get a Dhan (DhanHQ) API key

Dhan has no separate API key; your client id and an access token are enough.

About 5 minutes 3 steps Checked November 2026

Before you start

  • A Dhan account

Create your Dhan (DhanHQ) API key

  1. 1

    Open DhanHQ settings

    On web.dhan.co open your profile → Access DhanHQ APIs.

  2. 2

    Generate a token

    Create an access token and choose its validity.

  3. 3

    Store both

    Save DHAN_CLIENT_ID and DHAN_ACCESS_TOKEN.

Test the key

Before wiring the key into a strategy, make one request by hand. It separates “the key is wrong” from “my code is wrong”.

curl -s https://api.dhan.co/v2/fundlimit -H "access-token: $DHAN_ACCESS_TOKEN" -H "client-id: $DHAN_CLIENT_ID"
Your fund limits as JSON confirm the token.

Keep the credentials safe

  • Store values in a password manager or a git-ignored .env, never in code or notebooks you share.
  • In an AlgoGP project you can still add them under APIs & keys (encrypted at rest) and read them with strategy_runtime.secrets.get("DHAN_CLIENT_ID").
  • Give each bot its own credential so you can revoke one without stopping the others.
DHAN_CLIENT_ID=paste-your-value-here
DHAN_ACCESS_TOKEN=paste-your-value-here
.env for local runs

Design and backtest your Dhan (DhanHQ) strategy first

AlgoGP turns an idea into Python and tests it on years of history before you connect it to Dhan (DhanHQ). The exported code keeps the broker behind four small adapter methods.

  • AI copilot writes and revises the rules
  • Backtests with realistic costs
  • Exported Python ready to wire to Dhan (DhanHQ)

Free plan, no card required.

How the Dhan (DhanHQ) API works

AlgoGP is not affiliated with Dhan (DhanHQ). Menus get renamed from time to time; if a label differs, the official documentation has the current path.