A complete AI platform that makes multiple models available from a single application. It features an API platform that has been built out to provide a range of AI interactions and applications alongside a React frontend and a mobile application (in development).
Check out my write up on this project here. I've also launched a version of this to try out at polychat.app.
Note
Please note that this project is still in active development so there are a few features that are not yet fully working or fully imagined. You can check out our roadmap here.
Here are some example chats that you can try out:
- Generation of a new React component
- Code generation and execution
- Web search integration
- Perplexity Deep Research
- Combined artifact previews
- Markdown formatting
- Search Grounding
This project is organized as a monorepo with multiple applications:
- app - Web and mobile frontend application built with React, TailwindCSS, and React Router
- api - Backend API built with Cloudflare Workers that interfaces with AI models and manages user data
- database - Shared database schema and migrations using Drizzle ORM
- metrics - Analytics and monitoring application to track usage and performance
- API structure designed to match the OpenAI API for easy integration with various SDKs and applications.
- Multiple provider and model support
- Anthropic
- Bedrock
- DeepSeek
- OpenAI
- Google AI Studio
- Grok
- Groq
- Hugging Face
- Mistral
- OpenRouter
- Perplexity
- Replicate
- Cloudflare AI
- Ollama
- Github Models
- Together AI
- An AI assisted podcasting app
- Drawing to painting and guessing the drawing app
- Llamaguard Guardrails Support
- Bedrock Guardrails Support
- Benchmarking
- RAG with Vectorize
- Automated model routing
- Bedrock Knowledge Bases
- Prompt Coaching
- Monitoring with Cloudflare Analytics Engine
- Media uploading to Cloudflare R2
- Multiple authentication methods:
- GitHub OAuth
- Session-based authentication
- JWT authentication
- API token authentication
- A frontend application built with React and TailwindCSS
- Uses the API app for authentication and AI requests
- Retrieves and displays conversations and makes it easy to create new ones
- Has the option to store conversations locally in IndexedDB or in LocalStorage (if IndexedDB is not supported)
- Set chat titles and delete chats
- Configure settings and models
- Web LLM support for completely offline usage
- The API is deployed as a Cloudflare Worker and the frontend is deployed with Cloudflare Assets
-
Clone the repository
-
Install dependencies
pnpm install
-
Configure environment variables:
- Copy
.dev.vars.example
to.dev.vars
in all the apps directories that have them. - Copy
wrangler.jsonc.example
towrangler.jsonc
in all the apps directories that have them. - Adjust with your API keys and configuration values.
- Copy
-
Start the development servers:
# Start all apps in development mode pnpm run dev # Or start individual apps pnpm run dev:app pnpm run dev:api pnpm run dev:metrics
The applications are designed to be deployed to Cloudflare:
# Deploy all applications
npm run deploy
# Deploy individual applications
npm run deploy:app
npm run deploy:api
npm run deploy:metrics
- User initiates login by visiting:
https://api.polychat.app/auth/github
- User is redirected to GitHub to authorize the application
- After authorization, GitHub redirects back to
https://api.polychat.app/auth/github/callback
- The API creates or updates the user record and generates a session
- User is redirected back to the specified
redirect_uri
with a session cookie set - The application can choose to use the session cookie or generate a JWT token
The authentication system uses HTTP cookies for session management. When a user successfully authenticates, a session
cookie is set with the session ID.
For API requests, the session ID can be included in one of these ways:
- Automatically via the session cookie (for browser-based requests)
- As a Bearer token in the Authorization header:
Authorization: Bearer your_session_id
To get information about the authenticated user, make a GET request to /auth/me
. This endpoint will use the session cookie or Authorization header to identify the user.
To generate a JWT token for the authenticated user, make a POST request to /auth/token
. This endpoint will use the session cookie or Authorization header to identify the user.
The JWT token will be returned in the response body and can then be used to make API requests to the other endpoints.
To log out, make a POST request to /auth/logout
. This will invalidate the session and clear the session cookie.
The application supports multiple AI providers through a unified API interface. To use a specific provider:
- Configure the API keys in your environment variables
- Select the provider and model in the frontend settings or specify them in API requests
Example API request:
POST /chat/completions
{
"model": "gpt-4",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello world!"}
]
}
The application uses a Cloudflare D1 database with Drizzle ORM for schema management and migrations.
cd apps/database
# Migrate to the local database
pnpm run db:migrate:local
# Migrate to the preview database
pnpm run db:migrate:preview
# Migrate to the production database
pnpm run db:migrate:prod
To generate a new migration, run:
pnpm run db:generate
The metrics application provides dashboards for monitoring:
- API usage and performance
- Model performance and costs
- User activity and engagement
Access the metrics dashboard at metrics.polychat.app.
Note
The mobile application is not yet fully developed and is not ready for use.
The project includes a mobile application built with Capacitor:
# Build the web app
cd apps/app
npm run build
# Add mobile platforms
npx cap add ios
npx cap add android
# Sync web code to mobile projects
npx cap sync
# Open in native IDEs
npx cap open ios
npx cap open android
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the terms of the license included in the repository.