A serverless API that provides sequential user agents (UAs) on-demand. The project generates user agents locally, uploads them to Vercel, and serves them with persistent indexing.
Last Updated: 2025-11-01
Total User Agents: 5,000
Current Index: 1
💡 Note: Update these values in this README when deploy to production. The current index should match your Redis database state.
Divyanshu Patel
📧 Email: itzdivyanshupatel@gmail.com
This project is open for all! Feel free to use, modify, and distribute it for any purpose.
Please give credit when using this project in your work. A simple attribution is appreciated:
Credits: User Agent Server by Divyanshu Patel
If you have any questions, suggestions, or need help with this project, feel free to reach out:
- 📧 Email: itzdivyanshupatel@gmail.com
- 👤 Author: Divyanshu Patel
Don't hesitate to ask! 🚀
USERAGENTS/
├── useragent-generate/ # Local UA generation script
│ └── generate-ua.py # Python script to generate UAs
├── ua-server/ # Vercel serverless API
│ ├── api/
│ │ └── ua.js # API endpoint handler
│ ├── data/
│ │ └── ua.json # Generated user agents data
│ └── package.json # Server dependencies
└── README.md # This file
- Generate User Agents: Run the Python script locally to generate user agents
- Upload to Vercel: Deploy the
ua-serverfolder to Vercel - API Request: Your app calls the API endpoint
- Sequential Delivery: Server returns the next UA and increments the index
- Persistent State: Index is stored in Vercel KV to maintain state across requests
cd useragent-generate
python generate-ua.py- Choose browser type (Chrome, Firefox, Edge, Mix, or All)
- Enter count (default: 1000)
- Output:
latest-useragents.json
Copy the generated JSON to the server:
# Copy latest-useragents.json to ua-server/data/ua.json
cp useragent-generate/latest-useragents.json ua-server/data/ua.jsonKV is now available through the Vercel Marketplace via Upstash:
- Go to Vercel Dashboard
- Go to Storage → Create New
- Select "Upstash" from the Marketplace
- Choose "Upstash Redis" (Redis-based key-value store)
- Follow the prompts to create the Redis database
- IMPORTANT: After creating, connect it to your project:
- On the Upstash Redis database page, click "Connect to a project"
- Select your
ua-serverproject - Click "Connect"
- Vercel will automatically add environment variables:
KV_REST_API_URLKV_REST_API_TOKENKV_REST_API_READ_ONLY_TOKENREDIS_URL
Free Tier (Hobby Plan):
- ✅ 1 KV database
- ✅ 30,000 requests per month
- ✅ 256 MB storage
- ✅ 256 MB data transfer per month
Perfect for personal projects and low-traffic apps!
cd ua-server
npm installThis installs @upstash/redis for Redis connectivity.
vercel deployvercel deploy --prodOr use Vercel CLI or connect your GitHub repo.
Note: The environment variables (KV_REST_API_URL, KV_REST_API_TOKEN, etc.) are automatically configured by Vercel when you connect the Upstash Redis database to your project.
When deploying to production, you can control the index behavior:
Option 1: Continue from Last Index (Default)
- Don't set any variable
- Index continues from where you left off
Option 2: Restart from Index 1
- Set environment variable:
RESET_INDEX=truein Vercel Dashboard - See
ua-server/DEPLOYMENT_INDEX_CONTROL.mdfor details
Option 3: Start from Custom Index
- Set environment variable:
START_INDEX=250(any number) - See
ua-server/DEPLOYMENT_INDEX_CONTROL.mdfor details
📖 Full guide: See ua-server/DEPLOYMENT_INDEX_CONTROL.md for step-by-step instructions.
Endpoint: https://ua-server.vercel.app/api/ua
Method: GET
Response:
{
"authorisedUserAgent": "Mozilla/5.0 ...",
"indexReturned": 1,
"total": 5000,
"updated": "2025-10-29",
"browserChoice": "mix"
}Each request returns the next user agent sequentially. Index wraps around after reaching the total.
Why the index was resetting:
- Stateless Edge Functions: Vercel Edge Functions don't maintain state between requests
- Multiple Edge Locations: Your requests can hit different edge locations, each with its own in-memory state
- Instance Recycling: After idle time, edge function instances are killed and restarted, resetting in-memory variables
- No Persistence: The original code used
let currentIndex = 0which is lost on each restart
What you observed:
- Immediate check → Returns next UA (works within the same instance's lifecycle)
- After some time → Starts from 1 again (instance restarted, index reset)
Upstash Redis (via Vercel Marketplace):
- Stores the index in a shared Redis database accessible by all edge locations
- Index persists across function restarts, deployments, and edge locations
- Provides truly global state for your application
- Uses
@upstash/redisSDK for reliable connectivity - Free tier includes 30,000 requests/month (perfect for this use case)
How it works now:
- Each API request reads the current index from KV
- Increments the index and saves it back to KV
- All edge locations share the same KV store, ensuring consistency
- Index resets: Ensure Vercel KV is properly configured with environment variables
- CORS issues: Already handled with
Access-Control-Allow-Origin: * - Empty responses: Check that
ua.jsonis properly formatted