> ## Documentation Index
> Fetch the complete documentation index at: https://phaseo.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 生成音乐

> 通过一个与提供商无关的端点生成音乐。Phaseo 会等待同步提供商完成，并在内部处理提供商队列的轮询。

通过统一且不依赖供应商的 API 生成音乐。Phaseo 会在后台处理同步响应并轮询供应商队列。

生成完成后，响应会包含 `audio_url` 或 `audio_base64`。如果供应商返回的任务尚未结束，请使用响应中的同一 `id` 调用 `GET /music/generate/{music_id}`。

## 请求结构

```json theme={null}
{
  "model": "minimax/music-3.0:free",
  "prompt": "Warm jazz trio with brushed drums",
  "format": "mp3"
}
```

## Suno 选项

* `suno.customMode` （布尔值，默认值为 `false`）
* `suno.instrumental` （布尔值，默认值为 `false`）
* `suno.prompt` （可选，用于覆盖顶层 `prompt`）
* `suno.style`, `suno.title` （当 `customMode = true` 时必填）
* `suno.personaId`, `suno.personaModel`
* `suno.negativeTags`, `suno.vocalGender`
* `suno.styleWeight`, `suno.weirdnessConstraint`, `suno.audioWeight`

## 验证规则

* 当 `customMode = false` 时，必须提供 `prompt`。
* 当 `customMode = true` 时，必须提供 `style` 和 `title`。
* 当 `customMode = true` 且 `instrumental = false` 时，必须提供 `prompt`。

验证错误会返回 `400`，并包含：

```json theme={null}
{
  "error": "validation_error",
  "reason": "..."
}
```

## 响应

```json theme={null}
{
  "id": "req_01JY6MUSIC123",
  "object": "music",
  "status": "completed",
  "provider": "gmicloud",
  "model": "minimax/music-3.0:free",
  "nativeResponseId": "5c30b275-d669-4a25-8151-de6d60214853",
  "audio_url": "https://.../generated-music.mp3",
  "usage": {
    "requests": 1,
    "output_audio_seconds": 25.364
  }
}
```

* `id` 是 Phaseo 的稳定请求 ID。使用 `GET /music/generate/{music_id}` 检索该请求。
* `nativeResponseId` 是上游提供商的标识符，用于关联提供商请求并联系其支持团队。
* `status` 可以是 `queued`、`in_progress`、`completed` 或 `failed`。
* 提供商报告生成时长时，`usage` 可能包含 `output_audio_seconds`。


## OpenAPI

````yaml zh-Hans/openapi/v1/openapi.localized.yaml POST /music/generate
openapi: 3.0.3
info:
  title: Phaseo Gateway API
  description: 通过兼容 OpenAI 的端点访问各种 AI 模型的网关 API。
  version: 1.0.0
  contact:
    name: Phaseo
    url: https://phaseo.app
    email: danielbutler500@gmail.com
servers:
  - url: https://api.phaseo.app/v1
    description: 全球路由
security:
  - BearerAuth: []
tags:
  - name: Gateway
    description: Core Phaseo Gateway operations.
