Axium Engine API Documentation

Quick Start

Get multi-AI orchestration running in under a minute. Five lines of code, one import, zero infrastructure.

JavaScript
import { AxiumEngine } from '@axium/engine';

const engine = new AxiumEngine();
await engine.initialize({
  licenseKey: process.env.AXIUM_LICENSE_KEY,
  bundleId: 'com.yourapp.id'
});

// You're ready to use multi-AI orchestration
const provider = engine.routeByComplexity("What is quantum computing?");
console.log(provider); // "gpt-4o-mini" (routed to cheapest adequate model)
The engine automatically loads the WebAssembly binary for maximum performance. If WASM is unavailable, it falls back to a pure TypeScript implementation with identical API surface.

Installation

Install the Axium Engine package from npm.

Terminal
npm install @axium/engine

Requirements

Requirement Minimum Version Notes
Node.js 18.0+ LTS recommended
WebAssembly MVP All modern browsers and Node.js 8+
Browser Chrome 57+, Firefox 52+, Safari 11+ Edge 16+ also supported
WebAssembly support is available in all modern browsers and Node.js versions. If your environment does not support WASM, the engine automatically falls back to a TypeScript implementation with identical behavior.

Initialization

Initialize the engine with your license key before calling any other methods.

engine.initialize(options)

Validates your license, loads the WASM binary, and prepares the engine for use. Must be called once before any other method.

Parameter Type Required Description
licenseKey string Required Your license key from the Axis Radius dashboard
bundleId string Required Your app's bundle ID (e.g., "com.yourapp.id")
requireWASM boolean Optional If true, throws an error instead of falling back to TypeScript. Default: false
Returns

Promise<void>

Throws

Error if license is invalid, expired, or bundle ID does not match.

JavaScript
const engine = new AxiumEngine();

// Standard initialization (auto-fallback to TS if WASM unavailable)
await engine.initialize({
  licenseKey: process.env.AXIUM_LICENSE_KEY,
  bundleId: 'com.myapp.production'
});

// Strict WASM mode (fails if WASM can't load)
await engine.initialize({
  licenseKey: process.env.AXIUM_LICENSE_KEY,
  bundleId: 'com.myapp.production',
  requireWASM: true
});

Multi-AI Orchestration

Coordinate multiple AI providers in a single session. Each AI gets unique instructions so they contribute distinct perspectives instead of repeating each other.

engine.getDifferentiationPrompt(config)

Generates a unique system prompt for each AI provider in a multi-AI session. This is the core differentiator that prevents AI responses from converging on the same answer.

Parameter Type Description
config.position number This AI's position in the sequence (1 = first, 2 = second, etc.)
config.totalProviders number Total number of AI providers in the session
config.mode string Session mode: "roundtable", "debate", "brainstorm", "redTeam", or "build"
config.previousResponses string[] Responses from earlier AI providers in this session
Returns

string — The differentiated prompt to send to this AI provider.

JavaScript
// Three-AI debate session
const prompt1 = engine.getDifferentiationPrompt({
  position: 1,
  totalProviders: 3,
  mode: 'debate',
  previousResponses: []
});
// Send prompt1 to GPT-4o, get response...

const prompt2 = engine.getDifferentiationPrompt({
  position: 2,
  totalProviders: 3,
  mode: 'debate',
  previousResponses: [gpt4oResponse]
});
// Send prompt2 to Claude — it knows what GPT-4o said and takes a different angle

engine.getModeEnhancement(mode)

Returns mode-specific behavioral instructions that shape how AIs interact within a session.

Parameter Type Description
mode string "roundtable", "debate", "brainstorm", "redTeam", or "build"
Returns

string — Mode-specific behavioral instructions.

engine.getRetryPrompt(previousResponses)

When an AI's response is flagged as too similar to previous ones, this generates a stronger differentiation prompt to force a unique perspective on retry.

Parameter Type Description
previousResponses string[] All responses collected so far in the session
Returns

string — A reinforced differentiation prompt.


Deduplication & Similarity

Detect when AI responses overlap and automatically trigger retries for unique perspectives.

engine.calculateSimilarity(newResponse, previousResponses)

Compares a new response against all previous responses using keyword extraction and overlap analysis. Returns a similarity score and verdict.

