AI 音乐检测 API — 完整开发者指南 2026
如果您正在构建 DSP、分销商、A&R 提交平台,或任何需要以编程方式标记 AI 生成音乐的工具,您就需要一个 API。本指南将带您了解所有内容: 身份验证、端点、Python/Node/Java 代码示例、速率限制、响应格式、错误处理以及生产环境实用建议。
我们将使用 AI Song Checker REST API 作为代码示例的基础 — 它可以免费上手 (无需信用卡),支持所有主流 AI 音乐引擎 (Suno、Udio、Riffusion、ElevenLabs Music、MusicGen、Stable Audio),并返回包含置信度分数和平台归因的丰富 JSON 数据。
为什么要通过 API 集成而非使用界面
- 规模化: 每小时批量分析数千首曲目
- 自动化: 集成到提交工作流、目录审计、流媒体上传中
- 可定制: 构建您自己的仪表盘、告警机制、评分阈值
- 合规性: 为欧盟《AI 法案》水印要求生成审计日志
- 成本效益: 按调用付费优于雇佣人工审核员
快速上手 — 60 秒
- 在 aisongchecker.pro 免费注册 (仅需邮箱)
- 升级到 Pro 版 (4,99€/月) 以解锁 API 访问权限
- 前往 仪表盘 → API 并复制您的
ASC_API_KEY - 发起您的第一次调用 (见下方 Python 示例)
身份验证
所有 API 请求都在 Authorization 请求头中使用 HTTP Basic Auth 或 Bearer 令牌。推荐使用 Bearer:
Authorization: Bearer ASC_LIVE_xxxxxxxxxxxxxxxx
您的 API 密钥拥有对账户的完全访问权限 — 请将其保存在服务器端,切勿放入客户端 JS 或移动应用打包文件中。
端点概览
| 端点 | 方法 | 功能 |
|---|---|---|
/api/v1/analyze/file | POST | 上传音频文件,获取 AI 检测结果 |
/api/v1/analyze/url | POST | 分析 YouTube/Spotify/SoundCloud 链接 |
/api/v1/analyze/batch | POST | 一次调用提交多达 100 首曲目 |
/api/v1/result/{id} | GET | 获取异步批处理任务的结果 |
/api/v1/certificate/{id} | GET | 获取真实性证书 (PDF,已签名) |
/api/v1/usage | GET | 当前配额使用情况 + 速率限制状态 |
分析单个文件 — Python
import requests
API_KEY = "ASC_LIVE_your_key_here"
URL = "https://api.aisongchecker.pro/v1/analyze/file"
with open("track.mp3", "rb") as f:
response = requests.post(
URL,
headers={"Authorization": f"Bearer {API_KEY}"},
files={"audio": f},
data={"return_features": "true", "return_certificate": "true"},
)
result = response.json()
print(f"AI probability: {result['ai_probability']:.1%}")
print(f"Verdict: {result['verdict']}") # "ai" | "human" | "uncertain"
print(f"Most likely platform: {result['platform_attribution']['top']}")
print(f"Confidence: {result['confidence']:.2f}")
响应示例
{
"id": "asc_anl_2k3jX9pQmR8t",
"ai_probability": 0.967,
"verdict": "ai",
"confidence": 0.94,
"platform_attribution": {
"top": "suno",
"scores": {
"suno": 0.91,
"udio": 0.04,
"riffusion": 0.02,
"elevenlabs_music": 0.01,
"musicgen": 0.01,
"stable_audio": 0.01
},
"version_hint": "v5"
},
"watermarks": {
"c2pa_detected": true,
"synthid_detected": false,
"c2pa_signer": "suno.ai"
},
"features": {
"spectral_flatness_mean": 0.0182,
"phase_coherence_entropy": 2.41,
"mfcc_distance_baseline": 8.93,
"frame_similarity": 0.78
},
"engine_version": "ASC-v8.3",
"analyzed_at": "2026-05-22T18:42:11Z",
"certificate_url": "https://aisongchecker.pro/cert/asc_anl_2k3jX9pQmR8t.pdf"
}
分析一个 URL — Node.js
const fetch = require('node-fetch');
const result = await fetch('https://api.aisongchecker.pro/v1/analyze/url', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.ASC_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
return_features: false
})
}).then(r => r.json());
console.log(`AI: ${(result.ai_probability * 100).toFixed(1)}%`);
if (result.verdict === 'ai') {
console.log(`Platform: ${result.platform_attribution.top}`);
}
批量分析 — Java
import java.net.http.*;
import java.net.URI;
HttpClient client = HttpClient.newHttpClient();
String json = """
{
"tracks": [
{"id": "t1", "url": "https://soundcloud.com/artist/track-1"},
{"id": "t2", "url": "https://open.spotify.com/track/abc123"},
{"id": "t3", "url": "https://youtu.be/xyz789"}
],
"webhook_url": "https://your-app.com/asc-webhook"
}""";
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create("https://api.aisongchecker.pro/v1/analyze/batch"))
.header("Authorization", "Bearer " + System.getenv("ASC_API_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> res = client.send(req, HttpResponse.BodyHandlers.ofString());
// Returns: {"job_id": "asc_job_xyz", "status": "queued", "estimated_completion": "..." }
速率限制
| 套餐 | 请求数/分钟 | 请求数/天 | 批处理大小 |
|---|---|---|---|
| 免费版 | 10 | 50 | 1 |
| Pro | 60 | 5,000 | 100 |
| Business | 300 | 50,000 | 500 |
| Enterprise | 定制 | 无限制 | 定制 |
每次响应中都包含速率限制请求头:
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 47
X-RateLimit-Reset: 1716422400
错误处理
| HTTP 状态码 | 含义 | 应对措施 |
|---|---|---|
| 400 | 错误请求 (文件格式无效、URL 不受支持) | 检查输入,使用有效数据重试 |
| 401 | API 密钥无效 | 在仪表盘中检查密钥,若泄露则轮换 |
| 402 | 配额已耗尽 (免费版) | 升级套餐或等待重置 |
| 413 | 文件过大 (最大 50 MB) | 压缩音频 (仍可传入 MP3 320 kbps) |
| 429 | 触发速率限制 | 实现指数退避 (见下方) |
| 500/503 | 服务器错误 | 使用退避策略重试。我们提供 99.9% 的 SLA。 |
指数退避模式
import time, requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
session = requests.Session()
retries = Retry(
total=5, backoff_factor=2,
status_forcelist=[429, 500, 502, 503, 504],
allowed_methods=["POST"]
)
session.mount("https://", HTTPAdapter(max_retries=retries))
# Then use session.post(...) — auto retries with 2s, 4s, 8s, 16s, 32s
用于异步批处理任务的 Webhook
对于超过 10 首曲目的批处理,结果会通过 webhook 送达 (比轮询更快)。在批处理请求中配置 webhook_url。Webhook 载荷:
POST https://your-app.com/asc-webhook
Content-Type: application/json
X-ASC-Signature: t=1716422400,v1=abc123...
{
"event": "batch.completed",
"job_id": "asc_job_xyz",
"results": [
{ "id": "t1", "ai_probability": 0.97, "verdict": "ai", "platform": "suno" },
{ "id": "t2", "ai_probability": 0.04, "verdict": "human" },
{ "id": "t3", "ai_probability": 0.81, "verdict": "ai", "platform": "udio" }
],
"stats": { "processed": 3, "errors": 0, "duration_ms": 12450 }
}
请在服务器端使用您的 webhook 密钥,通过 HMAC-SHA256 验证 X-ASC-Signature 请求头 (与 Stripe webhook 采用相同方案)。
使用场景 — 真实示例
1. 流媒体平台 — 自动标记上传内容
在曲目上传时,异步调用 /analyze/file。如果 ai_probability > 0.85,则自动添加 "AI 生成" 标签 (符合欧盟《AI 法案》要求)。在元数据中标记 platform_attribution.top 以保证透明度。
2. A&R 提交筛选
类似 SubmitHub 的平台在每次 demo 上传时调用 API。ai_probability > 0.7 的曲目将获得人工审核优先级。为策划人节省数小时。
3. 音乐监制 — 授权尽职调查
在为影视授权曲目之前,先通过 /analyze/file 运行并申请签名证书 (HMAC-SHA256)。将证书附加到授权合同中,作为人类创作的证明。
4. 唱片公司目录审计
通过 /analyze/batch 提交您的历史目录 (1 万至 100 万首曲目)。获取一份可疑曲目的 CSV 报告以供人工审核。定价: Business 套餐下约每首曲目 $0.01。
可用的 SDK
- Python:
pip install aisongchecker· GitHub - Node.js:
npm install @aisongchecker/sdk· GitHub - Java: Maven 依赖,GitHub
- Go:
go get github.com/aisongchecker/go-sdk - Postman 集合: 从 /api-docs 导入
生产环境检查清单
- ☑️ API 密钥仅存储在服务器端 (环境变量或密钥管理器)
- ☑️ 对 429/5xx 采用指数退避
- ☑️ Webhook 签名验证 (HMAC-SHA256)
- ☑️ 按音频哈希缓存结果 (避免重复分析)
- ☑️ 高流量使用时设置
return_features=false(响应更小) - ☑️ 在仪表盘中监控
X-RateLimit-Remaining - ☑️ 幂等性: 传入您自己的
request_id以对重试进行去重