sendAudio
Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
For sending voice messages, use the sendVoice method instead.
Parameters
business_connection_idStringOptionalchat_idIntegerStringRequired@channelusername)message_thread_idIntegerOptionaldirect_messages_topic_idIntegerOptionalparse_modeStringOptionaldurationIntegerOptionalperformerStringOptionaltitleStringOptionaldisable_notificationBooleanOptionalprotect_contentBooleanOptionalallow_paid_broadcastBooleanOptionalmessage_effect_idStringOptionalreply_markupInlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReplyOptional⌨️ KeyboardsReturns
On success, the Message object is returned.
GramIO Usage
Send an audio file by URL from a message handler using the context shorthand:
bot.on("message", async (ctx) => {
await ctx.sendAudio(
"https://example.com/track.mp3",
{
performer: "Artist Name",
title: "Song Title",
duration: 210,
}
);
});Reply to the user's message with the audio using replyWithAudio:
bot.on("message", async (ctx) => {
await ctx.replyWithAudio("https://example.com/track.mp3", {
performer: "Artist Name",
title: "Song Title",
});
});Upload a local MP3 file using MediaUpload.path and include a caption:
bot.on("message", async (ctx) => {
await ctx.sendAudio(await MediaUpload.path("./music/track.mp3"), {
caption: format`${bold("Now playing:")} My Favorite Track`,
performer: "My Band",
title: "My Favorite Track",
duration: 195,
});
});Resend a previously uploaded audio using its file_id for efficiency:
bot.on("message", async (ctx) => {
// file_id obtained from a previously received Message
const fileId = "CQACAgIAAxkBAAIB...";
await ctx.sendAudio(fileId, {
caption: "Resent from cache — no re-upload needed!",
});
});Direct API call with bot.api.sendAudio (useful outside message handlers):
const msg = await bot.api.sendAudio({
chat_id: 123456789,
audio: await MediaUpload.url("https://example.com/track.mp3"),
performer: "Artist",
title: "Track",
duration: 210,
caption: "Enjoy the music!",
});Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: chat not found | The chat_id is invalid, the bot has never interacted with the user, or the chat does not exist. |
| 400 | Bad Request: wrong file identifier/HTTP URL specified | The file_id is malformed or the URL is unreachable / returns a non-audio response. |
| 400 | Bad Request: failed to get HTTP URL content | Telegram could not download the audio from the provided HTTP URL. Ensure the URL is publicly accessible. |
| 400 | Bad Request: file is too big | The audio exceeds the 50 MB server-side limit. Compress or split the file before uploading. |
| 400 | Bad Request: AUDIO_INVALID | The file format is not supported. Only .mp3 and .m4a formats are displayed in the music player. |
| 403 | Forbidden: bot was blocked by the user | The user blocked the bot. Remove them from your active user list. |
| 429 | Too Many Requests: retry after N | Flood control triggered. Back off for the specified number of seconds. |
TIP
Use GramIO's auto-retry plugin to handle 429 errors automatically.
Tips & Gotchas
- Only MP3 and M4A show in the music player. Other formats (OGG, WAV, FLAC) will be sent as documents. If you need voice-note playback, use
sendVoiceinstead. - Use
file_idto re-send. Once uploaded, store thefile_idfrom the returnedMessage.audio.file_idand pass it directly on future sends — no bandwidth cost. performerandtitlepopulate the mini player. Provide both to give users a proper music-player experience. Without them, Telegram displays the filename.- Thumbnail is only applied to fresh uploads. Passing a
thumbnailwith afile_idaudio has no effect — Telegram uses the cached thumbnail. - 50 MB is the current cap. Split long recordings or reduce bitrate (128 kbps is sufficient for voice/speech).
- Caption limit is 1024 characters. Unlike
sendMessage, audio captions are capped at 1024 chars.
See Also
- Media Upload guide — file_id, URL, path, buffer upload patterns
- Formatting guide — bold, italic, and entity-based caption formatting
- Keyboards overview — attaching inline or reply keyboards
- sendVoice — send OGG voice messages
- sendDocument — send files without media player rendering
- Audio type — structure of the returned audio object
- Message type — full structure of the returned message