DEV Community

Alex Spinov
Alex Spinov

Posted on

Chainlit Has a Free API You Should Know About

Chainlit is an open-source framework for building production-ready AI chatbot UIs in Python. It handles the chat interface, file uploads, streaming, and conversation history — you focus on the AI logic.

Why Chainlit Beats Custom Chat UIs

A developer spent a week building a React chat frontend for their LLM app — message bubbles, streaming, file uploads, conversation threading. Chainlit provides all of this with a Python decorator.

Key Features:

  • Chat UI — Production-ready chat interface
  • Streaming — Real-time token streaming
  • File Uploads — Handle documents, images, audio
  • Conversation History — Persistent chat memory
  • Multi-Step Reasoning — Show intermediate steps
  • Authentication — Built-in auth support

Quick Start

pip install chainlit
Enter fullscreen mode Exit fullscreen mode
import chainlit as cl

@cl.on_message
async def main(message: cl.Message):
    response = await call_llm(message.content)
    await cl.Message(content=response).send()
Enter fullscreen mode Exit fullscreen mode
chainlit run app.py
Enter fullscreen mode Exit fullscreen mode

With OpenAI Streaming

import chainlit as cl
from openai import AsyncOpenAI

client = AsyncOpenAI()

@cl.on_message
async def main(message: cl.Message):
    msg = cl.Message(content="")
    stream = await client.chat.completions.create(
        model="gpt-4", messages=[{"role": "user", "content": message.content}],
        stream=True
    )
    async for chunk in stream:
        if chunk.choices[0].delta.content:
            await msg.stream_token(chunk.choices[0].delta.content)
    await msg.send()
Enter fullscreen mode Exit fullscreen mode

Why Choose Chainlit

  1. Production-ready UI — no frontend development needed
  2. Streaming built-in — real-time responses
  3. LangChain/LlamaIndex integration — works with popular frameworks

Check out Chainlit docs to get started.


Building AI chatbots? Check out my Apify actors or email spinov001@gmail.com for data extraction.

Top comments (0)