Parameter Type Description
newResponse string The new response to evaluate
previousResponses string[] All previous responses to compare against
Returns
TypeScript
{
  score: number;            // 0-1, higher = more similar
  verdict: string;          // "unique", "similar", or "duplicate"
  overlappingKeywords: string[]; // Shared keywords between responses
}
JavaScript — Example
const similarity = engine.calculateSimilarity(
  "Machine learning requires large datasets",
  ["Deep learning needs lots of training data"]
);

if (similarity.verdict === 'duplicate') {
  // This AI repeated what the other said — retry with stronger prompt
  const retryPrompt = engine.getRetryPrompt(previousResponses);
  // Re-send to the AI with retryPrompt prepended
}
Similarity thresholds: Scores below 0.3 are considered unique. Scores between 0.3 and 0.7 are similar. Scores above 0.7 are flagged as duplicates. Use these to decide when to retry.

Consensus Detection

Determine how much multiple AI providers agree. High consensus means high confidence. A split means the answer needs human review.

engine.calculateConsensus(responses, providers)

Analyzes multiple AI responses to find agreement and disagreement points. Uses keyword extraction and cross-response comparison to produce a consensus score.

Parameter Type Description
responses string[] All AI responses to analyze
providers string[] Provider names in the same order (e.g., ["gpt-4o", "claude-3-5-sonnet"])
Returns
TypeScript
{
  level: string;                 // "high", "moderate", "low", or "split"
  score: number;                 // 0-1 consensus score
  agreementPoints: string[];     // What the AIs agree on
  disagreementPoints: string[]; // Where they diverge
}
JavaScript — Example
const consensus = engine.calculateConsensus(
  [response1, response2, response3],
  ['gpt-4o', 'claude-3-5-sonnet', 'gemini-2.0-flash']
);

if (consensus.level === 'high') {
  // All AIs agree — high confidence answer
  console.log('Agreement points:', consensus.agreementPoints);
} else if (consensus.level === 'split') {
  // AIs disagree — flag for human review
  console.log('Disagreements:', consensus.disagreementPoints);
}

Cost Intelligence

Estimate costs before sending requests, route queries to the optimal provider, and find the cheapest model that meets your quality bar.

engine.estimateCost(provider, inputText, expectedOutputTokens)

Predicts the cost of an AI API call before you send it. Uses built-in token counting and up-to-date provider pricing.

Parameter Type Description
provider string Provider name (e.g., "gpt-4o", "claude-3-5-sonnet")
inputText string The prompt text you plan to send
expectedOutputTokens number Expected response length in tokens
Returns
TypeScript
{
  provider: string;
  estimatedInputTokens: number;
  estimatedOutputTokens: number;
  estimatedCost: number;       // USD
  qualityScore: number;       // 0-1
  costEfficiency: number;     // quality / cost ratio
}

engine.routeByComplexity(query)

Analyzes the query's complexity and automatically selects the best provider. Simple questions route to cheap, fast models. Complex reasoning routes to premium models.

Parameter Type Description
query string The user's query text
Returns

string — Provider name (e.g., "gpt-4o-mini", "gpt-4o", "claude-3-5-sonnet").

JavaScript — Example
// Simple query — routes to budget model
engine.routeByComplexity("What time is it in Tokyo?");
// → "gpt-4o-mini"

// Complex query — routes to premium model
engine.routeByComplexity("Analyze the trade-offs between microservices and monolith architectures for a healthcare platform handling HIPAA-compliant data.");
// → "claude-3-5-sonnet"

engine.findCheapestProvider(minQuality)

Find the least expensive provider that meets your minimum quality threshold.

Parameter Type Description
minQuality number Minimum acceptable quality score, 0 to 1
Returns

string — The cheapest provider name that meets the quality threshold.

JavaScript — Example
// "Good enough" quality at minimum cost
engine.findCheapestProvider(0.85);
// → "gpt-4o-mini"

// Premium quality required
engine.findCheapestProvider(0.95);
// → "gpt-4o"

Usage Tracking

Monitor sessions, messages, token consumption, and cost accumulation for billing and analytics.

engine.meterSession(sessionId)

Register a new session for usage tracking. Call this when a user starts a multi-AI interaction.

Parameter Type Description
sessionId string Unique identifier for this session

engine.meterMessage(provider, tokenCount, cost)

Record an individual AI message for usage tracking.

Parameter Type Description
provider string Provider name (e.g., "gpt-4o")
tokenCount number Total tokens used in this message
cost number Cost in USD for this message

