Skip to main content
Broker Guides

How to Connect Zerodha for Algo Trading (Kite Connect Guide)

A practical guide to connecting Zerodha for algo trading with Kite Connect — app creation, API keys, the daily token refresh, safety, and troubleshooting.

BhavAI Research Team 8 min read

Zerodha is the broker most Indian retail algo traders start with, and Kite Connect is the official gateway for automating it. The API itself is well documented and reliable — but the setup involves a developer app, two credentials, and a daily re-authentication ritual that surprises almost everyone the first time.

This guide walks through the whole process: what Kite Connect is, what it can and cannot do, how to create your app, how to connect it to an algo platform like BhavAI, and how to handle the errors you will inevitably meet.

What is Kite Connect?

Kite Connect is Zerodha’s official trading API — a set of programmatic interfaces that let external software place, modify and cancel orders, read positions and holdings, and stream market data from your Zerodha account. It is the only sanctioned way to automate trading on Zerodha; a monthly API fee applies for order placement, and historical candle data is available as a separate add-on subscription.

“Official” is the key word. SEBI’s framework for retail algorithmic trading expects automation to flow through broker-provided APIs with proper controls, and Kite Connect is exactly that. Screen-scraping tools or session-hijacking scripts sit outside this framework and can get your account flagged — avoid them.

What you can and can’t do with Kite Connect

CapabilitySupported?Notes
Place, modify, cancel ordersYesEquity, F&O, currency and commodity segments enabled on your account
Read positions, holdings, marginsYesReal-time via API calls
Live market quotes and streamingYesWebSocket streaming for subscribed instruments
Historical candle dataYes, as an add-onSeparate subscription on top of the base API fee
Order update notificationsYesVia WebSocket and postback webhooks
Fully unattended loginNoYou must complete a Zerodha login once per day (see below)
Sharing one API app across many users’ accountsNoIndividual use is per-account; multi-client distribution needs separate approvals

The “no fully unattended login” row is the one that shapes your daily routine, so let’s address it head-on.

The daily login reality

Kite Connect uses short-lived access tokens. Each day, the previous day’s token becomes invalid, and generating a new one requires you to log in through Zerodha’s own login page — user ID, password and two-factor authentication. This is deliberate: it ensures that you, not a third-party server holding your password, authorize each day’s session.

For a self-hosted script, this means building a token-exchange flow and running it every morning before the market opens. Platforms handle it more gracefully: BhavAI, for example, prompts you with a one-tap “reconnect Zerodha” action each morning — you complete Zerodha’s login in a popup, and the platform exchanges the resulting request token for the day’s access token behind the scenes. Your password is entered only on Zerodha’s page, never on the platform.

Plan your routine around it: no valid token, no orders. If you run intraday strategies, re-authenticating before 9:15 AM should become as habitual as checking margin.

Prerequisites

Before connecting anything, you need:

  • An active Zerodha account with the segments you plan to trade (F&O requires activation).
  • A Kite Connect developer app, created at developers.kite.trade. This is where the monthly API fee applies.
  • Your API key and API secret, generated when the app is created.
  • A redirect URL for your app — the address Zerodha sends you back to after login. An algo platform will tell you exactly what to enter here.
  • Sufficient funds/margin in the account for whatever the strategy will trade.

Step-by-step: connect Zerodha to BhavAI

  1. Create the developer app. Sign in at developers.kite.trade with your Zerodha credentials, create a new Kite Connect app, and pay the API subscription. Give the app any name you like.
  2. Set the redirect URL. In the app settings, paste the redirect URL shown on the platform’s broker connection screen. This must match exactly — a trailing slash mismatch is the most common first-day error.
  3. Copy the API key and secret. Both are shown on the app’s detail page. Treat the secret like a password.
  4. Add the broker in the dashboard. Open the brokers section, choose Zerodha, and paste the API key and secret. They are encrypted at rest; the platform never sees or stores your Zerodha password.
  5. Complete the first login. Click connect — a Zerodha login window opens. Enter your credentials and 2FA on Zerodha’s page. On success you are redirected back and the connection shows as active.
  6. Re-authenticate daily. Each trading morning, tap the reconnect prompt and repeat the Zerodha login. It takes a few seconds.
  7. Deploy a strategy. Pick a strategy you have already backtested and paper traded, set its capital, product type and risk limits, and deploy. If you haven’t validated the strategy yet, stop here and read Backtesting vs Paper Trading first — connecting a broker is the last step of the pipeline, not the first.

