Unkey is an open-source API key management and rate limiting service. Create, validate, and revoke API keys with built-in analytics.
Create API Key
import { Unkey } from "@unkey/api";
const unkey = new Unkey({ rootKey: process.env.UNKEY_ROOT_KEY });
const { result } = await unkey.keys.create({
apiId: "api_123",
prefix: "sk",
name: "My App Key",
ownerId: "user_456",
meta: { plan: "pro" },
expires: Date.now() + 30 * 24 * 60 * 60 * 1000, // 30 days
ratelimit: { type: "fast", limit: 100, refillRate: 10, refillInterval: 1000 },
remaining: 1000 // usage limit
});
console.log(result.key); // sk_abc123...
Verify API Key
const { result } = await unkey.keys.verify({ key: "sk_abc123..." });
if (result.valid) {
console.log("Owner:", result.ownerId);
console.log("Meta:", result.meta);
console.log("Remaining:", result.remaining);
} else {
console.log("Invalid:", result.code); // NOT_FOUND, EXPIRED, RATE_LIMITED, USAGE_EXCEEDED
}
Rate Limiting
const { result } = await unkey.ratelimits.limit({
namespace: "api",
identifier: userId,
limit: 10,
duration: 60000 // 10 requests per minute
});
if (!result.success) {
return new Response("Rate limited", { status: 429 });
}
Key Features
- API key creation and management
- Real-time key verification
- Rate limiting
- Usage tracking with remaining counts
- Analytics dashboard
Need to scrape or monitor web data at scale? Check out my web scraping actors on Apify or email spinov001@gmail.com for custom solutions.
Top comments (0)