Skip to content
Get API key

Guides · Audio

Play a sacred recording

Request a temporary playback URL for an entry with a recording.

Try this request in the sandbox

1 Make a working request

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"
Illustrative response with a placeholder URL200 OK
{
  "data": {
    "url": "https://storage.example.com/signed-recording",
    "expiresAt": "2026-11-12T17:51:28.392Z",
    "bytes": 123077,
    "contentType": "audio/x-m4a"
  }
}

2 Call it from your server

Keep the key in your backend and return only the content to your app. This Node.js server exposes one route your app can call.

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');
In your view
document.querySelector("audio").src = data.url; // Web player; on mobile use data.url as the audio source.

3 Inputs and pagination

Use audio.href from the mantra record and append ?format=json. If audio is null, hide the player. The plain endpoint redirects to the recording. JSON mode gives your backend the signed URL.

Pass data.url to your player, and request a fresh link after data.expiresAt. The example response substitutes a placeholder for the expired signed URL.

4 Quota

Each successful link issuance uses one request and charges the full file size in bytes against audio allowance. Reading the already issued URL in the player makes no new Mantrilo API request.

Requests read the base URL from MANTRILO_API_URL. The server example falls back to https://api.mantrilo.com.