Delete a sample.
A sample can only be deleted if:
Sample reference (name, UUID, or sample object)
Optionalsignal: AbortSignalOptional AbortSignal
void on success, or an Error
Download a sample's audio file.
If the sample is still processing, this will wait until it's ready.
Sample reference (name, UUID, or sample object)
Optionaloptions: { format?: SampleFormat }Download options
Optionalformat?: SampleFormatAudio format to download.
Optionalsignal: AbortSignalOptional AbortSignal to cancel the download
The audio file as a Blob, or an Error
Get metadata for a single sample.
Sample reference (name, UUID, or sample object)
Optionalsignal: AbortSignalOptional AbortSignal
The sample metadata, or an Error if not found
List samples with optional filtering and pagination.
Optionaloptions: SampleListOptionsList options including filters and pagination
Optionalsignal: AbortSignalOptional AbortSignal
List result with samples and pagination token
Upload a new sample. Returns immediately with pending metadata and a promise that resolves when processing completes.
The upload flow:
Important: If you stop uploading a file without proper cleanup, your user will have their rate limit reduced by 1 slot until the upload is cancelled automatically, which happens only within 24 hours.
Make sure that you either wait for an upload to complete, or cancel the upload.
In browsers: Pass preventTabClose: true to prompt the user with a
confirmation dialog if they try to close the tab while the upload is in
progress.
In Node.js/Bun/Deno: There's no automatic cleanup mechanism. You should handle process signals yourself:
const controller = new AbortController()
process.on("SIGINT", () => controller.abort())
process.on("SIGTERM", () => controller.abort())
const upload = await at.samples.upload({
file: audioBuffer,
displayName: "My Sample",
}, controller.signal)
Upload options including the file and metadata
Optionalsignal: AbortSignalOptional AbortSignal to cancel the upload
Sample metadata with uploaded and ready promises
const upload = await at.samples.upload({
file: audioFile,
displayName: "My Sample",
})
if (upload instanceof Error) throw upload
// Wait until bytes are safely on the server.
const err = await upload.uploaded
if (err instanceof Error) throw err
You can insert a sample into a document before upload.ready resolves by
decoding local audio duration and passing a plain object to
document.TransactionBuilder.insertSample. If that object omits bpm, the
project BPM from config is used (fallback 120 if no config exists).
async function readLocalDurationSeconds(file: Blob): Promise<number> {
const context = new AudioContext()
try {
const decoded = await context.decodeAudioData(await file.arrayBuffer())
return decoded.duration
} finally {
await context.close()
}
}
const upload = await at.samples.upload({ file, displayName: "My Sample", bpm: 120 })
if (upload instanceof Error) throw upload
const durationSeconds = await readLocalDurationSeconds(file)
await nexus.modify(t => {
t.insertSample({
name: upload.name,
durationSeconds,
// bpm optional
})
})
High-level API for working with samples. Handles the complexity of uploads, downloads, and metadata management.
Example: Upload a sample
Example: Download a sample
Example: List and search samples