Skip to main content
Every Soundpiece request follows the same three steps:
  1. Submit the request. You get back an operation id and status: "processing".
  2. Wait until status is ready or failed, by polling the same endpoint (or by receiving a webhook).
  3. Download the audio from the signed URL in the result.
This guide generates a song from lyrics and a prompt, using the reference client to do the waiting and retrying for you.

Step 1: Get your API key

API keys are issued from your account dashboard, under Developer → API keys. A key is shown once, when you create it, so save it somewhere safe. Keys start with spk_; the prefix is part of the key. Put the key in an environment variable, so it never appears in your code:
Anyone with your key can use your account. Never put it in code that runs in a browser or a mobile app. If a key is exposed, revoke it from the dashboard and create a new one. See Authentication.

Step 2: Save the reference client

Copy the file for your language from The reference client into a new folder:
  • Python: save it as soundpiece.py, then run pip install requests.
  • JavaScript: save it as soundpiece.mjs. It needs Node.js 18 or later and nothing else.

Step 3: Generate a song

Save this program next to the client and run it. Generating a song usually takes a minute or two.
run returns the finished song object. It looks like this:
  • id identifies the operation. You can poll it again later with GET /v1/create.new_song?id=....
  • idempotency_key is the key the client sent with your request. Sending the same key again returns this same operation instead of starting new work; see keeping a key across re-runs.
  • outputs has one entry per variation. Set n_variations (1 to 3) in the request for more.
  • url is a signed download link for a FLAC file (44.1 kHz). It needs no API key, and stops working at expires_at. Poll the operation again for a fresh one.
If the song can’t be made, run raises a SoundpieceError carrying the result’s error.code and error.message; see Errors.

Next steps

The same pattern works for every endpoint. Swap the endpoint name and the request body: Each endpoint has a guide with a complete example, its result, its errors and its cost; follow the links in the table. The exact fields are in the API Reference, e.g. create.new_song (submit). Before you go to production, work through the production checklist.