A TypeScript/Node.js SDK for interacting with Secret AI Confidential LLMs on the Secret Network blockchain.
- Secret Network Integration: Connect to Secret Network smart contracts
- Confidential AI: Interact with Secret AI Confidential LLMs
- Mnemonic Support: Generate private keys from mnemonics
- TypeScript Support: Full TypeScript type definitions
- Streaming Support: Custom streaming handlers for chat responses
- Built-in Authentication: API key management for Secret AI services
npm install secret-ai-sdk-js
import { Secret, ChatSecret } from 'secret-ai-sdk-js';
// Initialize Secret client
const secret = new Secret();
// Get available models
const models = await secret.getModels();
console.log('Available models:', models);
// Get available URLs
const urls = await secret.getUrls();
console.log('Available URLs:', urls);
// Initialize ChatSecret with Secret client
const chatSecret = new ChatSecret({
model: 'deepseek-r1:70b',
baseUrl: 'https://secretai-rytn.scrtlabs.com:21434',
temperature: 0.7
});
import { Secret } from 'secret-ai-sdk-js';
const secret = new Secret();
const mnemonic = 'grant rice replace explain federal release fix clever romance raise often wild taxi quarter soccer fiber love must tape steak together observe swap guitar';
const privateKey = secret.getPrivKeyFromMnemonic(mnemonic);
console.log('Private key:', privateKey);
import { Secret, ChatSecret } from 'secret-ai-sdk-js';
// Custom Secret Network configuration
const secret = new Secret(
'secret-4', // chainId
'https://lcd.secret.express' // nodeUrl
);
// Custom ChatSecret configuration
const chatSecret = new ChatSecret({
model: 'deepseek-r1:70b',
baseUrl: 'https://secretai-rytn.scrtlabs.com:21434',
temperature: 0.7,
clientKwargs: {
timeout: 30000,
headers: {
'X-Custom-Header': 'value'
}
}
});
new Secret(chainId?: string, nodeUrl?: string)
getModels(): Promise<string[]>
- Get available AI modelsgetUrls(model?: string): Promise<string[]>
- Get available URLs for modelsgetPrivKeyFromMnemonic(mnemonic: string): string
- Generate private key from mnemonic
new ChatSecret(config: ChatSecretConfig)
interface ChatSecretConfig {
baseUrl?: string;
model?: string;
temperature?: number;
clientKwargs?: Record<string, any>;
[key: string]: any;
}
getAttestation(): Promise<Record<string, any>>
- Get attestation reportsecretClient
- Get underlying Secret AI clientasyncClient
- Get underlying Secret AI async client
The SDK supports the following environment variables:
SECRET_CHAIN_ID
- Secret Network chain ID (default: 'secret-4')SECRET_NODE_URL
- Secret Network node URL (default: 'https://lcd.secret.express')SECRET_WORKER_SMART_CONTRACT
- Smart contract address for worker managementSECRET_AI_API_KEY
- API key for Secret AI servicesLOG_LEVEL
- Logging level (default: 'info')
import { ChatSecret, SecretStreamingHandler } from 'secret-ai-sdk-js';
// Custom streaming handler
class MyStreamingHandler extends SecretStreamingHandler {
handleLLMNewToken(token: string): void {
process.stdout.write(token);
}
}
const chatSecret = new ChatSecret({
model: 'deepseek-r1:70b',
baseUrl: 'https://secretai-rytn.scrtlabs.com:21434'
});
// Use with streaming
const handler = new MyStreamingHandler();
// ... implement streaming logic
import { Secret, SecretAIError } from 'secret-ai-sdk-js';
try {
const secret = new Secret();
const models = await secret.getModels();
} catch (error) {
if (error instanceof SecretAIError) {
console.error('Secret AI Error:', error.message);
} else {
console.error('Unknown error:', error);
}
}
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Run linting
npm run lint
# Build the project
npm run build
- Node.js 16+
- npm or yarn
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Run linting
npm run lint
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
MIT License
For issues and questions:
- GitHub Issues: Create an issue
- Documentation: Secret Network Docs
- Discord: Secret Network Discord