Initialization and Setup

In your main application file, import and set up the Skynet-SmartAccessPoint with your project’s core services.

Here is an example initialization:

import dotenv from 'dotenv';
dotenv.config();

import express from 'express';
import { initAIAccessPoint } from '@decloudlabs/Skynet-SmartAccessPoint /lib/init';
import { checkBalance } from '@decloudlabs/Skynet-SmartAccessPoint /lib/middleware/checkBalance';
import { protect } from '@decloudlabs/Skynet-SmartAccessPoint /lib/middleware/auth';
import SkyMainNodeJS from '@decloudlabs/skynet/lib/services/SkyMainNodeJS';
import { getSkyNode } from './clients/skynet';

const app = express();
const port = process.env.PORT || 3000;

const setupAccessPoint = async () => {
    const skyNode: SkyMainNodeJS = await getSkyNode();

    await initAIAccessPoint(
        skyNode,
        checkBalanceCondition,
        applyCosts,
        app,
        runNaturalFunction
    );

    app.listen(port, () => {
        console.log(`Server running on port ${port}`);
    });
};

setupAccessPoint();

The initAIAccessPoint function sets up the necessary routes and middleware, allowing you to securely manage AI access while enforcing balance checks and service control.

Last updated