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
- Handles authentication, helpful errors, and rate-limit messages
- Generic
get/posthelpers for future endpoints
npm install 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('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 'labs-api';
import type { Bot } from './src/types';
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();
await client.postStats({ botId: 'BOT_ID', guildCount: 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 metadata
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/:idlistUsers(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 and post helpers.
- Provide your API key either by passing
{ apiKey: 'sk_...' }toLabsApiClientor by settingLABS_API_KEYin the environment. - See the official API docs for details on permissions 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.
Telemetry
- 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, and optionallyX-SDK-Platform/X-SDK-Node-Version). - To customize or disable telemetry, pass the
telemetryoption when creating the client, for example:new LabsApiClient({ telemetry: { enabled: false } })or overridesdkName/sdkVersion.- 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 Error with descriptive messages. Common messages:
labs-api: API key is required...— you called an authenticated endpoint without an API key.labs-api: Unauthorized. Please check your API key.— 401 from server.labs-api: Rate limit exceeded. Please wait before retrying.— 429 from server.labs-api: Invalid JSON response from API.— unexpected server response.
Inspect .code and .statusCode properties on thrown errors for programmatic handling.
- 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