Skip to content
reaatechREAATECH

Files · Cohere AI Spend Control for Budget-Conscious SMBs

65 (1 binary, 620.7 kB total)attempt 3

README.md·2159 B·markdown
markdown
# Cohere AI Spend Control for Budget-Conscious SMBs
 
> Enforce daily AI spend limits, automatically downgrade to cheaper Cohere models, and get real-time cost dashboards without modifying existing agent code.
 
A tutorialized reference solution from [reaatech.com](https://reaatech.com), demonstrating how to build production-grade AI systems with the `@reaatech/*` package family.
 
## Overview
 
This project prevents unpredictable Cohere API bills via per-tenant budgets, automatic model downgrade (command-a-03-2025 → command-r-03-2025), and real-time dashboards.
 
## Quick Start
 
```bash
pnpm install
cp .env.example .env     # then set COHERE_API_KEY
pnpm dev                 # Next.js dashboard
node --loader tsx src/cli/cost-daemon.ts start  # standalone CLI
```
 
## Architecture
 
```
CohereClientWrapper → CostTelemetryService → BudgetEnforcementService → LLMRouter → Langfuse/Portkey
```
 
## CLI Reference
 
- `start` — Start the cost daemon HTTP server
- `status` — Show all tenant budget states
- `config` — Show current router configuration
- `reset --tenant <name>` — Reset budget for a tenant
 
## API Reference
 
- `GET /api/cost` — Get cost summary
- `POST /api/cost` — Record a cost span
- `PUT /api/cost` — Update cost configuration
- `DELETE /api/cost` — Reset cost data
 
## Environment
 
- `COHERE_API_KEY` — Cohere API key
- `COHERE_DEFAULT_MODEL` — Default model ID (default: command-a-03-2025)
- `COHERE_BUDGET_MODEL` — Budget model ID (default: command-r-03-2025)
- `PORT` — HTTP server port (default: 3000)
- `LANGFUSE_PUBLIC_KEY` — Langfuse public key (optional)
- `LANGFUSE_SECRET_KEY` — Langfuse secret key (optional)
- `PORTKEY_VIRTUAL_KEY` — Portkey virtual key (optional)
 
## Testing
 
```bash
pnpm test    # vitest run with coverage
```
 
## Project layout
 
```
app/                  Next.js App Router pages + API routes
src/                  services, lib, adapters
tests/                vitest suite (mirrors src/)
packages/             API references for every dependency (read these first)
DEV_PLAN.md           build plan for this recipe
```
 
## License
 
MIT — see [LICENSE](./LICENSE).