JavaScript/TypeScript SDK
The official JavaScript/TypeScript SDK for Vehk Axle Fleet Management Platform.
Installation
npm install vehk-axle
# or
yarn add vehk-axle
Requirements: Node.js 14+ or modern browser
Quick Start
import { VehkClient } from 'vehk-axle';
// Initialize client
const client = new VehkClient('vehk_your_api_key');
// Send telemetry
await client.telemetry.send({
vehicle_id: 'VH-001',
sensor_data: { speed: 65, rpm: 2500 }
});
// Get prediction
const prediction = await client.predictions.get('VH-001', { speed: 65, rpm: 2500 });
console.log(`Health: ${prediction.health_score}%`);
Client Configuration
import { VehkClient } from 'vehk-axle';
const client = new VehkClient(
'vehk_your_api_key',
'https://api.vehk.in' // Custom URL (optional)
);
TypeScript Types
The SDK is fully typed. Import types as needed:
import {
VehkClient,
TelemetryData,
Prediction,
Vehicle,
BatchResult,
HealthStatus,
RiskLevel
} from 'vehk-axle';
Telemetry API
Send Single Telemetry
const response = await client.telemetry.send({
vehicle_id: 'TRUCK-001',
sensor_data: {
speed: 65,
rpm: 2500,
coolant_temp: 92,
fuel_level: 45,
battery_voltage: 12.6
},
timestamp: '2026-01-14T10:00:00Z', // Optional
location: { lat: 12.97, lng: 77.59 } // Optional
});
console.log(response.telemetry_id);
Send Batch Telemetry
const result = await client.telemetry.sendBatch([
{ vehicle_id: 'TRUCK-001', sensor_data: { speed: 65, rpm: 2500 } },
{ vehicle_id: 'TRUCK-002', sensor_data: { speed: 70, rpm: 2800 } },
{ vehicle_id: 'TRUCK-003', sensor_data: { speed: 55, rpm: 2200 } },
]);
console.log(`Processed: ${result.records_processed}`);
console.log(`Time: ${result.processing_time_ms}ms`);
Predictions API
Get Prediction
const prediction = await client.predictions.get('TRUCK-001', {
speed: 65,
rpm: 2500,
coolant_temp: 92
});
console.log(`Health Score: ${prediction.health_score}%`);
console.log(`Status: ${prediction.health_status}`);
console.log(`Risk: ${prediction.risk_level}`);
// Get maintenance alerts
prediction.maintenance_alerts.forEach(alert => {
console.log(`- ${alert.type}: ${alert.description}`);
});
// Get recommendations
prediction.recommendations.forEach(rec => {
console.log(`💡 ${rec}`);
});
List Recent Predictions
// Get all recent predictions
const predictions = await client.predictions.list();
// Filter by vehicle
const vehiclePredictions = await client.predictions.list('TRUCK-001', 10);
predictions.forEach(p => {
console.log(`${p.vehicle_id}: ${p.health_score}%`);
});
Vehicles API
List All Vehicles
const vehicles = await client.vehicles.list();
vehicles.forEach(vehicle => {
console.log(`${vehicle.vehicle_id}: ${vehicle.make} ${vehicle.model}`);
console.log(` Health Score: ${vehicle.health_score}%`);
});
Error Handling
import { VehkClient } from 'vehk-axle';
const client = new VehkClient('vehk_your_key');
try {
const prediction = await client.predictions.get('VH-001', { speed: 65 });
console.log(prediction.health_score);
} catch (error) {
if (error.message.includes('[401]')) {
console.error('❌ Invalid API key');
} else if (error.message.includes('[429]')) {
console.error('⏳ Rate limited');
} else if (error.message.includes('[503]')) {
console.error('🔌 Service unavailable');
} else {
console.error('⚠️ Error:', error.message);
}
}
TypeScript Interfaces
TelemetryData
interface TelemetryData {
vehicle_id: string;
sensor_data: Record<string, any>;
timestamp?: string;
location?: { lat: number; lng: number };
}
Prediction
interface Prediction {
vehicle_id: string;
health_score: number;
health_status: 'critical' | 'warning' | 'healthy' | 'unknown';
risk_level: 'high' | 'medium' | 'low' | 'none';
components: Record<string, ComponentHealth>;
maintenance_alerts: MaintenanceAlert[];
recommendations: string[];
confidence: number;
metadata: {
model_version: string;
processing_time_ms: number;
timestamp: string;
};
}
Vehicle
interface Vehicle {
id: string;
vehicle_id: string;
vin?: string;
make?: string;
model?: string;
year?: number;
registration?: string;
health_score?: number;
}
Browser Usage
The SDK works in browsers with bundlers like Webpack or Vite:
// React example
import { VehkClient } from 'vehk-axle';
function FleetDashboard() {
const [vehicles, setVehicles] = useState([]);
useEffect(() => {
const client = new VehkClient(process.env.REACT_APP_VEHK_API_KEY);
client.vehicles.list().then(setVehicles);
}, []);
return (
<div>
{vehicles.map(v => (
<div key={v.id}>
{v.vehicle_id}: {v.health_score}%
</div>
))}
</div>
);
}
Node.js Backend Example
import express from 'express';
import { VehkClient } from 'vehk-axle';
const app = express();
const vehk = new VehkClient(process.env.VEHK_API_KEY!);
app.post('/api/telemetry', async (req, res) => {
const { vehicle_id, sensor_data } = req.body;
// Forward to Vehk
const result = await vehk.telemetry.send({
vehicle_id,
sensor_data
});
res.json(result);
});
app.get('/api/predictions/:vehicleId', async (req, res) => {
const prediction = await vehk.predictions.get(
req.params.vehicleId,
req.body.sensor_data
);
res.json({
health_score: prediction.health_score,
status: prediction.health_status,
recommendations: prediction.recommendations
});
});
app.listen(3000);
Health Check
// Check if API is reachable
const health = await client.healthCheck();
console.log(`API Status: ${health.status}`);
Supported Sensor Fields
| Field | Description | Unit |
|---|---|---|
speed | Vehicle speed | km/h |
rpm | Engine RPM | RPM |
coolant_temp | Coolant temperature | °C |
fuel_level | Fuel level | % |
battery_voltage | Battery voltage | V |
oil_pressure | Oil pressure | PSI |
throttle | Throttle position | % |
intake_air_temp | Intake air temperature | °C |
ambient_temp | Ambient temperature | °C |
odometer | Odometer reading | km |