{"id":4906,"library":"chainlit","title":"Chainlit","description":"Chainlit is an open-source Python framework designed to simplify the creation of interactive user interfaces for Large Language Model (LLM) applications. It enables developers to build ChatGPT-like UIs with minimal frontend code, offering features such as chat lifecycle hooks, UI actions, real-time message streaming, and integrations with popular LLM libraries like LangChain and LlamaIndex. The library is actively maintained with frequent releases, currently at version 2.11.0.","status":"active","version":"2.11.0","language":"en","source_language":"en","source_url":"https://github.com/Chainlit/chainlit","tags":["AI","LLM","chatbot","UI","framework","conversational AI","LangChain","LlamaIndex"],"install":[{"cmd":"pip install chainlit","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Chainlit requires Python 3.10 or higher, but less than 4.0.0.","package":"python","optional":false}],"imports":[{"symbol":"cl","correct":"import chainlit as cl"},{"note":"Decorator for functions that run when a new chat session begins.","symbol":"cl.on_chat_start","correct":"@cl.on_chat_start"},{"note":"Decorator for functions that handle incoming user messages.","symbol":"cl.on_message","correct":"@cl.on_message"},{"note":"Chainlit is async-first; all `cl.Message` operations must be `await`ed to send the message and avoid returning a coroutine object.","wrong":"cl.Message(content='Hello!').send()","symbol":"cl.Message","correct":"await cl.Message(content='Hello!').send()"}],"quickstart":{"code":"import chainlit as cl\nimport os\n\n# Optional: Set CHAINLIT_AUTH_SECRET if authentication is enabled for your app\n# os.environ['CHAINLIT_AUTH_SECRET'] = os.environ.get('CHAINLIT_AUTH_SECRET', 'your_secret_key_here_for_testing')\n\n@cl.on_chat_start\nasync def start():\n    await cl.Message(\n        content=\"Welcome! I am a simple Chainlit bot. Type anything to get a response.\"\n    ).send()\n\n@cl.on_message\nasync def main(message: cl.Message):\n    # Simulate a tool's response\n    await cl.Message(author=\"Tool\", content=f\"Processing: {message.content}\", indent=1).send()\n\n    # Send back the final answer\n    await cl.Message(content=f\"You said: {message.content}\").send()\n\n# To run this:\n# 1. Save the code as `app.py`\n# 2. Run `chainlit run app.py -w` in your terminal\n","lang":"python","description":"This quickstart demonstrates a basic Chainlit application. Create a file named `app.py`, paste the code, and run it using `chainlit run app.py -w` in your terminal. This will start the Chainlit UI in your browser, where you can interact with the bot. The `@cl.on_chat_start` function sends a welcome message, and `@cl.on_message` handles incoming user messages, simulating an intermediate step and then echoing the user's input."},"warnings":[{"fix":"Execute the SQL command `ALTER TABLE steps ADD COLUMN IF NOT EXISTS modes JSONB;` on your Chainlit database before upgrading or starting applications on version 2.9.4 or higher.","message":"Chainlit v2.9.4 introduced a breaking change requiring a database migration for users employing persistence. You must run `ALTER TABLE steps ADD COLUMN IF NOT EXISTS modes JSONB;` to migrate your database.","severity":"breaking","affected_versions":">=2.9.4"},{"fix":"Always prepend `await` to asynchronous Chainlit function calls, e.g., `await cl.Message(...).send()`.","message":"Chainlit is an async-first framework. All operations that interact with the UI, such as `cl.Message().send()` or other `cl` methods that involve sending data, must be `await`ed. Failing to do so will result in a coroutine object being returned instead of the expected action, potentially leading to silent failures or unexpected behavior.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the `CHAINLIT_AUTH_SECRET` environment variable is correctly set and accessible to your Chainlit application. For OAuth, verify all `OAUTH_PROVIDER_CLIENT_ID`, `OAUTH_PROVIDER_CLIENT_SECRET`, and domain variables are correctly configured.","message":"When authentication is enabled (e.g., via `CHAINLIT_AUTH_SECRET` or OAuth), 'Invalid authentication token' errors can occur, especially when rendering images. This often indicates a missing or incorrect `CHAINLIT_AUTH_SECRET` environment variable.","severity":"gotcha","affected_versions":"All versions with authentication enabled"},{"fix":"Verify your `chainlit.toml` file is correctly formatted and located. If issues persist, ensure `load_dotenv()` (if used) is called before `import chainlit`. Consider updating to the latest Chainlit version, as such issues are often addressed.","message":"Configuration defined in `chainlit.toml` (e.g., project name, UI settings) may occasionally be ignored, particularly in certain older versions (e.g., v2.7.2). This can lead to default settings being applied instead of your custom configurations.","severity":"gotcha","affected_versions":"<2.9.4 (and potentially other versions)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}