A full-stack API usage tracking application built with NestJS, Next.js, Prisma, and PostgreSQL.
The application allows users to generate and use API keys, track api usage, adds token limits, and monitor API activity through a responsive dashboard.
- User signup
- User login
- JWT-based authentication
- Unique API key generated for every user
- Protected API access using
x-api-key
- Accepts text/context input
- token counting using word count
- Tracks API usage
- Enforces token usage limits
- Rate limiting using NestJS Throttler
- View API key
- Total API calls
- Tokens used
- Remaining token limit
- Recent API usage history
- NestJS
- Prisma ORM
- PostgreSQL
- JWT Authentication
- NestJS Throttler
- Next.js
- TypeScript
- Tailwind CSS
- Axios
npm installDATABASE_URL="postgresql://postgres:password@localhost:5432/api_tracker"
JWT_SECRET="your_secret"
PORT=8000npx prisma migrate devnpm run start:devBackend runs on:
http://localhost:8000
npm installNEXT_PUBLIC_API_URL=http://localhost:8000npm run devFrontend runs on:
http://localhost:3000
Request:
{
"name": "Samrood",
"email": "sam@example.com",
"password": "123456"
}Request:
{
"email": "sam@example.com",
"password": "123456"
}Headers:
x-api-key: YOUR_API_KEYRequest:
{
"content": "Hello this is a test request"
}Response:
{
"success": true,
"tokensUsed": 6
}Token usage is simulated by counting words in the provided content.
Example:
"Hello this is a test"
Token count:
5
Protected API endpoints are rate limited using NestJS Throttler.
Current configuration:
- 5 requests per minute
The dashboard displays:
- User API key
- Total API calls
- Total tokens used
- Remaining token limit
- Recent API usage history
- Token limits do not reset automatically.
- API usage history stores successful requests only.
- Authentication uses JWT tokens.
