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

# Upload Audio

> Upload audio files to get URLs for use in audio-related APIs

> [!NOTE]
>
> **Note for users in mainland China:** Please use `https://toapis.cn` as the API endpoint (Base URL). Replace `https://toapis.com` with `https://toapis.cn` in the examples in this document.

> [!NOTE]
>
> **The docs Playground does not support file uploads**: Please use the cURL, Python, or JavaScript code examples below for testing.

## Why Upload Audio First?

1. **Unified input flow** - Upload local audio once and reuse the returned public URL
2. **Less repeated transfer** - The same uploaded audio can be reused in multiple requests

## Authorizations

**Authorization** `string` *required*

Use Bearer Token for authentication

Get your API Key: Visit [API Key Management](https://toapis.com/console/token)

```
Authorization: Bearer YOUR_API_KEY
```

## Body

**file** `file` *required*

Audio file

**Supported formats:**

* MP3 (.mp3)
* WAV (.wav)
* M4A (.m4a)

**Limits:**

* Maximum file size: 50MB

**purpose** `string`

Upload purpose (optional)

Default: `generation`

## Response

**success** `boolean`

Whether the request succeeded

**data** `object`

**Response data**

**id** `string`

Upload record ID for tracking

**url** `string`

Public URL of the uploaded audio

**mime\_type** `string`

MIME type of the audio, e.g. `audio/mpeg`

**size** `integer`

File size in bytes

```bash cURL theme={null}
curl --request POST \
  --url https://toapis.com/v1/uploads/audios \
  --header 'Authorization: Bearer <token>' \
  --form 'file=@/path/to/your/audio.mp3'
```

```python Python theme={null}
import requests

with open('audio.mp3', 'rb') as f:
    response = requests.post(
        "https://toapis.com/v1/uploads/audios",
        headers={
            "Authorization": "Bearer your-ToAPIs-key"
        },
        files={
            "file": f
        }
    )

result = response.json()
audio_url = result['data']['url']
print(f"Audio URL: {audio_url}")
```

```javascript JavaScript theme={null}
(async () => {
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = 'audio/mpeg,audio/wav,audio/mp4';
fileInput.click();
await new Promise(resolve => fileInput.onchange = resolve);

const formData = new FormData();
formData.append('file', fileInput.files[0]);

const uploadResponse = await fetch('https://toapis.com/v1/uploads/audios', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your-ToAPIs-key'
  },
  body: formData
});

const uploadResult = await uploadResponse.json();
console.log('Upload result:', uploadResult);
})();
```

```json 200 Success theme={null}
{
  "success": true,
  "message": "",
  "data": {
    "id": "upload_abc12345",
    "url": "https://files.toapis.com/uploads/123/audios/1737568800_abc12345.mp3",
    "mime_type": "audio/mpeg",
    "size": 1892345
  }
}
```

```json 400 Bad Request theme={null}
{
  "success": false,
  "message": "Unsupported or invalid audio file. Allowed: MP3, WAV, M4A"
}
```

```json 400 File Too Large theme={null}
{
  "success": false,
  "message": "Audio too large. Maximum size is 50MB"
}
```


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