engine.getUsageStats()

Retrieve aggregated usage statistics for the current engine instance.

Returns
TypeScript
{
  sessionCount: number;
  messageCount: number;
  totalTokens: number;
  totalCost: number;     // USD
  lastUsed: string;     // ISO 8601 timestamp
}

engine.getStatus()

Returns the current engine status including version, build date, license validity, and execution mode.

Returns
TypeScript
{
  version: string;       // e.g., "1.0.0"
  buildDate: string;     // ISO 8601
  licenseValid: boolean;
  mode: string;          // "wasm" or "typescript"
}
JavaScript — Full Usage Example
// Track a session
engine.meterSession('session-abc-123');

// After each AI call, record it
engine.meterMessage('gpt-4o', 1250, 0.0187);
engine.meterMessage('claude-3-5-sonnet', 980, 0.0147);

// Check totals
const stats = engine.getUsageStats();
console.log(`Total cost: $${stats.totalCost.toFixed(4)}`);
// → "Total cost: $0.0334"

Protection

Built-in tamper detection to ensure engine integrity at runtime.

engine.checkTamper()

Runs a series of integrity checks on the engine's internal state. Use this in production to detect if the WASM binary or license logic has been modified.

Returns
TypeScript
{
  tampered: boolean;    // true if any check failed
  checks: string[];     // All checks that were run
  failures: string[];   // Checks that failed (empty if clean)
}
JavaScript — Example
const integrity = engine.checkTamper();

if (integrity.tampered) {
  console.error('Engine integrity compromised:', integrity.failures);
  // Shut down or alert — do not continue processing
  process.exit(1);
}
Run checkTamper() on application startup and periodically during long-running processes. A tampered engine may return incorrect routing or cost data.

Engine Management

Manage engine lifecycle in long-running applications.

engine.resetEngine()

Resets all internal state including usage counters, session data, and cached computations. Use this in long-running server processes to prevent memory growth.

This method is only available when running in WASM mode. In TypeScript fallback mode, create a new AxiumEngine instance instead.
JavaScript — Example
// In a long-running server, reset periodically
const status = engine.getStatus();

if (status.mode === 'wasm') {
  engine.resetEngine();
  console.log('Engine state cleared');
}

Error Handling

All errors are thrown as standard JavaScript Error objects with descriptive messages.

JavaScript
try {
  await engine.initialize({
    licenseKey: 'invalid-key',
    bundleId: 'com.app.id'
  });
} catch (err) {
  console.error(err.message);
  // "Invalid license key"
}

Common Errors

Best practice: Wrap initialize() in a try/catch at app startup. If initialization fails, fall back to a single-provider mode rather than crashing.

Modes Reference

Each mode shapes how AI providers interact within a multi-AI session. Choose the mode that matches your use case.

"roundtable"

AIs build on each other collaboratively, adding new information and expanding the discussion.

Best for: Research, analysis, comprehensive coverage

"debate"

AIs take opposing positions and challenge each other's reasoning. Forces consideration of counterarguments.

Best for: Decision making, risk assessment, due diligence

"brainstorm"

Each AI proposes unique, creative ideas without judgment. Maximizes the diversity of suggestions.

Best for: Creative tasks, ideation, naming, marketing

"redTeam"

Each AI finds different vulnerabilities, weaknesses, or edge cases. Adversarial by design.

Best for: Security review, QA, stress testing, contract review

"build"

Each AI contributes different components or modules. Divides work across providers for parallel output.

Best for: Code generation, architecture, document drafting

Supported Providers

Built-in pricing, quality scores, and routing intelligence for all major AI providers.

Provider Quality Cost Best For
gpt-4o 0.95 $$ General purpose, balanced quality and speed
gpt-4o-mini 0.85 $ Simple queries, high volume, budget-friendly
claude-3-5-sonnet 0.98 $$ Complex reasoning, code, long-form writing
claude-3-5-haiku 0.88 $ Fast responses, chat, lightweight tasks
gemini-2.0-flash 0.90 Free Budget-conscious, high volume, prototyping
gemini-1.5-pro 0.92 $ Long context windows, document analysis
Quality scores are based on internal benchmarks across reasoning, code generation, and instruction following. Provider pricing is updated with each engine release. Use estimateCost() for exact per-request pricing.