Developer Integration

NeuroCP offers a robust and adaptable framework for Developer Integration, enabling developers to easily create, customize, and scale AI agents. Whether building new agents, linking external services, or embedding NeuroCP’s AI functionalities into your applications, this framework delivers the comprehensive tools and APIs required for seamless development.

Feature
Description

API Access

RESTful and WebSocket APIs for interacting with AI agents and system components

SDKs

Software Development Kits available for popular programming languages like Python and JavaScript

Custom Agent Creation

Tools and templates to build agents tailored to specific tasks or industries

Event Hooks

Define custom event listeners to trigger actions based on agent activity or user interaction

Context Integration

Seamless access to decentralized context data within your custom applications

Security Controls

Robust authentication and permission systems to protect user data and control access

SDK Installation

Install the official NeuroCP SDK from npm:

npm install @neurocp/sdk

Set your API key in a .env file:

NeuroCP_API_KEY="YOUR_NeuroCP_API_KEY_HERE"

Example: Verifying AI Model Output

Below is a full implementation example for verifying AI outputs using the NeuroCP SDK:

// Import the NeuroCP SDK – your gateway to decentralized AI attestation
import { NeuroCP } from '@neurocp/sdk';

// Initialize the NeuroCP client with your API key
// Ensure your NeuroCP_API_KEY is set in your environment variables for production use.
const ncp = new NeuroCP({
  apiKey: process.env.NeuroCP_API_KEY,
  environment: 'production' // Use 'production' for live deployments
});

/**
 * Validates the output of an AI model using NeuroCP's decentralized attestation network.
 * This process guarantees integrity and transparency of AI-generated content or decisions.
 *
 * @param {string} modelId - The identifier of the AI model (e.g., 'gpt-4o', 'custom-financial-predictor').
 * @param {string} input - The prompt or input given to the AI model.
 * @param {string} output - The exact output generated by the AI model.
 * @returns {Promise<object|null>} The verification details if successful, otherwise null.
 */
async function validateAIModelOutput(modelId, input, output) {
  console.log(`\n--- Beginning Validation for Model: ${modelId} ---`);
  console.log('Input:', input);
  console.log('Output:', output);

  try {
    // Step 1: Request Attestation
    console.log('Requesting attestation from NeuroCP...');
    const attestation = await ncp.createAttestation({
      modelId,
      input,
      output,
      options: {
        includeProof: true,
        storagePolicy: 'persistent'
      }
    });

    console.log(`Attestation created successfully! Attestation ID: ${attestation.id}`);

    // Step 2: Confirm Attestation Validity
    console.log('Verifying the attestation...');
    const verification = await ncp.verifyAttestation(attestation.id);
    
    if (verification.isValid) {
      console.log('✅ AI Output Validated Successfully!');
      console.log(`Verification ID: ${verification.id}`);
      return verification;
    } else {
      console.error('❌ Validation Failed!');
      console.error(`Reason: ${verification.reason}`);
      return null;
    }
  } catch (error) {
    console.error('An error occurred during the validation process:');
    if (error.response) {
        console.error('API Error Status:', error.response.status);
        console.error('API Error Data:', error.response.data);
    } else if (error.request) {
        console.error('Network Error: No response received from NeuroCP API.');
    } else {
        console.error('General Error Message:', error.message);
    }
    throw error;
  } finally {
    console.log('--- Validation Process Completed ---');
  }
}

// --- Example Usage ---

validateAIModelOutput(
  'gpt-4o',
  'What is the capital of France?',
  'The capital of France is Paris.'
).then(result => {
    if (result) {
        console.log('Factual AI output validation passed.');
    } else {
        console.log('Factual AI output validation failed.');
    }
});

validateAIModelOutput(
  'content-moderator-v1',
  'Review the following text for hate speech: "I love sunny days!"',
  'Classification: Clean. No hate speech detected.'
).then(result => {
    if (result) {
        console.log('Content moderation AI output validation passed.');
    } else {
        console.log('Content moderation AI output validation failed.');
    }
}).catch(err => {
    console.error("Content moderation validation encountered an error:", err);
});

Last updated