Back to projects

Project case study

AI Chatbot API

FastAPI chat API with streaming, conversation history and an AI provider switched by an environment variable.

My roleAnalyst/Developer
Technologies used
  • FastAPI
  • Python
  • SQLAlchemy
  • SQLite
  • Pydantic
  • pytest
Typographic plate for the project: the published demo is offline and no capture is available.
Project cover

Problem

Switching AI providers usually means rewriting the integration.

Long replies without streaming leave the interface frozen until the end.

Solution

Architecture at a glance
  • Conversation messages, stored per conversation in SQLite.
Technical decisions
  1. A service layer picks OpenAI, Anthropic or Google through an environment variable.
  2. Replies as JSON or streamed through Server-Sent Events, read by the frontend with a stream reader.
  3. Per-conversation history with routes to list, read and delete.

Result

Interchangeable AI providers
3
Private repository / src/services/ai_service.py / commit 6b0e1e6
API tests
6
Private repository / tests/test_api.py, static count / commit 6b0e1e6

A foundation API that separates the conversation from the provider; the deployment needs a configured key to respond.

  • FastAPI API
  • SSE streaming
  • Provider abstraction
  • Simple persistence

Learnings and limitations

  • The published demo answers HTTP 500: the provider key is missing and there is no demonstration mode.
  • SQLite in a local file does not persist on serverless hosting.
  • The health endpoint reports the model as ready even without a key.

More about the project

Full case details, collapsed for optional reading.

Full description

Web chatbot with a FastAPI API and a static frontend, designed to switch AI providers without rewriting the integration.

The service layer picks OpenAI, Anthropic or Google through an environment variable; OpenAI is the default.

Replies arrive as JSON or streamed through Server-Sent Events, and history is kept per conversation in SQLite.

The published demo is offline: it answers HTTP 500 because the provider key is not configured.

FastAPI with SQLAlchemy and SQLite, Pydantic, sse-starlette for streaming and the OpenAI, Anthropic and Google SDKs.

Features and highlights
  • Chat with a full or streamed reply.
  • Persisted conversation history.
  • List, open and delete conversations.
  • Markdown and code highlighting in replies.
  • OpenAPI documentation at /api/docs.
  • Streams replies through Server-Sent Events.
  • Switches the AI provider through an environment variable.
  • Keeps per-conversation history in SQLite.
  • Exposes the API documented in OpenAPI.
Technical architecture and data

Technical architecture

How the case was designed as a product

FastAPI chat API with streaming, conversation history and an AI provider switched by an environment variable.

FastAPIFrameworkPythonLanguageSQLAlchemyDatabaseSQLiteDatabasePydanticFrameworkpytestFramework

Data used

  • Conversation messages, stored per conversation in SQLite.

Core components

  • Chat with a full or streamed reply.
  • Persisted conversation history.
  • List, open and delete conversations.
  • Markdown and code highlighting in replies.
  • OpenAPI documentation at /api/docs.

Technical decisions

  • FastAPI API
  • SSE streaming
  • Provider abstraction
  • Simple persistence

Trade-offs

  • The published demo answers HTTP 500: the provider key is missing and there is no demonstration mode.
  • SQLite in a local file does not persist on serverless hosting.
  • The health endpoint reports the model as ready even without a key.
How to run
  1. The repository is private; the steps below apply to anyone with access.
  2. python -m venv venv and activate the environment.
  3. pip install -r requirements.txt
  4. cp .env.example .env and set the chosen provider's key.
  5. python src/main.py
Additional media
Chatbot demonstration video
Credits

Developed by Matheus Siqueira - https://www.matheusdev.tech

Next projectENCOM Gesture Console

Futuristic console with webcam gesture detection, visual telemetry, and real-time 3D effects.

View full case