# Extend Music

> Extend or modify existing music tracks by creating sequels based on source audio. Supports custom mode with full parameter control or simple mode inheriting original parameters. Specify continuation points and maintain style consistency across extensions up to 8 minutes.

## Overview

- Submit: `https://api.poyo.ai/api/generate/submit`
- Status: `https://api.poyo.ai/api/generate/status/{task_id}`
- Page: https://poyo.ai/models/extend-music
- Model page ID: `extend-music`
- API model ID: `extend-music`
- Category: Music
- Auth: `Authorization: Bearer $POYO_API_KEY`
- Create a key at https://poyo.ai/dashboard/api-key

This model uses PoYo's unified async API. POST the JSON body below, then poll status with the returned `task_id` or receive a webhook on `callback_url`. Failed tasks are not charged.

## Pricing

- Standard generation: 20 credits ($0.100) per generation

For more details, see https://poyo.ai/models/extend-music.

## API Information

The request envelope is always `{ model, input, callback_url? }`. Input fields below are nested under `input`.

### Request envelope

- `model` (`ModelEnum`, required):
  API model identifier.
  
  Must be `extend-music` for this endpoint.
  - Options: `"extend-music"`
  - Examples: "extend-music"
- `callback_url` (`string`, optional):
  Webhook callback URL for result notifications.
  
  Endpoint that receives task completion updates.
  - Examples: "https://your-domain.com/callback"

### Input Schema

Input parameters for music extension

The API accepts the following `input` parameters:

- `default_param_flag` (`boolean`, optional):
  Controls whether to use custom parameters or inherit from the source audio.
  
  - When `true`: Enables custom parameter mode. `mv`, `style`, `title`, and `continue_at` become required. `prompt` is additionally required for vocal extensions.
  
  - When `false`: `audio_id` and `mv` are required.
  - Default: `true`
  - Examples: `true`
- `audio_id` (`string`, required):
  Identifier of the source audio track to extend.
  
  This is the unique ID of an existing track that you want to continue or modify.
  - Examples: "audio_abc123"
- `prompt` (`string`, optional):
  Description of how you want to extend the music.
  
  Required for vocal extensions when `default_param_flag` is `true`. It is not sent when `instrumental` is `true`.
  
  Character limits by model:
  - **V4**: Maximum 3000 characters
  - **V4_5 & V4_5PLUS**: Maximum 5000 characters
  - **V4_5ALL**: Maximum 5000 characters
  - **V5**: Maximum 5000 characters
  - **V5_5**: Maximum 5000 characters
  - **V6, V6_MINI, and V6_WILD**: Maximum 5000 characters
  - Examples: "Continue with an energetic chorus section"
- `style` (`string`, optional):
  Music style specification for the extended section.
  
  Required when `default_param_flag` is `true`.
  
  Character limits by model:
  - **V4**: Maximum 200 characters
  - **V4_5 & V4_5PLUS**: Maximum 1000 characters
  - **V4_5ALL**: Maximum 1000 characters
  - **V5**: Maximum 1000 characters
  - **V5_5**: Maximum 1000 characters
  - **V6, V6_MINI, and V6_WILD**: Maximum 1000 characters
  - Examples: "Pop, Upbeat"
- `title` (`string`, optional):
  Title for the extended track.
  
  Required when `default_param_flag` is `true`.
  
  Character limits by model:
  - **V4**: Maximum 80 characters
  - **V4_5 & V4_5PLUS**: Maximum 100 characters
  - **V4_5ALL**: Maximum 80 characters
  - **V5**: Maximum 100 characters
  - **V5_5**: Maximum 100 characters
  - **V6, V6_MINI, and V6_WILD**: Maximum 100 characters
  - Examples: "Summer Vibes Extended"
- `continue_at` (`float`, optional):
  The timestamp (in seconds) from which to start the extension.
  
  Specifies the point in the original track where the extension should begin.
  
  Required when `default_param_flag` is `true`.
  - Examples: `120`
