AI Music Detection in Node.js — SDK Tutorial

Published May 22, 2026 · 9 min read · AI Song Checker team

Integrate AI music detection into Node.js / TypeScript apps in under 10 minutes. This tutorial covers install, auth, file/URL analysis, batch processing, and Express integration.

Installation

npm install @aisongchecker/sdk
# or yarn add @aisongchecker/sdk
# or pnpm add @aisongchecker/sdk

Authentication

import { Client } from '@aisongchecker/sdk';

const client = new Client({ apiKey: process.env.ASC_API_KEY });

Analyze a file

import fs from 'fs';

const result = await client.analyzeFile({
  file: fs.createReadStream('./track.mp3'),
  returnFeatures: false,
});

console.log(`AI: ${(result.aiProbability * 100).toFixed(1)}%`);
console.log(`Verdict: ${result.verdict}`);
console.log(`Engine: ${result.platformAttribution.top}`);

Analyze a URL

const result = await client.analyzeUrl({
  url: 'https://www.youtube.com/watch?v=xyz',
  returnCertificate: true,
});

if (result.verdict === 'ai') {
  console.log(`Certificate: ${result.certificateUrl}`);
}

Batch processing with webhooks

const batch = await client.analyzeBatch({
  tracks: [
    { id: 't1', url: 'https://soundcloud.com/.../track1' },
    { id: 't2', url: 'https://open.spotify.com/track/abc' },
  ],
  webhookUrl: 'https://your-app.com/asc-webhook',
});

console.log(`Job: ${batch.jobId}`);

Express middleware example

import express from 'express';
import multer from 'multer';
import { Client } from '@aisongchecker/sdk';

const app = express();
const upload = multer({ dest: '/tmp', limits: { fileSize: 50 * 1024 * 1024 } });
const asc = new Client({ apiKey: process.env.ASC_API_KEY });

app.post('/check', upload.single('audio'), async (req, res) => {
  try {
    const result = await asc.analyzeFile({ file: fs.createReadStream(req.file.path) });
    res.json({
      isAI: result.verdict === 'ai',
      probability: result.aiProbability,
      engine: result.platformAttribution.top,
    });
  } catch (err) {
    res.status(500).json({ error: err.message });
  }
});

app.listen(3000);

Webhook verification

import crypto from 'crypto';

function verifyWebhook(rawBody, signature, secret) {
  const [tsPart, sigPart] = signature.split(',');
  const ts = tsPart.split('=')[1];
  const sig = sigPart.split('=')[1];

  const payload = `${ts}.${rawBody}`;
  const expected = crypto.createHmac('sha256', secret).update(payload).digest('hex');

  return crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
}

app.post('/asc-webhook', express.raw({ type: 'application/json' }), (req, res) => {
  const sig = req.headers['x-asc-signature'];
  if (!verifyWebhook(req.body.toString(), sig, process.env.ASC_WEBHOOK_SECRET)) {
    return res.sendStatus(401);
  }
  const event = JSON.parse(req.body);
  // Process results...
  res.sendStatus(200);
});

Production patterns

Related