Getting a Kite Connect API key takes ten minutes. The part that catches everyone is that the access token expires every day at 6 AM. Here's how to handle both.
Step 1: Get your API key
- Sign up at developers.kite.trade/signup. This is separate from your normal Kite login.
- Choose a plan:
| Plan | Cost | What you get |
|---|---|---|
| Personal | Free | Place orders, view positions, holdings and funds |
| Connect | ₹500/month | Everything above, plus live and historical market data |
- Go to My Apps → Create New App and fill in your app name, Zerodha Client ID and a redirect URL (
http://127.0.0.1:8000works for personal use). - You'll get an API key and API secret. Keep the secret private, like a password.
Step 2: Understand the daily token
| Credential | Lasts |
|---|---|
| API key and secret | Until you regenerate them |
| Access token | Until 6 AM the next day |
Every API call needs a valid access token, so you need a new one each trading day.
Step 3: Refresh the token each morning
By hand:
- Open
https://kite.zerodha.com/connect/login?v=3&api_key=YOUR_API_KEYand log in. - Copy the
request_tokenfrom the URL you're redirected to. - Exchange it for an access token:
from kiteconnect import KiteConnect
kite = KiteConnect(api_key="YOUR_API_KEY")
data = kite.generate_session("REQUEST_TOKEN", api_secret="YOUR_API_SECRET")
kite.set_access_token(data["access_token"])
Automatically:
Most people script the login so they don't have to do it every morning. The script generates your 2FA code from your TOTP secret (using the pyotp library), completes the login, grabs the request_token and exchanges it as above. Schedule it to run every weekday before market open.
Stay safe
- Never share or publish your API secret, password or TOTP secret. Anyone with them can access your account.
- Keep secrets out of your code and out of any public repository.
- Have a manual backup. Automated logins can break if Zerodha changes its login page.