How to add AI audio generation to your product with an API

November 23, 2026

An AI audio generation API returns generated music or sound effects to your application over HTTP. The Stable Audio 3.0 API exposes three endpoints: text-to-audio, audio-to-audio and inpaint. Each takes a prompt over multipart form data, returns a job ID immediately, and delivers 44.1 kHz stereo MP3 or WAV on polling for 8 credits.

Key takeaways

  • Every Stable Audio 3.0 endpoint is asynchronous, so your integration needs a polling loop and somewhere to hold a 64-character generation ID.

  • Stems come from tags written into the prompt string rather than from a parameter, because the API has no stem field to set.

  • Stability documents no loop parameter and no loop-point output, which leaves loop handling to your own pipeline.

  • The hosted API and the open weights name the same controls differently, so audio-to-audio and inpaint code needs its fields renamed before it moves between the two.

How a Stable Audio 3.0 API request works

Generation starts with a POST and finishes with a GET. Stable Audio 3.0 accepts multipart/form-data at api.stability.ai, authenticated with a bearer API key in the Authorization header. Text-to-audio sits at /v2beta/audio/stable-audio/text-to-audio, and the model field defaults to stable-audio-3, the only value that endpoint accepts.

The response to that POST is not audio. Stability's API answers with HTTP 202 and a JSON body containing a 64-character generation id, and the file arrives later. An accept header of audio/* returns raw bytes on retrieval, while application/json returns base64 inside a JSON envelope.

Two limits shape the request layer. Prompts cap at 10,000 characters, and the endpoint is rate limited to 150 requests per 10 seconds, with a 60-second timeout once you cross it. Requests can also fail before any audio exists. A 403 means content moderation blocked the job and you were not charged, and a 422 means the classifier rejected it, for a reason such as a non-English prompt, per the Stability AI text-to-audio API reference.

The polling loop, and what comes back in the headers

Retrieval runs against one endpoint. GET /v2beta/audio/results/{id} answers 202 with a status of in-progress while the job runs, and 200 with the audio once it finishes. Stability's own cURL sample retries after 10 seconds, a sensible floor given the rate limit.

Headers carry the metadata worth logging. A raw-bytes response returns x-request-id, a content-type of audio/mpeg or audio/wav, a finish-reason of SUCCESS, and the seed used for the generation. Those last two move into the JSON body when you ask for application/json, so a client reading them from headers will find them missing after someone changes an accept header.

Results do not sit on Stability's servers indefinitely. A 404 from the results endpoint means the generation does not exist or has expired, and the documentation publishes no retention window, so retrieve promptly and store the file yourself.

Read more: Stability AI fetch audio result reference

The three endpoints and what each one needs

Your entry point depends on whether you already have audio. Text-to-audio builds a clip from a prompt alone. Audio-to-audio takes a file plus a prompt and moves the whole thing. Inpaint takes a file and regenerates only the region between two timestamps.

Input constraints are identical across the two endpoints that accept a file: MP3 or WAV, between 6 and 380 seconds long, inside a request of no more than 100 MB. That six-second floor matters if your product sends short user recordings, which need padding before the API will take them.

The parameters that differ are the ones to read twice. Audio-to-audio uses strength on a 0 to 1 scale, where 0 returns the input unchanged and 1 behaves as though no audio had been supplied. Inpaint uses mask_start and mask_end, both in seconds, defaulting to 30 and 380, so leaving those defaults in place regenerates almost the entire file.

Stable Audio 3.0 endpoints. Retrieved 23 November 2026.

Endpoint Path Required fields Distinctive parameters Input audio
Text-to-audio /v2beta/audio/stable-audio/text-to-audio prompt None beyond the shared set Not accepted
Audio-to-audio /v2beta/audio/stable-audio/audio-to-audio prompt, audio strength, 0 to 1, default 1 MP3 or WAV, 6 to 380 seconds
Inpaint /v2beta/audio/stable-audio/inpaint prompt, audio mask_start default 30, mask_end default 380 MP3 or WAV, 6 to 380 seconds

How to generate stems through the API

