Skip to content
Get API key

How to Generate a Kundli (Vedic Birth Chart) with an API

4 min read

Build a Janam Kundli feature: collect birth details, call a Kundli API for D1 and D9 charts, render the chart image and list planetary positions.

A Kundli, or Janam Kundli, is the Vedic birth chart: where the Sun, Moon, planets and the ascendant (lagna) stood at the moment and place of birth. It is the foundation of almost every Hindu astrology feature, from daily horoscopes to Dasha timelines to marriage matching.

Calculating one yourself means sidereal planetary positions, an ayanamsa, house division and divisional charts. A Kundli API gives you all of that from one request. In this tutorial you will collect a user's birth details, request the D1 (Rashi) and D9 (Navamsa) charts from Mantrilo, render the chart as an image and show a table of planetary positions.

Try it in one request

bash
curl https://api.mantrilo.com/v1/astrology/calculate \
  -H "Authorization: Bearer $MANTRILO_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{
    "operation": "chart",
    "birth": {
      "datetime": "1995-03-14T06:30:00+05:45",
      "latitude": 27.7172,
      "longitude": 85.3240,
      "timezone": "Asia/Kathmandu"
    }
  }'

By default Mantrilo returns the Lahiri D1 and D9 charts. The calculation lives in data.result.

No key yet? Get a free sandbox key and run the request above in under a minute.

What you'll build

  1. A birth form with date, time and place
  2. A server endpoint that resolves the place and requests the chart
  3. A rendered Kundli image
  4. A planet table showing sign, degree and house

Step 1: Collect birth details

You need three things from the user: date of birth, time of birth and place of birth. Ask for the place as a city name. Users rarely know their coordinates, and they almost never know their historical UTC offset.

Two tips that save support tickets later:

  • Ask "Do you know your exact birth time?" and store the answer. Charts are sensitive to time, and you can show a gentle note when the time is approximate.
  • Let users type the city, then confirm from a short list of matches. "Hyderabad" exists in India and in Pakistan.

Step 2: Resolve the place and build the birth object

First, a small helper that calls Mantrilo from your server. Every astrology operation goes through the same endpoint:

javascript
// server/mantrilo.js
export async function callMantrilo(body) {
  const res = await fetch("https://api.mantrilo.com/v1/astrology/calculate", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.MANTRILO_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(body),
  });
  const json = await res.json();
  if (!res.ok) throw new Error(json.error?.message || `HTTP ${res.status}`);
  return json.data.result;
}

The places operation returns coordinates and the IANA time zone for a city:

javascript
const places = await callMantrilo({ operation: "places", query: "Kathmandu", limit: 3 });

The birth object has strict rules, and they exist for accuracy:

  • datetime must include an explicit UTC offset, with seconds set to 00
  • latitude and longitude as numbers
  • timezone as an IANA name such as Asia/Kathmandu

The offset must be the one in force on the birth date, not today's. Kathmandu used +05:30 before 1986. Luxon applies the right historical rule for you:

javascript
import { DateTime } from "luxon";

function buildBirth({ date, time, place }) {
  const dt = DateTime.fromISO(`${date}T${time}`, { zone: place.timezone })
    .set({ second: 0, millisecond: 0 });
  return {
    datetime: dt.toISO({ suppressMilliseconds: true }),
    latitude: place.latitude,
    longitude: place.longitude,
    timezone: place.timezone,
  };
}

Births during a daylight saving change need one extra check: on the night clocks fall back, the same local time happens twice. Mantrilo rejects those ambiguous times rather than guessing, so ask the user whether the birth was before or after the change.

Step 3: Request the chart data

Keep your API key on your server and expose one endpoint:

javascript
// server/kundli.js
import express from "express";
const router = express.Router();

router.post("/api/kundli", async (req, res) => {
  try {
    const birth = buildBirth(req.body); // { date, time, place } from your form
    const chart = await callMantrilo({ operation: "chart", birth });
    res.json({ birth, chart });
  } catch (err) {
    res.status(400).json({ error: err.message });
  }
});

export default router;

callMantrilo is the helper from Step 2, so your key never leaves the server.

Step 4: Render the Kundli as an image

Drawing a North or South Indian chart by hand is fiddly. The chart-image operation returns a finished PNG, base64-encoded in data.imageBase64. Pass layout as north (the default), south or east to match the chart style your users expect:

javascript
async function getChartImage(birth) {
  const res = await fetch("https://api.mantrilo.com/v1/astrology/calculate", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.MANTRILO_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ operation: "chart-image", birth, layout: "north" }),
  });
  const json = await res.json();
  if (!res.ok) throw new Error(json.error?.message);
  return json.data.imageBase64;
}

Display it in React with a data URL:

javascript
function KundliImage({ base64 }) {
  return (
    <img
      src={`data:image/png;base64,${base64}`}
      alt="Vedic birth chart (D1)"
      width={480}
    />
  );
}

If you show the same chart often, decode it once and save the PNG to your own storage instead of requesting it on every view. A chart for fixed birth details never changes.

Step 5: Show the planetary positions

Most users want more than a picture. Under data.result, the chart lists each body with its sign and position. Log one real response, then map it into a table:

javascript
function PlanetTable({ planets }) {
  return (
    <table>
      <thead>
        <tr><th>Planet</th><th>Sign</th><th>Degree</th><th>House</th></tr>
      </thead>
      <tbody>
        {planets.map((p) => (
          <tr key={p.name}>
            <td>{p.name}</td>
            <td>{p.sign}</td>
            <td>{p.degree?.toFixed(2)}°</td>
            <td>{p.house}</td>
          </tr>
        ))}
      </tbody>
    </table>
  );
}

Show the D9 positions in a second tab. Many astrologers read the Navamsa alongside the Rashi chart, especially for marriage and strength of planets.

Going further

  • Add Dasha periods. Pass dashaLevels (1 to 3) with a referenceDate to get Vimshottari Mahadasha, Antardasha and Pratyantardasha.
  • Add matching. Two birth objects and the match operation give you a Guna Milan score.
  • Save the result. Store the chart with the user's profile. The same inputs always produce the same chart.

FAQ

Which ayanamsa does the Kundli API use? Lahiri, the most widely used ayanamsa in Indian astrology, by default.

Which divisional charts are included? D1 (Rashi) and D9 (Navamsa) by default. The divisions option lets you choose others where available; check the docs for the current list.

What if the user doesn't know their exact birth time? You can still calculate a chart, but the ascendant and houses may be wrong, since the lagna changes sign roughly every two hours. Mark these profiles as approximate.

Can I generate the chart image in the browser? Call your own server, which calls Mantrilo. Never expose your API key in client code.

Your first Kundli is one request away. Get a free sandbox key and browse every operation in the astrology docs.