If you are still choosing where that pipeline should live, our guide to the best algo trading platform in India lists the criteria that matter, broker handling included.

Order types and product types

Kite Connect exposes the same order and product types you see in the Kite app. The ones your strategies will use most:

TypeMeaningTypical use in algos
MISMargin Intraday Square-off — intraday product, auto squared-off by the broker near session closeIntraday strategies; higher leverage, forced exit
CNCCash and Carry — equity deliveryPositional/swing equity strategies
NRMLNormal — overnight F&O positionsPositional futures and options strategies
Market / Limit / SL / SL-MStandard order typesEntries, exits and stop losses

Two practical notes. First, MIS positions are squared off by the broker in the closing window whether your algo intended it or not — build your exits earlier than that. Second, make sure the product type your strategy deploys with matches your intent: deploying a swing strategy as MIS is a classic and expensive mistake.

Safety notes

  • Never share your API secret. Anyone with the key and secret pair can initiate the login flow for your app. Regenerate the secret immediately if you suspect exposure.
  • Your Zerodha password stays with Zerodha. A legitimate platform only ever handles the API key, secret and daily tokens. If any tool asks you to type your Zerodha password into its own interface, walk away.
  • Revoke access anytime. You can delete the app at developers.kite.trade or disconnect the broker inside your platform; either kills the automation instantly.
  • Use platform-level kill switches. Max daily loss, max open positions and max order size should be set before the first live order. Our risk management guide covers sensible defaults.

Troubleshooting common errors

“Token expired” / “Invalid session”. The most common error, and usually benign: the daily access token has lapsed. Re-run the login flow. If it recurs mid-session, check whether you logged into Kite Connect from another application — a fresh token from elsewhere can invalidate the current one.

Insufficient funds or margin. Order rejections citing margin mean the account balance cannot cover the order at current margin requirements — common when an F&O strategy scales up or when margins rise around events. Reduce position size in the strategy settings or add funds; the algo cannot fix this on its own.

Order rejected by RMS. Broker-side risk management can reject orders for many reasons: price outside circuit limits, a contract in ban period, an illiquid strike, or a stop-loss price on the wrong side of market price. The rejection message from Zerodha states the reason — read it verbatim in your platform’s order log rather than guessing.

Redirect URL mismatch during login. The URL registered in your developer app doesn’t exactly match what the platform sent. Copy-paste the URL again, character for character.

Orders fire but nothing appears in Kite. Check that you are looking at the same account and segment, and that the order wasn’t placed as AMO or rejected instantly. Every order attempt, successful or not, should appear in your platform’s logs with Zerodha’s response.

Where this fits in your automation journey

Connecting the broker is the mechanical part. The judgment lies in what you deploy through it. A sensible sequence — idea, backtest on NSE data, Monte Carlo validation, paper trading, then live deployment with small size — is covered end-to-end in how retail traders can automate trading. BhavAI compresses that sequence into one dashboard: describe the strategy in plain English or build it visually, validate it, then one-click deploy to Zerodha with the daily re-auth handled by a single tap. You can start free and connect a broker only when you’re ready to go live.

FAQ

Does Kite Connect cost money? Yes — a monthly API fee applies for the order-placement API, and historical data access is a separate add-on. Factor this into your total cost alongside any platform subscription.

Do I have to log in every single day? Yes. Access tokens expire daily by design, so a fresh Zerodha login is required each trading day. Good platforms reduce this to a one-tap prompt, but no legitimate tool can eliminate it entirely.

Is automating trades through Kite Connect legal in India? Yes. Kite Connect is Zerodha’s official API, and using it for your own account sits squarely within SEBI’s framework for retail algo trading through registered brokers.

Can I run multiple strategies through one Kite Connect app? Yes — one app and one daily token can serve several strategies on the same account. Just remember they share the same capital and margin pool, so set per-strategy limits accordingly.


Trading in securities involves risk of loss. Nothing in this article is investment advice; it is educational content. Always test strategies thoroughly before deploying real capital.

Put this into practice

Build and backtest your own strategy free — no coding, no card.

Start free
Free · No card

Create your account

25 free backtests on seven years of NSE data. We'll set you up and email your login.

By continuing you agree to our Terms and Privacy Policy.