- `mv` (`MvEnum`, required):
  AI model version for music extension.
  
  - **V5**: Superior musical expressiveness with faster generation
  - **V5_5**: Personalized model tuned to your unique taste.
  - **V4_5PLUS**: Enhanced tonal richness with new creative approaches, max 8 min duration
  - **V4_5**: Improved prompt intelligence and faster generation, max 8 min duration
  - **V4_5ALL**: V4_5ALL enables smarter prompts, faster generations, max 8 min duration
  - **V4**: Improved vocal quality, max 4 min duration
  - **V6**: Greater musical expression with more natural vocals.
  - **V6_MINI**: Lightweight and fast.
  - **V6_WILD**: Bolder, more distinctive musical expression.
  - Options: `"V4"`, `"V4_5"`, `"V4_5ALL"`, `"V4_5PLUS"`, `"V5"`, `"V5_5"`, `"V6"`, `"V6_MINI"`, `"V6_WILD"`
  - Examples: "V5_5"
- `negative_tags` (`string`, optional):
  Music styles or characteristics to exclude from the extension.
  
  Specify unwanted genres, moods, or instruments to avoid in the output.
  - Examples: "Heavy Metal, Sad"
- `vocal_gender` (`VocalGenderEnum`, optional):
  Preferred vocal gender for the extended section.
  
  - `m`: Male vocals
  - `f`: Female vocals
  
  **Note**: This parameter increases the probability but cannot guarantee the specified gender.
  - Options: `"m"`, `"f"`
  - Examples: "m"
- `style_weight` (`float`, optional):
  Controls how strongly the specified style influences the extension.
  
  Range: 0-1, up to 2 decimals.
  
  Higher values result in stronger adherence to the specified style.
  - Range: `0` to `1`
  - Examples: `0.7`
- `weirdness_constraint` (`float`, optional):
  Controls the level of experimental creativity and unconventional elements.
  
  Range: 0-1, up to 2 decimals.
  
  - Lower values: More conventional music
  - Higher values: More experimental and unique outputs
  - Range: `0` to `1`
  - Examples: `0.5`
- `audio_weight` (`float`, optional):
  Balances audio characteristics against other generation factors.
  
  Range: 0-1, up to 2 decimals.
  
  Adjusts the emphasis on audio quality and sonic features in the final output.
  - Range: `0` to `1`
  - Examples: `0.6`
- `persona_id` (`string`, optional):
  Persona ID to apply to the extended music.
  
  Only available when Custom Mode ( `default_param_flag: true` ) is enabled.
  
  Use this to apply a specific persona style to your music extension.
  
  How to generate persona_id, visit [generate-persona](/api-manual/music-series/generate-persona).
  - Examples: "persona_123"
- `persona_model` (`PersonaModelEnum`, optional):
  Persona type; requires persona_id, default_param_flag=true, and V5, V5_5, V6, V6_MINI, or V6_WILD.
  - Options: `"style_persona"`, `"voice_persona"`
- `instrumental` (`boolean`, optional):
  Whether the extension is instrumental. When true, prompt is not sent.

Required Parameters Example:

```json
{
  "model": "extend-music",
  "input": {
    "audio_id": "audio_abc123",
    "mv": "V5_5"
  }
}
```

Full Example:

```json
{
  "model": "extend-music",
  "input": {
    "default_param_flag": true,
    "audio_id": "audio_abc123",
    "instrumental": false,
    "prompt": "Continue with an energetic chorus section",
    "style": "Pop, Upbeat",
    "title": "Summer Vibes Extended",
    "continue_at": 120,
    "mv": "V5_5",
    "negative_tags": "Heavy Metal, Sad",
    "style_weight": 0.7,
    "vocal_gender": "m",
    "weirdness_constraint": 0.5,
    "audio_weight": 0.6,
    "persona_id": "persona_123"
  }
}
```

Simple Mode - Use Original Parameters:

```json
{
  "model": "extend-music",
  "input": {
    "default_param_flag": false,
    "audio_id": "audio_abc123",
    "mv": "V4_5PLUS"
  }
}
```

### Output Schema

Submit returns a `task_id`. Poll `GET /api/generate/status/{task_id}` until `status` is `finished` or `failed`. Completed media is in `data.files`.

Response fields:

- `code` (`CodeEnum`, required):
  Business status code. `200` means success; any other value means the request failed. Always check this field: some validation errors return HTTP 200 with `code: 400` in the body.
  
  - `200`: Success
  - `400`: Invalid request parameters
  - `401`: Missing or invalid API key
  - `402`: Insufficient credits
  - `403`: Permission denied
  - `404`: Resource not found
  - `408`: Request timeout
  - `429`: Rate limit exceeded
  - `500`: Internal server error
  - `502`: Upstream service error
  - `503`: Service unavailable
  
  See [Error Codes](/api-manual/error-codes) for details.
  - Options: `200`, `400`, `401`, `402`, `403`, `404`, `408`, `429`, `500`, `502`, `503`
  - Examples: `200`
- `data` (`object`, required):

Example Response:

```json
{
  "code": 200,
  "data": {
    "task_id": "task_example",
    "status": "finished",
    "files": [
      {
        "file_url": "",
        "file_type": "file"
      }
    ]
  }
}
```

## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://api.poyo.ai/api/generate/submit \
  --header "Authorization: Bearer $POYO_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{"model":"extend-music","input":{"default_param_flag":true,"audio_id":"audio_abc123","instrumental":false,"prompt":"Continue with an energetic chorus section","style":"Pop, Upbeat","title":"Summer Vibes Extended","continue_at":120,"mv":"V5_5","negative_tags":"Heavy Metal, Sad","style_weight":0.7}}'
```

### Python

```python
import json
import os
import time
import requests

API = "https://api.poyo.ai"
headers = {
    "Authorization": f"Bearer {os.environ['POYO_API_KEY']}",
    "Content-Type": "application/json",
}
payload = json.loads("{\n  \"model\": \"extend-music\",\n  \"input\": {\n    \"default_param_flag\": true,\n    \"audio_id\": \"audio_abc123\",\n    \"instrumental\": false,\n    \"prompt\": \"Continue with an energetic chorus section\",\n    \"style\": \"Pop, Upbeat\",\n    \"title\": \"Summer Vibes Extended\",\n    \"continue_at\": 120,\n    \"mv\": \"V5_5\",\n    \"negative_tags\": \"Heavy Metal, Sad\",\n    \"style_weight\": 0.7\n  }\n}")

submit = requests.post(f"{API}/api/generate/submit", headers=headers, json=payload)
submit.raise_for_status()
task_id = submit.json()["data"]["task_id"]

while True:
    status = requests.get(f"{API}/api/generate/status/{task_id}", headers=headers)
    status.raise_for_status()
    data = status.json()["data"]
    if data["status"] in ("finished", "failed"):
        print(data)
        break
    time.sleep(2)
```

### JavaScript

```javascript
const headers = {
  Authorization: `Bearer ${process.env.POYO_API_KEY}`,
  "Content-Type": "application/json",
};

const submit = await fetch("https://api.poyo.ai/api/generate/submit", {
  method: "POST",
  headers,
  body: JSON.stringify({
  "model": "extend-music",
  "input": {
    "default_param_flag": true,
    "audio_id": "audio_abc123",
    "instrumental": false,
    "prompt": "Continue with an energetic chorus section",
    "style": "Pop, Upbeat",
    "title": "Summer Vibes Extended",
    "continue_at": 120,
    "mv": "V5_5",
    "negative_tags": "Heavy Metal, Sad",
    "style_weight": 0.7
  }
}),
});

const submitted = await submit.json();
const taskId = submitted.data.task_id;

while (true) {
  const statusResponse = await fetch(`https://api.poyo.ai/api/generate/status/${taskId}`, { headers });
  const status = await statusResponse.json();
  if (["finished", "failed"].includes(status.data.status)) {
    console.log(status.data);
    break;
  }
  await new Promise((resolve) => setTimeout(resolve, 2000));
}
```

## Additional Resources

### Documentation

- [Model Playground](https://poyo.ai/models/extend-music)
- [API Documentation](https://docs.poyo.ai/api-manual/music-series/extend-music)
- [API Documentation (Markdown)](https://docs.poyo.ai/api-manual/music-series/extend-music.md)
- [Task status](https://docs.poyo.ai/api-manual/task-management/query-task-status)
- [Webhooks](https://docs.poyo.ai/api-manual/task-management/webhooks)

### Other agent-readable surfaces

- [Platform overview](https://poyo.ai/llms.txt)
- [Documentation index](https://docs.poyo.ai/llms.txt)
- [Full documentation text](https://docs.poyo.ai/llms-full.txt)
- Any other model: `https://poyo.ai/models/<model-id>/llms.txt`
