PHP code example of kaaljyoti / sdk

1. Go to this page and download the library: Download kaaljyoti/sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kaaljyoti / sdk example snippets




use Kaaljyoti\Client;
use Kaaljyoti\Models\{Birth, CalculationOptions, KundliRequest};

Request(
    birth: new Birth(
        datetime: '1990-05-14T10:30:00', // wall clock at the birth place
        latitude: 28.6139,
        longitude: 77.209,
        timezone: 'Asia/Kolkata',
        place: 'New Delhi',
    ),
    options: new CalculationOptions(ayanamsa: 'lahiri', language: ['en']),
));

echo $answer->data->ascendantDms;          //  99°02'48.2"
echo $answer->data->lagnaSign->name;       //  Cancer
echo $answer->meta->timezone->source;      //  given

$signs = $kj->reference('signs', ['en', 'hi']);
// the list is joined into the one comma-separated parameter the API takes
echo $signs->data[0]['name'];        //  Aries
print_r($signs->meta->language);     //  ['en', 'hi'] — the labels you actually got

$zone = $kj->timezone(28.6139, 77.209);
echo "{$zone->data->name} {$zone->data->utcOffset}"; //  Asia/Kolkata +05:30

$sky = $kj->transit->events(new TransitEventsRequest(year: 2026, timezone: 'Asia/Kolkata'));
foreach ($sky->data->events as $event) {
    echo $event->local, ' ', $event->planet->id, ' ', $event->kind, "\n";
}

use Kaaljyoti\Models\{CalculationOptions, Disclaimer, HoroscopeRequest, KundliRequest, ReportLagnaRequest, VarshphalRequest};

$reading = $kj->reports->lagna(new ReportLagnaRequest(
    sign: 'leo',
    options: new CalculationOptions(language: ['en', 'hi']),
));
echo $reading->data->lagna?->entry->text->hi;
echo $reading->data->disclaimer?->en;
//  These predictions are indicative. For a reading of your own chart, consult an astrologer.

$lords = $kj->reports->houseLords(new KundliRequest(birth: $birth));
foreach ($lords->data->houseLords ?? [] as $lord) {
    // Twelve, in house order: the sign on the house, its lord, and the house the lord sits in.
    echo "{$lord->house}: {$lord->sign->name}, lord {$lord->lord->name} in {$lord->inHouse}\n"; // 1: Gemini, lord Mercury in 9
}

$week = $kj->horoscope(new HoroscopeRequest(
    sign: 'aries',
    period: 'weekly',          // daily (the default), weekly, monthly, yearly
    date: '2026-09-28',        // default today, in `timezone` (default Asia/Kolkata)
    options: new CalculationOptions(
        disclaimer: new Disclaimer(name: 'Acharya Amit Verma', url: 'https://kaaljyoti.com'),
    ),
));
echo "{$week->data->summary->level}: {$week->data->summary->text->en}\n";
foreach ($week->data->areas as $area) {
    // work, money, relationships, health, education — each favourable, mixed or care.
    echo "{$area->area} ({$area->level}): {$area->text->en}\n";
}

$dashas = $kj->reports->vimshottari(new KundliRequest(birth: $birth));
foreach ($dashas->data->periods as $period) {
    echo "{$period->lord->name} {$period->from} – {$period->to} ({$period->level})", $period->current ? ' ← now' : '', "\n";
}

$year = $kj->reports->varshphal(new VarshphalRequest(birth: $birth, year: 2026));
echo $year->data->summary->text->en, "\n";

use Kaaljyoti\Models\{HouseSystem, PdfKundliOptions, PdfKundliRequest};

$answer = $kj->pdf->kundli(new PdfKundliRequest(
    birth: $birth,
    name: 'Ravi Kumar',
    edition: 'professional',
    template: 'traditional',
    options: new PdfKundliOptions(language: ['en', 'hi'], houseSystem: HouseSystem::KP),
));
$file = $answer->data;

$file->bytes;      //  string — the PDF itself
$file->filename;   //  'kundli-ravi-kumar.pdf', from Content-Disposition
$file->credits;    //  1000, from X-KJ-Credits
$answer->cached;   //  true when the 24-hour cache answered: no PDF used, still 1,000 credits
$answer->creditsRemaining; //  what is left this month, packs 

$kundli = $kj->kundli;
$chart = $kundli->get(new KundliRequest(birth: $birth));

$answer = $kj->kundli->get(new KundliRequest(birth: $birth));

$answer->data;       //  the calculation, typed per endpoint
$answer->meta;       //  ayanamsa, timezone, engine, computeMs, languageFallback, credits
$answer->requestId;  //  'X-KJ-Request-Id' — quote it to support
$answer->plan;       //  the plan this answer was served under
$answer->cached;     //  true when the 24-hour cache answered. Costs the same credits.
$answer->credits;    //  'X-KJ-Credits' — what this request cost, as meta->credits says
$answer->creditsRemaining; //  'X-KJ-Credits-Remaining' — secret keys only
$answer->rateLimit;  //  RateLimit(limit, remaining, reset) — the bucket as it stands

use Kaaljyoti\KaaljyotiException;

