Authentication
Secure API key management
API Key Types
GET /sandbox/*
Use the separate keyless sandbox for fixed examples. Production API keys are paid, with one exception: accounts that have never paid can start a 14-day Professional trial with $5 of API credit from Plans & billing ($60 a month from day 14 unless you cancel).
vk_live_*
For production. Real calculations. Pay-per-use billing.
Basic Authentication
// server-client.cjs
const { VedikaClient } = require('@vedika-io/sdk');
function createVedikaClient() {
const apiKey = process.env.VEDIKA_API_KEY;
if (!apiKey) {
throw new Error('Configure VEDIKA_API_KEY in the server environment.');
}
return new VedikaClient({ apiKey });
}
module.exports = { createVedikaClient };
Calling the REST API directly instead of the SDK? Send the key as Authorization: Bearer <key>. The older X-API-Key header still works until 18 January 2027, then it stops. New code should use Authorization: Bearer. Calls that still use X-API-Key get Deprecation and Sunset response headers, so you can find them in your own logs.
Environment Variables Setup
Create a .env file in your project root:
# Configure VEDIKA_API_KEY in your server's protected environment first.
# Export the existing variable without assigning or revealing its value.
export VEDIKA_API_KEY
.env to your .gitignore file to prevent accidentally committing your API key.
Framework-Specific Setup
Node.js with dotenv
import 'dotenv/config';
import { VedikaClient } from '@vedika-io/sdk';
const vedika = new VedikaClient({ apiKey: process.env.VEDIKA_API_KEY });
Next.js
// .env.local: configure VEDIKA_API_KEY privately on the server.
import { VedikaClient } from '@vedika-io/sdk';
const vedika = new VedikaClient({ apiKey: process.env.VEDIKA_API_KEY });
export async function POST(request) {
// Enforce your application's authenticated-user and input rules first.
const { birthDetails } = await request.json();
return Response.json(await vedika.getBirthChart(birthDetails));
}
Vite / React (Browser Proxy)
async function fetchChart(birthDetails) {
const response = await fetch('/api/astrology/chart', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ birthDetails })
});
if (!response.ok) {
throw new Error('Chart request failed.');
}
return response.json();
}
Security Best Practices
DO: Use environment variables
Store API keys in environment variables, not in code.
DO: Keep keys server-side
Never expose API keys in client-side JavaScript. Use backend proxies.
DO: Rotate keys regularly
Regenerate keys periodically and after any suspected compromise.
DON'T: Commit keys to git
Add .env to .gitignore immediately.
DON'T: Share keys publicly
Never share API keys in forums, GitHub issues, or support tickets.
Backend Proxy Pattern
For frontend apps, mount the backend route behind your application authentication, rate limits and input validation:
// chart-handler.cjs — your application server
const { VedikaClient, VedikaAPIError } = require('@vedika-io/sdk');
async function handleChart(req, res) {
try {
const apiKey = process.env.VEDIKA_API_KEY;
if (!apiKey) {
throw new Error('Configure VEDIKA_API_KEY in the server environment.');
}
const vedika = new VedikaClient({ apiKey });
const chart = await vedika.getBirthChart(req.body.birthDetails);
res.json(chart);
} catch (error) {
const status = error instanceof VedikaAPIError
&& Number.isInteger(error.statusCode)
&& error.statusCode >= 400 && error.statusCode <= 599
? error.statusCode : 500;
res.status(status).json({ error: 'Chart request failed.' });
}
}
module.exports = { handleChart };
async function fetchChart(birthDetails) {
const response = await fetch('/api/astrology/chart', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ birthDetails })
});
if (!response.ok) {
throw new Error('Chart request failed.');
}
return response.json();
}
Key Management
Manage your API keys in the Vedika Dashboard:
- Create: Generate new API keys
- Rotate: Regenerate existing keys
- Revoke: Delete compromised keys
- Monitor: Track usage per key
Testing Authentication
import { VedikaClient, AuthenticationError } from '@vedika-io/sdk';
try {
const vedika = new VedikaClient({ apiKey: process.env.VEDIKA_API_KEY });
console.log('Client constructed; server key validity is not checked.');
} catch (error) {
if (!(error instanceof AuthenticationError)) throw error;
console.error('Configure a server-side API key.');
}