No stem parameter exists. Part-level output comes from the prompt text, so a request for an isolated instrument is an ordinary text-to-audio call with tags written at the front of the prompt string. TrackType: Instrument asks for a single part rather than a full arrangement, VocalType: Instrumental pushes toward more coherent output, and Format: Duo asks for two instruments together. Genre can be repeated inside one prompt, and Instruments takes a list, as set out in the Stable Audio 3.0 prompting guide.

Alignment is the constraint that decides your architecture. Separately generated parts are independent renders with no shared arrangement, and the released models expose no key or pitch conditioning, so two calls carrying the same stated BPM will not reliably stack. Products that need layers to fit together generate one bed first and derive further parts from it with audio-to-audio. Strength decides how much of the bed carries over: values near 0 return it almost unchanged, and values near 1 discard it, so a mid-range value is the place to start testing.

Prompt tags are strings, with one practical consequence for your code. The API does not validate the tag vocabulary, so a misspelled tag returns audio rather than a 400. Tag construction belongs in a tested helper.

Read more: AI music stems and audio inpainting: generating parts instead of finished songs

What the API does for loops, and what it leaves to you

Loop handling is your pipeline's job. Stability's API reference defines no loop parameter, the prompt guide defines no loop tag, and nothing in the response carries loop points or a bar count. What comes back is a clip of the duration you asked for, which may or may not repeat cleanly.

Products shipping loop libraries need a post-processing step of their own. Trimming to a musical length derived from the BPM you wrote into the prompt, snapping the edit to a zero crossing, and crossfading the tail into the head all sit in your code rather than in the API.

The inpaint endpoint does cover extension, a different problem that often gets grouped with looping. Setting mask_start at the current length of the file and asking for a longer duration continues the audio instead of replacing part of it, so a 20-second clip masked from 20 seconds comes back longer.

Parameters that change the output: duration, steps, cfg_scale and seed

Four parameters carry shared behavior across all three endpoints, and the defaults are not neutral.

duration accepts 1 to 380 seconds and defaults to 190. Omit it and you get a three-minute clip for the same 8 credits a five-second one costs, so set it explicitly on every call. Stability's own description puts the ceiling at six minutes while the schema allows 380 seconds, a gap to test against before you rely on the top of the range.

steps accepts 4 to 8 and defaults to 8 on Stable Audio 3.0, a far narrower window than the 30 to 100 available on the older stable-audio-2 model. cfg_scale accepts 1 to 25 and defaults to 1, with higher values holding output closer to the prompt.

seed decides whether your product can reproduce anything. The default of 0 means random, and Stability's prompt guide states that the model will not output the same thing twice without a seed set. Capturing the returned seed on every generation costs nothing and is the only route back to a result a user liked.

Hosted API or open weights: what changes in your code

Moving between the two is not a configuration change. Audio-to-audio is the clearest case. The API takes strength and the open weights take init_noise_level. Both run from 0 to 1 in the same direction: lower values keep more of the input, and 1 ignores it entirely. Stability’s guidance for init_noise_level runs from 0.3 for a light touch to 0.9 for substantial change.

The repository also documents one capability the API schema does not, since both of its mask parameters accept lists, so several disconnected regions regenerate in a single call.

Model access differs as well. Stable Audio 3.0 Large, at 2.7 billion parameters, ships through the API rather than as open weights. Medium, at 1.4 billion parameters, needs a CUDA GPU and Flash Attention 2, and the small checkpoints run on CPU at 433 million parameters with a 120-second ceiling, per the Stable Audio 3 repository model table. Deployment trade-offs are covered in self-hosted vs API deployment explainer.

What changes between deployment routes. Retrieved 23 November 2026.

What you are setting Hosted API Open weights
Audio-to-audio amount strength, 0 to 1, where 0 leaves the input unchanged init_noise_level, guidance 0.3 to 0.9
Inpaint region mask_start, mask_end inpaint_mask_start_seconds, inpaint_mask_end_seconds
Several regions in one call Not in the published schema Documented, both parameters accept lists
Maximum duration 380 seconds 380 seconds on Medium, 120 on the small models
Largest model available Large, 2.7B parameters Medium, 1.4B parameters
Hardware Stability's CUDA GPU for Medium, CPU for small
Cost model 8 credits per successful generation Your own compute

Constraints to design around before you ship

