TutorialNext.js 14 App RouterJune 2026

Integrating a Vedic Astrology API in Next.js — Complete Guide with Code

This guide walks through integrating VedIntel™ AstroAPI into a Next.js 14 App Router project from zero to working feature — environment setup, server-side data fetching, client components, and real endpoint examples including planet positions, Lagna, Mahadasha, and Panchang.

Prerequisites

  • Next.js 14+ with App Router
  • A free VedIntel™ API key — get one here (500 calls/month, no credit card)
  • Birth data: date (DD/MM/YYYY), time (HH:MM 24hr), latitude, longitude, timezone offset

Step 1 — Environment Setup

Add your API key to .env.local. Never expose it to the browser:

.env.local
VEDINTEL_API_KEY=vai_pk_your_key_here
# Do NOT use NEXT_PUBLIC_ prefix — keep this server-side only

Step 2 — A Typed API Client

Create a small helper to call VedIntel endpoints. This runs server-side only:

lib/vedintel.ts
const BASE = 'https://vedintelastroapi.com/api/v1'
export interface BirthData {
dob: string // DD/MM/YYYY
tob: string // HH:MM (24hr)
lat: number // decimal degrees
lon: number // decimal degrees
tz: number // UTC offset (5.5 for IST)
lang?: string // default 'en'
}
export async function vedintel<T>(
endpoint: string, birth: BirthData
): Promise<T> {
const key = process.env.VEDINTEL_API_KEY!
const params = new URLSearchParams({
api_key: key, ...birth as Record<string, string>,
})
const res = await fetch(`${BASE}/${endpoint}?${params}`, {
next: { revalidate: 3600 } // cache 1 hour
})
const data = await res.json()
if (data.status !== 200) throw new Error(data.error)
return data.response as T
}

Step 3 — Fetch Planet Positions in a Server Component

app/chart/page.tsx
import { vedintel } from '@/lib/vedintel'
const birth = {
dob: '01/10/1977', tob: '11:40',
lat: 11, lon: 77, tz: 5.5
}
export default async function ChartPage() {
const planets = await vedintel<Record<string, Planet>>(
'horoscope/planet-details', birth
)
return (
<div>
<h1>Birth Chart</h1>
{Object.entries(planets).map(([id, p]) => (
<div key={id}>
{p.name}: {p.zodiac} {p.local_degree.toFixed(2)}°
— {p.nakshatra} pada {p.nakshatra_pada}
</div>
))}
</div>
)
}

Step 4 — Current Mahadasha

GET /api/v1/dashas/current-mahadasha
# curl example
curl "https://vedintelastroapi.com/api/v1/dashas/current-mahadasha?
api_key=YOUR_KEY&dob=01/10/1977&tob=11:40&lat=11&lon=77&tz=5.5"
// Response:
{
"status": 200,
"response": {
"mahadasha": { "name": "Jupiter", "start": "2017-08-...", "end": "2033-08-..." },
"antardasha": { "name": "Mercury", ... },
"pratyantardasha": { "name": "Ketu", ... }
},
"remaining_api_calls": 498
}

In a Next.js route handler, call this from an API route to avoid exposing your key, or use the server component pattern from Step 3 directly.

Step 5 — Panchang for Today

The Panchang endpoint uses a date parameter instead of dob/tob:

Panchang — today
const today = new Date().toLocaleDateString('en-GB', {
day: '2-digit', month: '2-digit', year: 'numeric'
}).replace(/\//g, '/')
const panchang = await fetch(
`https://vedintelastroapi.com/api/v1/panchang/panchang?
api_key=${key}&date=${today}&lat=12.97&lon=77.59&tz=5.5`
)
// Returns: tithi, nakshatra, yoga, karana, vara, sunrise, sunset

Caching Strategy

Natal chart data (planet positions, Lagna, divisional charts) is immutable — the same birth data always returns the same result. Cache aggressively:

  • Natal endpointsrevalidate: false (cache forever, or use force-cache)
  • Panchang / transitrevalidate: 3600 (hourly refresh is plenty)
  • Current dasharevalidate: 86400 (daily — dashas don't change intra-day)

116 Endpoints, Free Tier Available

VedIntel™ covers horoscope, divisional charts, dashas, doshas, Panchang, kundali matching, numerology, and AI interpretation — all from one API key. Free plan: 500 calls/month, no credit card.

Get Free API Key →Full API Reference
Related articles
Building a kundali matching feature — Guna Milan API guide →Why Swiss Ephemeris matters for accuracy →How we verified 71 calculations against Jagannatha Hora →