try {
    $answer = $kj->kundli->get(new KundliRequest(birth: $birth));
} catch (KaaljyotiException $error) {
    match ($error->code()) {
        'validation_error' => $form->reject($error->field),  // 'birth.utc_offset'
        'quota_exceeded' => $this->askToUpgrade($error->docs),
        default => $log->warning("{$error->code()} {$error->status} {$error->requestId}"),
    };
    if ($error->isRetryable()) {
        $queue->later($error->retryAfter ?? 60, $job);
    }
}

$kj = new Client(apiKey: $apiKey, maxRetries: 0);

use Kaaljyoti\WallClock;

// A DateTime whose fields already are the clock at the place — a date and a
// time typed into a form. Written out as they stand:
WallClock::format(new DateTimeImmutable('1990-05-14 10:30:00'));
// '1990-05-14T10:30:00'

// An instant from anywhere else — a UTC database column, another API — turned
// into the clock that was on the wall at the place:
WallClock::fromDateTime(new DateTimeImmutable('1990-05-14T05:00:00Z'), 'Asia/Kolkata');
// '1990-05-14T10:30:00'

// The reverse, given meta.timezone.utcOffset from an answer:
WallClock::toDateTime('1990-05-14T10:30:00', '+05:30');
// DateTimeImmutable 1990-05-14T05:00:00+00:00

// The offset a zone was on at an instant, for birth.utcOffset:
WallClock::offsetAt(new DateTimeImmutable('1944-03-15T10:00:00Z'), 'Asia/Kolkata');
// '+06:30' — India's war time, not today's +05:30

$zone = $kj->timezone(28.6139, 77.209, '1944-03-15T10:00:00');
$zone->data->utcOffset; // '+06:30'

use Kaaljyoti\Models\{ChartStyle, KundliChartRequest};

// The document: metadata plus the markup in `data->svg`.
$document = $kj->kundli->chart(new KundliChartRequest(
    birth: $birth,
    style: ChartStyle::NORTH,
    size: 360,
));
$document->data->style;  //  'north'
$document->data->svg;    //  '<svg …'

// The markup itself. `data` is a string, and `meta` is null.
$svg = $kj->kundli->chartSvg(new KundliChartRequest(birth: $birth, size: 360));
echo $svg->data;

$moon = $kj->kundli->chart(new KundliChartRequest(birth: $birth, firstHouse: 'moon'));
$moon->data->firstHouseSign->id;  //  the Moon's sign, now house 1
$moon->data->title;               //  'Moon chart'

use Kaaljyoti\Models\{MatchBatchRequest, MatchBatchRequestPairsItem};

$answer = $kj->match->batch(new MatchBatchRequest(pairs: [
    new MatchBatchRequestPairsItem(bride: $brideBirth, groom: $groomBirth),
    new MatchBatchRequestPairsItem(bride: $brideBirth, groom: $otherBirth),
]));

foreach ($answer->data->results as $result) {
    if ($result->error !== null) {
        echo "pair {$result->index}: {$result->error->code} {$result->error->field}\n";
        continue;
    }
    echo "{$result->index}: {$result->data?->total} / 36\n";
}

$answer->meta->credits; //  what the request cost: one per pair

use Kaaljyoti\Http\CurlClient;

$kj = new Client(
    apiKey: $apiKey,
    httpClient: new CurlClient([CURLOPT_PROXY => 'http://proxy.internal:3128']),
);

use Kaaljyoti\Http\Psr18Client;

$kj = new Client(
    apiKey: $apiKey,
    httpClient: new Psr18Client($psr18Client, $requestFactory, $streamFactory),
);

use Kaaljyoti\Http\{HttpClient, HttpRequest, HttpResponse, TransportException};

final class WpHttpClient implements HttpClient
{
    public function send(HttpRequest $request): HttpResponse
    {
        $answer = wp_remote_request($request->url, [
            'method' => $request->method,
            'headers' => $request->headers,
            'body' => $request->body,
            'timeout' => $request->timeoutSeconds,
        ]);

        // A dead socket must throw, never come back as an invented status:
        // the SDK retries a transport failure on a different budget than a 500.
        if (is_wp_error($answer)) {
            throw new TransportException($answer->get_error_message());
        }

        return new HttpResponse(
            wp_remote_retrieve_response_code($answer),
            wp_remote_retrieve_headers($answer)->getAll(),
            wp_remote_retrieve_body($answer),
        );
    }
}

$kj = new Client(
    apiKey: $apiKey,
    timeoutSeconds: 10.0,
    maxRetries: 1,
);

$kj = new Client(apiKey: $publishableKey, headers: ['Origin' => 'https://example.com']);

$kj = new Client(
    apiKey: getenv('KAALJYOTI_TEST_KEY'), // a kj_test_… key
    baseUrl: 'https://api-staging.kaaljyoti.com',
);

$sun = $answer->data->positions['sun'];
$sun->sign->id;            //  'aries'  ← the stable half: switch on this
$sun->sign->name;          //  'Aries'  ← for people, in the first language you asked for
$sun->sign->names['hi'];   //  'मेष'    ← present when you asked for more than one