Read the Build a basic LLM chat app tutorial to learn how to use st.chat_message and st.chat_input to build chat-based apps.

Display a chat input widget.

Function signature[source]

st.chat_input(placeholder="Your message", *, key=None, max_chars=None, disabled=False, on_submit=None, args=None, kwargs=None)


placeholder (str)

A placeholder text shown when the chat input is empty. Defaults to "Your message". For accessibility reasons, you should not use an empty string.

key (str or int)

An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.

max_chars (int or None)

The maximum number of characters that can be entered. If None (default), there will be no maximum.

disabled (bool)

Whether the chat input should be disabled. Defaults to False.

on_submit (callable)

An optional callback invoked when the chat input's value is submitted.

args (tuple)

An optional tuple of args to pass to the callback.

kwargs (dict)

An optional dict of kwargs to pass to the callback.


(str or None)

The current (non-empty) value of the text input widget on the last run of the app. Otherwise, None.


When st.chat_input is used in the main body of an app, it will be pinned to the bottom of the page.

import streamlit as st

prompt = st.chat_input("Say something")
if prompt:
    st.write(f"User has sent the following prompt: {prompt}")

The chat input can also be used inline by nesting it inside any layout container (container, columns, tabs, sidebar, etc). Create chat interfaces embedded next to other content or have multiple chat bots!

import streamlit as st

with st.sidebar:
    messages = st.container(height=300)
    if prompt := st.chat_input("Say something"):
        messages.chat_message("assistant").write(f"Echo: {prompt}")

For an overview of the st.chat_input and st.chat_message API, check out this video tutorial by Chanin Nantasenamat (@dataprofessor), a Senior Developer Advocate at Streamlit.


Still have questions?

Our forums are full of helpful information and Streamlit experts.