What JSON can and cannot do for Suno
People asking how to use json in suno tend to have one of two goals. Some want a repeatable way to produce songs in bulk, with titles, style descriptions and lyrics kept in separate, clean fields. Others have a script or app that calls a music tool and needs its inputs in a predictable shape. Both goals are about structured text, and that is where a language model with JSON output helps.
The boundaries are worth stating. This site runs an OpenAI-compatible text API. It does not generate music, voices or any other audio, and we are not affiliated with Suno. What it can do is write the song details and return them as a JSON object. How those fields get into Suno, whether pasted into its create form or sent through whatever interface you use, depends on Suno's own current documentation, so check that for field names and length limits.
The workflow, then, has three steps: ask for JSON, check the JSON, and hand the fields to the music tool. The rest of this article covers each step with code.
Turning on JSON mode
The endpoint supports JSON mode through response_format. Add {"type":"json_object"} to your request and the model returns a single JSON object instead of free-form prose. Here it is in curl first, since it shows the raw request.
curl https://api.sunoapis.com/v1/chat/completions \
-H "Authorization: Bearer $UNCENSORED_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"response_format": {"type": "json_object"},
"messages": [
{"role": "system", "content": "Return a JSON object with keys title, style, lyrics. style is a comma-separated list of descriptors."},
{"role": "user", "content": "A sea shanty about a lost phone."}
]
}'
Two habits make JSON mode behave. First, mention JSON in the system message and list the keys. The mode guarantees an object, but the shape inside it comes from your instructions. Second, keep the schema small. Five or six keys with clear names are returned more reliably than a deeply nested structure.
The key goes in the header as Authorization: Bearer. You can get one from the API key page, where new accounts can also claim a $0.50 trial credit with one click, with no card needed.
A complete Python example
This script asks for a song spec, parses it and checks the fields. It uses the standard OpenAI SDK pointed at the endpoint.
import json, os
from openai import OpenAI
client = OpenAI(
base_url="https://api.sunoapis.com/v1",
api_key=os.environ["UNCENSORED_API_KEY"],
)
SYSTEM = '''You write song specs. Respond with a JSON object with exactly these keys:
title (string, max 60 characters),
style (string, comma-separated descriptors, max 120 characters),
lyrics (string, with [Verse], [Chorus] and [Bridge] markers on their own lines),
mood (string).
Do not add any other keys.'''
def song_spec(idea: str) -> dict:
r = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": SYSTEM},
{"role": "user", "content": idea},
],
response_format={"type": "json_object"},
temperature=0.9,
)
return json.loads(r.choices[0].message.content)
spec = song_spec("A slow country song about a truck that will not start.")
print(spec["title"])
print(spec["style"])
print(spec["lyrics"])
The section markers in the lyrics are an example of the kind of convention you set in the system message. Whether Suno reads such markers the way you expect is something to confirm in its documentation and by testing, since this API only produces the text.
If you prefer Node, the call is the same shape:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.sunoapis.com/v1",
apiKey: process.env.UNCENSORED_API_KEY,
});
const r = await client.chat.completions.create({
model: "uncensored",
messages: [
{ role: "system", content: "Return JSON with keys title, style, lyrics." },
{ role: "user", content: "A lullaby for a robot." },
],
response_format: { type: "json_object" },
});
const spec = JSON.parse(r.choices[0].message.content);
console.log(spec.title);Designing the schema before you prompt
The quality of a JSON pipeline is set by the schema, not by clever wording. Spend a few minutes on it first.
Start from what Suno needs, then work backwards
Look at the fields you actually fill in when you create a song by hand: perhaps a title, a style box, a lyrics box, and maybe an option for an instrumental. Make one key per field. Do not invent extra keys "just in case"; each one is another chance for a mismatch.
Use plain types
Strings, numbers and booleans are returned reliably. Lists of strings are fine. Nested objects work but fail more often, so flatten where you can. If you need a list of style tags as one line for a text box, ask for a string and let the model do the joining.
State the limits in the schema text
If a field has a length cap, say so beside the key: "style (string, max 120 characters)". Then enforce the same cap in your validator, because models count characters poorly.
Give one short example
Add a single example object to the system message, with short placeholder values. It anchors the key names and the format of strings such as lyrics. Keep the example clearly generic so the model does not copy its content into every song.
With a schema like this fixed, you can test the whole pipeline with a handful of ideas and read the API docs for any parameter you want to tune, such as stop or top_p.
Validate before you trust it
JSON mode gives you parseable output, not guaranteed correct output. A model can still return a title that is too long, skip a key, or put a list where you wanted a string. Treat the response as untrusted input and check it the way you would check data from a user.
REQUIRED = {"title": 60, "style": 120}
def check(spec: dict) -> list[str]:
problems = []
for key, limit in REQUIRED.items():
v = spec.get(key)
if not isinstance(v, str) or not v.strip():
problems.append(f"{key} missing")
elif len(v) > limit:
problems.append(f"{key} too long ({len(v)} > {limit})")
if "[Chorus]" not in spec.get("lyrics", ""):
problems.append("no chorus marker")
return problems
def song_spec_checked(idea: str, tries: int = 3) -> dict:
for _ in range(tries):
spec = song_spec(idea)
problems = check(spec)
if not problems:
return spec
idea = idea + " Fix these problems: " + "; ".join(problems)
raise ValueError("no valid spec after retries")
Note the retry feeds the specific problems back to the model. That works better than a blind retry, because the second attempt knows exactly what to change. Also wrap json.loads in a try block; on rare occasions the output can be cut short if you set a low max_tokens, and the parser will complain. Leaving max_tokens unset lets the completion use the rest of the 100,000-token window, which removes that cause.
Common mistakes and fixes
The model wraps the JSON in prose or code fences
This is mostly a problem when JSON mode is off. With response_format set, you should get a bare object. If your script still sees fences, strip them defensively before parsing.
Keys change from run to run
You listed the keys loosely. Write "exactly these keys" and name them, and add a one-line example object to the system message. Models follow examples closely.
Lyrics come back as a list of lines
Say in the schema that lyrics is one string with newline characters. Or accept a list and join it in code. Pick one and enforce it in the validator.
Every song sounds alike
Raise temperature to 0.9 or 1.0, vary the user idea, or pass a different seed per request. If you want identical output while testing, fix the seed and keep the other settings unchanged.
The request is rejected with 429
You hit a limit. The error code concurrency means too many simultaneous requests (8 on a full key, 2 on the trial key). The code rate_limited means too many per minute (300 on a full key, 60 on the trial key). A 429 carrying Retry-After: 5 means a temporary overload, so wait five seconds and retry.
Batch generation without hitting limits
Once one spec works, the natural next step is a batch: a list of ideas, one spec each, saved to a file. Keep concurrency at or under your limit and retry on 429.
import time
from concurrent.futures import ThreadPoolExecutor
from openai import RateLimitError
def safe_spec(idea):
for attempt in range(4):
try:
return song_spec_checked(idea)
except RateLimitError:
time.sleep(5 * (attempt + 1))
return None
ideas = ["Synthwave about a night bus", "Folk ballad about a lighthouse", "Punk song about Mondays"]
with ThreadPoolExecutor(max_workers=2) as pool:
results = list(pool.map(safe_spec, ideas))
with open("specs.json", "w") as f:
json.dump([r for r in results if r], f, indent=2)
Two workers suit the trial key; use up to eight on a full key. The docs list every supported parameter and the response headers, including X-Request-Id for support questions and X-Balance-USD for tracking spend as the batch runs.
If you also need prompts for video tools, the page on text-to-video options covers that related use of a text API.
Cost of a JSON song-spec pipeline
Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens, with no subscription. Failed or refused requests are not charged, and credit never expires.
A request with a detailed system message plus a short idea might use about 1,500 input tokens and return about 500 tokens of JSON with lyrics. For 1,000 song specs:
- Input: 1,500,000 tokens x $0.15 / 1M = $0.225
- Output: 500,000 tokens x $0.50 / 1M = $0.25
- Total: $0.475
That is under half a dollar for a thousand structured drafts, so the $0.50 trial credit nearly covers a batch that size, and the validation retries described above add only a little on top. When you need more, top-ups run from $20 to $500, with bonuses of 5% from $50, 10% from $100 and 15% from $200. You can pay by crypto (USDT on TRC20, USDC on Base). See the pricing page for the full table. Your prompts and lyrics are not used for training.
