मुख्य कंटेंट पर जाएँ
API key पाएँ

गाइड · ऑडियो

पवित्र रिकॉर्डिंग चलाएँ

रिकॉर्डिंग वाली प्रविष्टि के लिए अस्थायी प्लेबैक URL माँगें।

यह रिक्वेस्ट सैंडबॉक्स में आज़माएँ

1 काम करने वाली रिक्वेस्ट भेजें

GET /v1/mantras/annapurna-aham-vaishvanaro-bhuthva/audio?format=json
curl "$MANTRILO_API_URL/v1/mantras/annapurna-aham-vaishvanaro-bhuthva/audio?format=json" \
  -H "Authorization: Bearer $MANTRILO_API_KEY"
प्लेसहोल्डर URL के साथ उदाहरण रिस्पॉन्स200 OK
{
  "data": {
    "url": "https://storage.example.com/signed-recording",
    "expiresAt": "2026-11-12T17:51:28.392Z",
    "bytes": 123077,
    "contentType": "audio/x-m4a"
  }
}

2 इसे अपने सर्वर से कॉल करें

key अपने बैकएंड में रखें और अपने ऐप को केवल कंटेंट लौटाएँ। यह Node.js सर्वर एक रूट देता है जिसे आपका ऐप कॉल कर सकता है।

server.mjs
// server.mjs · Node.js 22+
import { createServer } from 'node:http';

const apiKey = process.env.MANTRILO_API_KEY;
if (!apiKey) throw new Error('Set MANTRILO_API_KEY on your server.');
const base = process.env.MANTRILO_API_URL ?? "https://api.mantrilo.com";

async function mantrilo(path, input) {
  const response = await fetch(base + path, {
    method: input ? 'POST' : 'GET',
    headers: {
      Authorization: 'Bearer ' + apiKey,
      ...(input ? { 'Content-Type': 'application/json' } : {}),
    },
    ...(input ? { body: JSON.stringify(input) } : {}),
    signal: AbortSignal.timeout(20000),
    redirect: 'error',
  });
  const result = await response.json();
  if (!response.ok) throw Object.assign(new Error('Mantrilo request failed'), {
    status: response.status, requestId: result.requestId,
  });
  return result;
}

async function load(incoming) {
  return mantrilo("/v1/mantras/annapurna-aham-vaishvanaro-bhuthva/audio?format=json");
}

createServer(async (req, res) => {
  const incoming = new URL(req.url, 'http://localhost');
  res.setHeader('Content-Type', 'application/json');
  if (req.method !== 'GET' || incoming.pathname !== '/api/mantrilo-guide') {
    res.writeHead(404).end(JSON.stringify({ error: 'Not found' }));
    return;
  }
  try {
    const result = await load(incoming);
    res.end(JSON.stringify(result));
  } catch (error) {
    res.writeHead(error.status ?? 502).end(JSON.stringify({
      error: 'Could not load this content',
      requestId: error.requestId,
    }));
  }
}).listen(3000, '127.0.0.1');
आपके व्यू में
document.querySelector("audio").src = data.url; // Web player; on mobile use data.url as the audio source.

3 इनपुट और पेजिनेशन

मंत्र रिकॉर्ड से audio.href लें और उसमें ?format=json जोड़ें। अगर audio null है, तो प्लेयर छिपा दें। सादा endpoint सीधे रिकॉर्डिंग पर रीडायरेक्ट करता है। JSON मोड आपके बैकएंड को signed URL देता है।

data.url को अपने प्लेयर में पास करें और data.expiresAt के बाद नया लिंक माँगें। उदाहरण रिस्पॉन्स में एक्सपायर हो चुके signed URL की जगह प्लेसहोल्डर दिखाया गया है।

4 कोटा

हर सफल लिंक जारी करने में एक रिक्वेस्ट लगती है और फ़ाइल का पूरा आकार (बाइट में) ऑडियो कोटा से घटता है। प्लेयर में पहले से जारी URL पढ़ने पर Mantrilo API की कोई नई रिक्वेस्ट नहीं होती।

रिक्वेस्ट base URL को MANTRILO_API_URL से पढ़ती हैं। सर्वर उदाहरण में यह न मिलने पर https://api.mantrilo.com का उपयोग होता है।