sendAudio
Send an audio file to a specified chat. Supports uploading a file directly or passing a file_id of a previously uploaded file. Unlike sendVoice, sendAudio is used for sending audio files such as music, which the client will display using an audio player.
Request
POST /:token/sendAudio
Use multipart/form-data encoding for file uploads.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| chat_id | Integer/String | Yes | Unique identifier or username of the target chat |
| audio | String/File | Yes | Audio file or file_id of a previously uploaded file |
| caption | String | No | Audio caption text |
| parse_mode | String | No | Parsing mode for the caption, supports HTML or Markdown |
| duration | Integer | No | Duration of the audio in seconds |
| reply_markup | Object | No | Custom keyboard or inline keyboard markup, JSON-serialized object |
| reply_to_message_id | Integer | No | ID of the message to reply to |
Response
Returns the sent Message object on success.
json
{
"ok": true,
"result": {
"message_id": 104,
"from": {
"id": 123456789,
"is_bot": true,
"first_name": "MyBot",
"username": "my_bot"
},
"chat": {
"id": 987654321,
"first_name": "User",
"username": "user123",
"type": "private"
},
"date": 1700000000,
"audio": {
"file_id": "CQACAgIAAxkBAAI...",
"file_unique_id": "AQADAgAT...",
"duration": 180,
"mime_type": "audio/mpeg",
"file_size": 3145728
},
"caption": "This is a song"
}
}Error Codes
| Code | Description |
|---|---|
| 400 | Bad request parameters, e.g. unsupported file format |
| 401 | Invalid or expired token |
| 403 | Bot does not have permission to send messages to this chat |
| 404 | Chat not found |
| 413 | File too large |
| 500 | Internal server error |
Examples
Send Audio via File Upload
bash
curl -X POST "https://api.example.com/<token>/sendAudio" \
-F "chat_id=987654321" \
-F "audio=@/path/to/song.mp3" \
-F "caption=This is a song" \
-F "duration=180"Send Audio via file_id
bash
curl -X POST "https://api.example.com/<token>/sendAudio" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 987654321,
"audio": "CQACAgIAAxkBAAI...",
"caption": "Forwarding a song"
}'