Backend API server for Ajatuskumppani - Finnish-first open-source decentralized AI platform.
- 🤖 Fireworks AI Integration - Chat completions with streaming support
- 💳 Stripe Payments - AJT token purchases via credit card
- 🔐 Wallet-based Auth - Solana wallet address authentication
- 📊 Balance Management - Track AJT token consumption
- 🚀 FastAPI - Modern, fast, async Python web framework
- Framework: FastAPI 0.115+
- AI Provider: Fireworks AI (Llama 4 Maverick)
- Payments: Stripe
- Server: Uvicorn (ASGI)
- Python 3.11+
- Fireworks AI API key
- Stripe account (for payments)
- Clone the repository
git clone https://github.com/Jiikooan/ajatus-server.git
cd ajatus-server- Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Configure environment variables
cp .env.example .env
# Edit .env with your API keysRequired environment variables:
FIREWORKS_API_KEY- Get from Fireworks AISTRIPE_SECRET_KEY- Get from Stripe DashboardSTRIPE_WEBHOOK_SECRET- Create webhook endpoint in StripePORT- Server port (default: 8000)
- Run the server
# Development mode with auto-reload
python main.py
# Or with uvicorn directly
uvicorn main:app --reload --host 0.0.0.0 --port 8000GET /Returns server status and configuration.
Response:
{
"status": "online",
"service": "Ajatuskumppani API",
"version": "1.0.0",
"fireworks_available": true,
"stripe_configured": true,
"timestamp": "2025-11-27T19:00:00"
}POST /api/chatSend messages to Fireworks AI and receive responses. Supports streaming.
Request Body:
{
"messages": [
{"role": "user", "content": "Hei! Mikä on Suomen pääkaupunki?"}
],
"model": "accounts/fireworks/models/llama-v4-maverick",
"stream": true,
"max_tokens": 2048,
"temperature": 0.7,
"wallet_address": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU"
}Response (Streaming):
data: {"content": "Suomen"}
data: {"content": " pääkaupunki"}
data: {"content": " on"}
data: {"content": " Helsinki"}
data: [DONE]
Response (Non-streaming):
{
"content": "Suomen pääkaupunki on Helsinki.",
"model": "accounts/fireworks/models/llama-v4-maverick",
"usage": {
"prompt_tokens": 15,
"completion_tokens": 8,
"total_tokens": 23
}
}GET /api/balance?wallet_address=7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsUGet AJT token balance for a wallet address.
Response:
{
"wallet_address": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
"balance": 1000,
"consumed": 0,
"last_updated": "2025-11-27T19:00:00"
}POST /api/create-checkout-sessionCreate a Stripe checkout session for purchasing AJT tokens.
Request Body:
{
"amount": 10000,
"currency": "usd",
"success_url": "https://ajatuskumppani.manus.space/payment/success",
"cancel_url": "https://ajatuskumppani.manus.space/chat",
"wallet_address": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU"
}Response:
{
"sessionId": "cs_test_a1b2c3d4e5f6g7h8i9j0",
"url": "https://checkout.stripe.com/c/pay/cs_test_..."
}POST /api/stripe-webhookWebhook endpoint for Stripe payment events. Automatically credits AJT tokens after successful payment.
Headers:
stripe-signature: Webhook signature for verification
- Initial Credits: 1000 AJT (free)
- Chat Cost: 1 AJT per message
- Purchase Rate: 1000 AJT = $1 USD
ajatus-server/
├── main.py # FastAPI application
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .env # Your environment variables (git-ignored)
├── README.md # This file
└── .gitignore # Git ignore rules
# Install test dependencies
pip install pytest httpx
# Run tests
pytestOnce the server is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]Set these in your deployment platform:
FIREWORKS_API_KEYSTRIPE_SECRET_KEYSTRIPE_WEBHOOK_SECRETPORTENVIRONMENT=production
- ✅ CORS configured for specific origins
- ✅ Stripe webhook signature verification
- ✅ Input validation with Pydantic
⚠️ TODO: Add rate limiting⚠️ TODO: Add JWT authentication⚠️ TODO: Replace in-memory storage with PostgreSQL
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE file for details
- Email: ajatuskumppani@pinnacore.ai
- GitHub: https://github.com/Jiikooan/ajatus-server
- Discord: https://discord.gg/ajatuskumppani
- PostgreSQL database integration
- Redis caching layer
- Rate limiting per wallet
- JWT authentication
- Docker sandbox for code execution
- WebSocket support for real-time updates
- Monitoring and analytics
- Multi-model support (GPT-4, Claude, etc.)