API Reference

The AudioLib API allows you to fetch random audio tracks from curated libraries. It follows REST conventions and returns JSON responses.

API base URL

https://api.audiolib.ai

Quick Start

Get a playable audio URL in one request.

cURL

bash
curl -X POST https://api.audiolib.ai/v1/audio \
  -H "Authorization: Bearer alp_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"library":"audio.focus"}'

JavaScript

javascript
const res = await fetch('https://api.audiolib.ai/v1/audio', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer alp_your_api_key',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ library: 'audio.focus' }),
})

const json = await res.json()
const url = json.data?.url
if (url) new Audio(url).play()

Authentication

All API requests require a Bearer token in the Authorization header. Generate API keys from your dashboard.

http
Authorization: Bearer alp_your_api_key_here

Key format: API keys begin with alp_ followed by 32 random characters. Keys are shown only once upon creation. Store them securely.

Endpoints

MethodEndpointDescription
POST/v1/audioFetch a random audio track from a library

Request Format

Send a JSON body with the library field set to a library's standard name.

FieldTypeRequiredDescription
librarystringYesThe standard name of the library (e.g. "audio.ambient")
json
{
  "library": "audio.ambient"
}

Response Format

Success responses use a standard envelope. Audio fields are in data.

json
{
  "code": 0,
  "msg": "ok",
  "data": {
    "title": "Deep Space Drift",
    "url": "https://cdn.example.com/audio/track.mp3",
    "duration_sec": 240
  }
}

Error Codes

HTTP StatusError CodeDescription
401MISSING_AUTHAuthorization header is missing or malformed
401INVALID_KEY_FORMATAPI key does not match expected format (alp_...)
401INVALID_KEYAPI key is invalid, inactive, or revoked
400INVALID_JSONRequest body is not valid JSON
400MISSING_LIBRARYThe library field is missing from the request body
404LIBRARY_NOT_FOUNDNo library found with the given name
404NO_AUDIO_ITEMSThe library has no active audio items
429QUOTA_EXCEEDEDFree plan enforced monthly limit of successful audio API calls reached; response includes limit (resets each UTC calendar month)
503PRESIGN_FAILEDTemporary URL could not be generated (storage/signing error)
500INTERNAL_ERRORAn unexpected server error occurred
json
{
  "error": "Library 'audio.unknown' not found",
  "code": "LIBRARY_NOT_FOUND"
}

Examples

cURL

bash
curl -X POST https://api.audiolib.ai/v1/audio \
  -H "Authorization: Bearer alp_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"library":"audio.sleep"}'

JavaScript (fetch)

javascript
const response = await fetch('https://api.audiolib.ai/v1/audio', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer alp_your_api_key',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ library: 'audio.focus' }),
})

const json = await response.json()
console.log(json.data.url) // Play this URL

Python (requests)

python
import requests

response = requests.post(
    'https://api.audiolib.ai/v1/audio',
    headers={'Authorization': 'Bearer alp_your_api_key'},
    json={'library': 'audio.ambient'}
)

data = response.json()
print(data['data']['url'])