翻篇收录说明
翻篇网页快照

AI audio generation API: how to add it to your product — Stability AI

https://stability.ai/explainers/ai-audio-generation-api-how-to-add-to-product

最近抓取:2026-12-04 21:44:48(北京时间)

最近内容变化:2026-12-02 09:13:03(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Add AI-generated music and sound effects to your app with the Stable Audio 3.0 API. Learn the endpoints, polling flow, key parameters, and limits to plan for.

正文摘录

How to add AI audio generation to your product with an API Nov 23 Written by Louisa Marshall 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 takeawaysEvery 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 worksGeneration 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 headersRetrieval 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 referenceThe three endpoints and what each one needsYour 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 APINo 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. The Stable Audio 3.0 guide recommends TrackType: Music, VocalType: Instrumental for full tracks. For stems, start with TrackType: Instrument. 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 songsWhat the API does for loops, and what it leaves to youLoop 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 seedFour 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 codeMoving 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 shipFive 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.