paths:
  /music/generate:
    post:
      tags:
        - Gateway
      summary: 生成音乐
      description: 通过一个与提供商无关的端点生成音乐。Phaseo 会等待同步提供商完成，并在内部处理提供商队列的轮询。
      operationId: generateMusic
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MusicGenerateRequest'
      responses:
        '200':
          description: 音乐生成响应
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MusicGenerateResponse'
components:
  schemas:
    MusicGenerateRequest:
      type: object
      required:
        - model
      properties:
        model:
          type: string
        prompt:
          type: string
        duration:
          type: integer
        format:
          type: string
          enum:
            - mp3
            - wav
            - ogg
            - aac
        provider:
          $ref: '#/components/schemas/ProviderRoutingOptions'
        suno:
          type: object
          properties:
            prompt:
              type: string
            style:
              type: string
            title:
              type: string
            customMode:
              type: boolean
            instrumental:
              type: boolean
            personaId:
              type: string
            model:
              type: string
            negativeTags:
              type: string
            vocalGender:
              type: string
              enum:
                - m
                - f
            styleWeight:
              type: number
              minimum: 0
              maximum: 1
            weirdnessConstraint:
              type: number
              minimum: 0
              maximum: 1
            audioWeight:
              type: number
              minimum: 0
              maximum: 1
            callBackUrl:
              type: string
              format: uri
        elevenlabs:
          type: object
          properties:
            prompt:
              type: string
            composition_plan:
              type: object
            music_length_ms:
              type: integer
            model_id:
              type: string
            force_instrumental:
              type: boolean
            store_for_inpainting:
              type: boolean
            with_timestamps:
              type: boolean
            sign_with_c2pa:
              type: boolean
            output_format:
              type: string
        echo_upstream_request:
          type: boolean
        debug:
          $ref: '#/components/schemas/DebugOptions'
    MusicGenerateResponse:
      type: object
      required:
        - id
        - object
        - status
        - model
        - provider
      properties:
        id:
          type: string
          description: 稳定的 Phaseo 请求 ID，可与 GET /music/generate/{music_id} 搭配使用。
        object:
          type: string
          enum:
            - music
        status:
          type: string
          enum:
            - queued
            - in_progress
            - completed
            - failed
        model:
          type: string
        provider:
          type: string
        nativeResponseId:
          type: string
          nullable: true
          description: 用于关联和支持的上游提供商标识符。
        audio_url:
          type: string
          format: uri
        audio_base64:
          type: string
        result:
          description: 由 Phaseo 标准化的提供商结果元数据。
        output:
          type: array
          items:
            type: object
            additionalProperties: true
        usage:
          type: object
          additionalProperties: true
      additionalProperties: true
    ProviderRoutingOptions:
      type: object
      description: 用于网关选择的提供商路由偏好设置。
      properties:
        order:
          type: array
          items:
            type: string
        only:
          type: array
          items:
            type: string
        ignore:
          type: array
          items:
            type: string
        include_alpha:
          type: boolean
          description: 在路由中包含 alpha 提供商（默认关闭）。
        allow_fallbacks:
          type: boolean
          nullable: true
          description: 失败后允许回退到其他符合条件的提供商。
        require_parameters:
          type: boolean
          nullable: true
          description: 路由前要求提供商支持所请求的参数。
        required_execution_region:
          type: string
          nullable: true
          description: 将路由限制为具有所需执行区域的提供商。
        required_data_region:
          type: string
          nullable: true
          description: 将路由限制为具有所需数据区域的提供商。
        require_zero_data_retention:
          type: boolean
          nullable: true
          description: 将路由限制为支持零数据保留的提供商。
        data_collection:
          type: string
          nullable: true
          enum:
            - allow
            - deny
        zdr:
          type: boolean
          nullable: true
        enforce_distillable_text:
          type: boolean
          nullable: true
        quantizations:
          type: array
          nullable: true
          items:
            type: string
        sort:
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
          description: 为此请求排列提供商，例如按价格、延迟或吞吐量排序。
        max_price:
          type: object
          properties:
            prompt:
              oneOf:
                - type: number
                - type: string
            completion:
              oneOf:
                - type: number
                - type: string
            image:
              oneOf:
                - type: number
                - type: string
            audio:
              oneOf:
                - type: number
                - type: string
            request:
              oneOf:
                - type: number
                - type: string
        preferred_min_throughput:
          oneOf:
            - type: number
            - type: object
              additionalProperties:
                type: number
        preferred_max_latency:
          oneOf:
            - type: number
            - type: object
              additionalProperties:
                type: number
    DebugOptions:
      type: object
      description: 网关调试控制项。这些标志绝不会转发给提供商。
      properties:
        enabled:
          type: boolean
        return_upstream_request:
          type: boolean
        return_upstream_response:
          type: boolean
        trace:
          type: boolean
        trace_level:
          type: string
          enum:
            - summary
            - full
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: Bearer 令牌身份验证

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.