Five constraints decide product fit, and audio quality is not among them.

Output is instrumental. Stable Audio 3.0 produces music and sound effects without singing or lyrics, though vocal textures appear occasionally and function as a pad or a hook.

Generation is offline and per-request. Medium returns 380 seconds of audio in 1.31 seconds on an H200, fast enough to sit behind a button in your interface and nowhere near buffer-rate synthesis inside an audio thread. Runtime playback stays your engine's responsibility.

Output is 44.1 kHz stereo, so any pipeline running at 48 kHz needs a resample step before the file reaches your mixer. Prompts are English, and a prompt in another language can come back as a 422 carrying an invalid_language classification rather than audio.

Licensing depends on the route. Calls to the hosted API run under Stability’s API terms and are billed per generation in credits. Self-hosting the open weights falls under the Stability AI Community License, which is free for organizations under $1M in annual revenue and requires attribution, including a prominent “Powered by Stability AI” notice. Above that threshold, an Enterprise license applies. What a platform may pass on to its own users is covered in the generative audio API for apps explainer.

Frequently asked questions about AI audio generation APIs

How do I generate audio with the Stable Audio 3.0 API? Send a multipart/form-data POST to /v2beta/audio/stable-audio/text-to-audio at api.stability.ai with a bearer API key and a prompt field. The endpoint returns HTTP 202 and a 64-character generation id. Poll GET /v2beta/audio/results/{id} until it answers 200, then read the audio from the response body.

Is the Stable Audio API synchronous, or does it return a job? The Stable Audio 3.0 endpoints are asynchronous. Each POST returns a generation ID with HTTP 202 rather than audio, and retrieval happens at a separate results endpoint. Stability's sample code polls every 10 seconds. Hold the job ID in your own queue, because the result expires and a late poll returns 404.

How much does one API call cost? Stable Audio 3.0 costs 8 credits per successful generation, a flat rate across the endpoints, and one credit is worth $0.01. Failed generations are not charged, including requests blocked at moderation. A five-second clip and a 380-second clip cost the same, so short-form features carry the same unit economics as long ones.

Can I generate stems through the API? Yes, through the prompt rather than a parameter. Starting a prompt with TrackType: Instrument raises the odds of an isolated part rather than a full arrangement, and Format: Duo asks for two instruments. Parts generated in separate calls are independent renders, so expect to align them yourself or derive them from a single bed with audio-to-audio.

Can I generate seamless loops with an AI audio API? Not directly. Stability's API reference defines no loop parameter and the response carries no loop points, so the API returns a clip rather than a loop. Trimming to a musical length, snapping to a zero crossing and crossfading the ends are steps your own pipeline performs on the returned file.

Can I get the same audio back twice? Only with a seed. The seed parameter defaults to 0, which means random, and Stability's prompt guide states that the model will not output the same thing twice by default. Every successful generation returns the seed it used, in a response header or in the JSON body, so capture it if users need to return to a result.

How long can a generated clip be? The API schema accepts a duration between 1 and 380 seconds and defaults to 190. Stability's prose describes the ceiling as about six minutes, slightly below the 380 seconds the schema allows, so test the top of the range before depending on it. Open-weights Medium matches 380 seconds and the small models stop at 120.

What sample rate and file formats does the API return? Stable Audio 3.0 returns 44.1 kHz stereo audio as MP3 or WAV, set with the output_format parameter, which defaults to mp3. Game engines and video pipelines running at 48 kHz need a resample step. An accept header of application/json returns the same audio base64-encoded alongside the seed and finish reason.

Can I run Stable Audio 3.0 on my own servers instead of the API? Yes, for the open-weights models. Medium at 1.4 billion parameters needs a CUDA GPU and Flash Attention 2, and the two small checkpoints run on CPU with a 120-second maximum. Stable Audio 3.0 Large is available through the API rather than as open weights, and parameter names differ between the two routes.

Does the API generate vocals? No. Stable Audio 3.0 produces instrumental music and sound effects with no singing or lyrics. Vocal textures appear occasionally and behave as a pad or a hook rather than as a performance. A product feature requiring a sung line needs a singer or a different model.

Last updated November 23, 2026.

Next
Next

Best AI music generators for film, TV, and ad production