yumoqing ae02a7e88c feat: add music generation API (MiniMax Music 2.5/2.6)
- Add POST /v1/music/generations endpoint (index.dspy)
- Add music generation section to API docs
- Update load_path.py RBAC permissions for new path
- Models: music-2.6, music-2.5 (MiniMax, sync, returns audio URL)
- Required params: model, catelogid=music_gen, prompt, lyrics
2026-06-04 13:40:08 +08:00

81 lines
2.3 KiB
Plaintext

# OpenAI-compatible Music Generation API
# POST /v1/music/generations
# Required params: model, catelogid, prompt, lyrics
# Optional params: output_format, audio_setting
#
# Example request:
# {
# "model": "music-2.6",
# "catelogid": "music_gen",
# "prompt": "Pop music, happy, suitable for a sunny day",
# "lyrics": "[Intro]\n\n[Verse]\nWalking down the street\nFeeling the beat\n\n[Chorus]\nDancing in the sun\nHaving so much fun"
# }
#
# Response (sync for MiniMax):
# {
# "id": "luid_xxx",
# "object": "music.generation",
# "model": "music-2.6",
# "status": "SUCCEEDED",
# "audio": "https://...",
# "created": 1234567890
# }
userid = await get_user()
userorgid = await get_userorgid()
if userid is None:
debug('need login')
return openai_403()
# Validate required parameters
if not params_kw.model:
d = return_error('Missing required parameter: model')
return json_response(d, status=400)
if not params_kw.catelogid:
d = return_error('Missing required parameter: catelogid')
return json_response(d, status=400)
if not params_kw.prompt:
d = return_error('Missing required parameter: prompt')
return json_response(d, status=400)
if not params_kw.lyrics:
d = return_error('Missing required parameter: lyrics')
return json_response(d, status=400)
lctype = params_kw.catelogid
env = request._run_ns
async with get_sor_context(env, 'llmage') as sor:
# Look up llm by model name and catalog type through llm_api_map
sql = """select distinct a.* from llm a
join llm_api_map m on a.id = m.llmid
join llmcatelog b on m.llmcatelogid = b.id
where (b.id = ${lctype}$ OR b.name = ${lctype}$)
and a.model=${model}$
and a.status = 'published'"""
recs = await sor.sqlExe(sql, {
'lctype': lctype,
'model': params_kw.model
})
if len(recs) == 0:
debug(f'{params_kw.model=} not found for catalog {lctype}')
return openai_400()
params_kw.llmid = recs[0].id
debug(f'{params_kw.llmid=}')
# Check balance
f = await checkCustomerBalance(params_kw.llmid, userid, userorgid)
if not f:
debug(f'{userid=} balance not enough')
return openai_429()
# Generate task ID and attach to params
if not params_kw.transno:
params_kw.transno = getID()
# Call inference (music generation via MiniMax is synchronous)
return await inference(request, env=env)