SDK Examples
End-to-end examples using the Ctrl AI SDK.
SDKs are coming soon. These examples show the planned usage patterns.
Credit Risk Assessment Pipeline
import { CtrlAI } from '@ctrlai/sdk';
const client = new CtrlAI({ apiKey: process.env.CTRLAI_API_KEY! });
// 1. Run the assessment
const result = await client.inference.query({
query: `Assess credit risk for:
- Annual income: $85,000
- Credit score: 720
- DTI ratio: 28%
- Employment: 5 years at current employer`,
domainId: 'finance',
});
// 2. Check coverage
if (result.coveragePercent < 50) {
console.warn('Low coverage — response may contain unverified reasoning');
}
// 3. Extract trust-tagged segments
for (const segment of result.segments) {
if (segment.trustLevel === 'verified') {
// Deterministic, program-computed — safe to use in automated decisions
console.log(`[VERIFIED] ${segment.text}`);
} else if (segment.trustLevel === 'neural') {
// Unverified LLM output — flag for human review
console.log(`[UNVERIFIED] ${segment.text}`);
}
}
// 4. Log the audit trail
console.log('Units fired:', result.unitsUsed.map(u => u.name));
console.log('Models used:', result.modelsUsed);Batch Unit Import
const units = [
{
name: 'DTI Threshold Check',
unitType: 'program' as const,
domainId: 'finance',
given: 'Applicant financial data is available',
when: 'DTI ratio needs to be evaluated against regulatory thresholds',
then: 'Classify risk level based on DTI',
},
{
name: 'Income Stability Assessment',
unitType: 'framework' as const,
domainId: 'finance',
given: 'Employment and income history is available',
when: 'Income stability needs to be evaluated for lending decision',
then: 'Produce income stability score across 6 factors',
},
];
for (const unit of units) {
const created = await client.units.create(unit);
console.log(`Created: ${created.name} (${created.id})`);
}