glucoguard
v0.1.0
Published
TypeScript client for the GlucoGuard diabetes and cardiovascular risk prediction API
Maintainers
Readme
glucoguard — TypeScript/JavaScript SDK
Typed client for the GlucoGuard REST API. Works in Node 18+ and modern browsers. Zero runtime dependencies.
Install
npm install glucoguard
# or
pnpm add glucoguard
# or
yarn add glucoguardQuick start
import { GlucoGuard } from 'glucoguard';
const gg = new GlucoGuard({ apiKey: 'sk_live_...' });
const result = await gg.predictDiabetes({
age: 55,
gender: 0,
bmi: 30,
systolic_bp: 140,
diastolic_bp: 88,
hba1c: 6.5,
});
console.log(`Risk: ${result.risk_score}% (${result.risk_category})`);
for (const factor of result.top_factors.slice(0, 3)) {
console.log(` ${factor.feature}: ${factor.direction} (${factor.shap_value.toFixed(3)})`);
}Batch predictions
const patients = [
{ age: 55, gender: 0, bmi: 30, systolic_bp: 140, diastolic_bp: 88 },
{ age: 35, gender: 1, bmi: 22, systolic_bp: 118, diastolic_bp: 72 },
];
const result = await gg.predictBatch(patients);
if (GlucoGuard.isInlineResult(result)) {
console.log(`Processed ${result.total} patients in ${result.processing_time_ms}ms`);
for (const item of result.results) {
console.log(`Patient ${item.index}: diabetes ${item.diabetes.risk_score}%`);
}
}Webhook batch jobs
For long-running batches, pass a webhookUrl and GlucoGuard will POST the
result to your endpoint when complete. The response includes the signed
HMAC-SHA256 signature in X-GlucoGuard-Signature.
const ack = await gg.predictBatch(patients, {
webhookUrl: 'https://your-server.com/glucoguard-hook',
});
if (GlucoGuard.isWebhookResult(ack)) {
console.log(`Job queued: ${ack.job_id}`);
}Error handling
Every failure is a typed error. Check with instanceof:
import {
GlucoGuard,
AuthenticationError,
RateLimitError,
ValidationError,
GlucoGuardError,
} from 'glucoguard';
try {
await gg.predictDiabetes(patient);
} catch (err) {
if (err instanceof AuthenticationError) {
console.error('Bad API key');
} else if (err instanceof RateLimitError) {
console.error('Slow down and retry');
} else if (err instanceof ValidationError) {
console.error('Bad request:', err.message);
} else if (err instanceof GlucoGuardError) {
console.error(`API error ${err.statusCode}: ${err.message}`);
console.error(`request_id: ${err.requestId}`); // useful for support
}
}Ops endpoints
await gg.health(); // public liveness probe
await gg.status(); // detailed status + model versions
await gg.usage(7); // your key's usage over 7 days
await gg.modelInfo('diabetes'); // model metrics + feature importance
await gg.samplePatients(); // pre-configured demo patientsPDF reports
import { writeFile } from 'node:fs/promises';
const bytes = await gg.generatePDFReport({
patient,
diabetes_result: diabetesResult,
cvd_result: cvdResult,
patient_name: 'Jane Smith',
});
await writeFile('report.pdf', Buffer.from(bytes));Browser usage
The client uses the built-in fetch API, so it works in modern browsers
with zero config. Do not expose your API key in client-side code —
always call the API from a trusted backend and proxy requests.
// browser-only — proxy through your own backend
const gg = new GlucoGuard({
apiKey: 'sk_live_server_proxy_token',
baseUrl: '/proxy/glucoguard', // your backend forwards to the real API
});Node 16 or older
The SDK requires a fetch implementation. Node 18+ has it built in.
For older versions:
npm install undiciimport { fetch } from 'undici';
import { GlucoGuard } from 'glucoguard';
const gg = new GlucoGuard({
apiKey: 'sk_live_...',
fetch: fetch as unknown as typeof globalThis.fetch,
});TypeScript
Every method is fully typed. The package ships with .d.ts files, so
IDE autocompletion works out of the box.
import type { PatientInput, PredictionResult } from 'glucoguard';
function makePatient(): PatientInput {
return { age: 55, gender: 0, bmi: 30, systolic_bp: 140, diastolic_bp: 88 };
}Links
- API docs: https://glucoguard.analyticadss.com/docs
- Web app: https://glucoguard.analyticadss.com
- Status: https://glucoguard.analyticadss.com/status.html
- Issues: mailto:[email protected]
Built by Analytica Data Science Solutions.
