A user-friendly Node.js/TypeScript client for the Conscherry Labs API. This package makes it simple to fetch public data (bots, users, website stats) and post authenticated bot statistics.
- Simple API for public and authenticated endpoints
- TypeScript definitions included
- Robust error handling with dedicated exception classes
- Built-in request timeouts to prevent hanging calls
- Automatic response normalization for server count aliases
- Generic
get/posthelpers for future endpoints - Configurable
baseUrlandtimeout - Node.js only (uses
undiciandfs); requires Node.js 20.18 or newer
npm install @conscherry/labs-api- Set your API key (for authenticated endpoints)
- Recommended: create a
.envfile and setLABS_API_KEY=sk_.... - Install dotenv for local development and load it at process start:
npm install dotenvrequire('dotenv').config();
// process.env.LABS_API_KEY is now available- Or pass the key to the client directly.
- Use the client
JavaScript (CommonJS):
const { LabsApiClient } = require('@conscherry/labs-api');
const client = new LabsApiClient(); // uses process.env.LABS_API_KEY if present
(async () => {
const bots = await client.listBots({ limit: 5 });
console.log(bots.data);
})();TypeScript:
import { LabsApiClient } from '@conscherry/labs-api';
import type { Bot } from '@conscherry/labs-api';
const client = new LabsApiClient({ apiKey: process.env.LABS_API_KEY });
async function main() {
const result = await client.listBots({ limit: 5 });
const bots = result.data as Bot[];
console.log(bots[0]?.name);
}
main();List bots (public):
const client = new LabsApiClient();
const res = await client.listBots({ limit: 10, sort: '-votes' });
console.log(res.data);Get a bot by ID (public):
const res = await client.getBotById('123456789012345678');
console.log(res.data);Post bot stats (authenticated — requires write:stats permission):
const client = new LabsApiClient();
// Supports guildCount, serverCount, and server_count aliases
await client.postStats({ botId: 'BOT_ID', serverCount: 1000, userCount: 5000 });Generic request (for new endpoints):
// GET /custom
const res = await client.get('/custom', { q: 'search' }, false);
// POST /admin (requires auth)
await client.post('/admin', { action: 'rebuild' }, true);Example scripts (built to dist/):
examples/simple.js— basic public website stats example (opt-out telemetry shown)examples/post-stats.js— authenticatedpostStatsexample usingserverCountaliasexamples/telemetry-enabled.js— enable telemetry and override SDK metadataexamples/generic-request.js— call an endpoint through the genericgethelper
Run an example after building:
npm run build
node examples/post-stats.jsPublic endpoints (no API key required):
listBots(params?)— GET/bots(params:limit,offset,sort,search,category,certified,verified,nsfw)getBotById(id)— GET/bots/:id(the id is URL-encoded)listUsers(params?)— GET/users(params:limit,offset,sort,search)getWebsiteStats()— GET/website
Authenticated endpoints (API key required):
postStats(body)— POST/stats(body:botId,guildCount,userCount,shardCount,uptime,ping,customFields)getStats(params)— GET/stats(params:botIdrequired,limitoptional)
All other documented endpoints are available via the generic get(path, params?, authenticated?) and post(path, body?, authenticated?) helpers. Paths must start with a single / and must not contain a query string; pass query values through params.
| Option | Type | Default |
|---|---|---|
apiKey |
string |
process.env.LABS_API_KEY |
baseUrl |
string |
https://labs.conscherry.com/api/v1 |
timeout |
number (ms) |
15000 |
telemetry |
{ enabled?, sdkName?, sdkVersion?, includePlatform? } |
{ enabled: true } |
- Provide your API key either by passing
{ apiKey: 'sk_...' }toLabsApiClientor by settingLABS_API_KEYin the environment. - See the official API docs for details and key management: https://labs.conscherry.com/developers/docs
- The client will throw a clear error if you attempt an authenticated call without a key.
- This client sends a small set of telemetry headers by default to identify the SDK and runtime to your API (headers:
X-SDK-Name,X-SDK-Version,X-SDK-Lang, andX-SDK-Instance-Id;X-SDK-PlatformandX-SDK-Node-Versionare added whenincludePlatformis true). - To customize or disable telemetry, pass the
telemetryoption when creating the client, for example:new LabsApiClient({ telemetry: { enabled: false } })or overridesdkName/sdkVersion.X-SDK-Instance-Idis a random UUID generated once per client.- Example: opt-out of telemetry
const client = new LabsApiClient({ telemetry: { enabled: false } });- Standard rate limits: ~100 requests/minute (headers
X-RateLimit-*are provided). - Posting stats: allowed once per bot every 5 minutes. Exceeding returns 429 with
Retry-After(seconds). - Best practices:
- Store keys in env vars, not in code.
- Respect
Retry-Afteron 429 responses. - Cache responses when appropriate.
The client throws specific exception classes for different API errors. LabsAPIError is the base class; LabsAPIAuthError covers 401 or a missing key, LabsAPIPermissionError covers 403, LabsAPIRateLimitError covers 429, LabsAPIRequestError covers other HTTP errors and LabsAPIConnectionError covers timeouts, network failures and invalid JSON. Every error exposes statusCode, code, retryAfter and response.
const { LabsAPIAuthError, LabsAPIRateLimitError } = require('@conscherry/labs-api');
try {
await client.getStats({ botId: '...' });
} catch (err) {
if (err instanceof LabsAPIAuthError) {
console.error('Authentication failed');
} else if (err instanceof LabsAPIRateLimitError) {
console.error('Rate limited. Retry after:', err.retryAfter);
} else {
console.error('API Error:', err.message);
}
}- Format:
npm run format - Build:
npm run build - Tests:
npm run test - Example: after build run
node examples/simple.jsto try the example.
- Bump
versioninpackage.json. - Build:
npm run build. - Verify package:
npm pack --dry-run. - Test prepublish:
npm run test. - Publish:
npm loginthennpm publish --access public.
PRs welcome — please open issues for bugs or feature requests.
MIT