Telegram error 400: Bad Request: inline keyboard expected
Last verified against Telegram Bot API reference
Bad Request: inline keyboard expectedWhat error 400 means
A method that only accepts an InlineKeyboardMarkup received a different kind of reply markup, such as a ReplyKeyboardMarkup, ReplyKeyboardRemove or ForceReply. The check lives in TDLib, the library behind the Bot API server, which returns "Inline keyboard expected" whenever a context permits inline keyboards only.
The edit methods are the classic case. The docs for editMessageReplyMarkup, editMessageText and the other edit methods type reply_markup as InlineKeyboardMarkup: a message's custom reply keyboard cannot be changed by editing. Inline query results, messages sent on behalf of inline mode, and channel posts likewise take inline keyboards only.
Usually the bug is a shared helper that builds "the keyboard" for both a new message and an edit. The JSON has a top-level keyboard field (reply keyboard) where the edit needs inline_keyboard. Nothing about the message or chat is wrong.
What it looks like
{"ok":false,"error_code":400,"description":"Bad Request: inline keyboard expected"}Why it happens
- An edit method was given JSON with
keyboardrows instead ofinline_keyboardrows. remove_keyboardorforce_replywas passed to an edit call to hide a reply keyboard.- An inline query result or a channel post was given a reply keyboard.
- A keyboard builder returned the wrong markup class for the context it was used in.
How to fix Telegram error 400
- 1Send
{"inline_keyboard": [[...]]}to edit methods. - 2To remove or replace a custom reply keyboard, send a new message with
ReplyKeyboardRemoveor a newReplyKeyboardMarkup. - 3To strip an inline keyboard from a message, call
editMessageReplyMarkupwith an empty inline keyboard or no reply_markup. - 4Split keyboard helpers by type so edits can only produce inline markup.
How to stop it recurring
Model reply keyboards and inline keyboards as separate types in your code, and type edit functions to accept only the inline one. The keyboard builder outputs both shapes so you can see the field difference, and keyboard limits lists the related constraints.
Official reference: Telegram Bot API reference. See all Telegram error codes or the Telegram limits and quotas.
Related codes
- 400: Bad Request: can't parse InlineKeyboardButton: Text buttons are not allowed in the inline keyboardBad Request: can't parse InlineKeyboardButton: Text buttons are not allowed in…
- 400: Bad Request: can't parse reply keyboard markup JSON objectBad Request: can't parse reply keyboard markup JSON object
- 400: Bad Request: message can't be editedBad Request: message can't be edited
Error 400 - quick answers
What does Telegram error 400 mean?
A method that only accepts an InlineKeyboardMarkup received a different kind of reply markup, such as a ReplyKeyboardMarkup , ReplyKeyboardRemove or ForceReply . The check lives in TDLib, the library behind the Bot API server, which returns "Inline keyboard expected" whenever a context permits inline keyboards only. The edit methods are the classic case.
How do I fix Telegram error 400?
1. Send {"inline_keyboard": [[...]]} to edit methods. 2. To remove or replace a custom reply keyboard, send a new message with ReplyKeyboardRemove or a new ReplyKeyboardMarkup . 3. To strip an inline keyboard from a message, call editMessageReplyMarkup with an empty inline keyboard or no reply_markup. 4. Split keyboard helpers by type so edits can only produce inline markup.
Stop debugging Telegram by hand
Connect the channel through Conferbot: tokens, webhooks and retries are handled, failures show as readable status.