Skip to content

SDKs and integration

Choose in-process inference when the application should own the model. Choose HTTP when several applications should share one Python engine and its decision cache. MCP provides tools to an editor or agent over stdio and can use either a local Router or your own server.

Capabilities

Interface Inference Batch Long documents Pro persistent cache
Python PyTorch or ONNX, in process yes yes memory, SQLite or your store
TypeScript HTTP client your Python server yes use Python directly server policy
TypeScript ONNX SDK Node.js or browser yes no no
Java SDK ONNX, in process yes yes no
.NET SDK ONNX, in process sequential calls no no
MCP local Python or your HTTP server yes no engine policy

Native SDK feature parity varies. Each SDK's README describes its model-export requirements, supported methods and calibration limits. A successful build with tiny random models verifies transport and execution, not pretrained accuracy. The review report records which SDK tests ran in this environment.

Python

from laya import DecisionCache, Router, triage_questions

with DecisionCache("decisions.sqlite", ttl=86400) as cache:
    with Router(hooks=[cache]) as router:
        answers = router.predict_batch(
            ["Payment failed", "Cannot sign in"], triage_questions(), batch_size=8
        )

Reuse the Router and cache between requests. Creating a new Router for each call reloads models and loses in-process reuse. max_loaded bounds resident checkpoints. For local weights, pass models={"english": "/path/to/checkpoint"} and select model="english". If the workload uses other languages, configure their checkpoint paths too.

Schema helpers and framework adapters are covered in structured decisions, LangChain / LangGraph, LlamaIndex and CrewAI.

TypeScript over HTTP

Build the client from this repository; an upstream npm package does not include fork changes.

cd sdk/typescript
npm ci
npm test
npm pack
# In your application:
npm install /path/to/laya-pro/sdk/typescript/laya-pro-client-0.1.0.tgz
import { Laya, triageQuestions } from 'laya-pro-client';

const client = new Laya({ baseURL: 'http://127.0.0.1:8000', timeoutMs: 120_000 });
const result = await client.predict('Payment failed', triageQuestions());
const batch = await client.predictBatch(
  ['Payment failed', 'Cannot sign in'], triageQuestions(), { batchSize: 8 }
);

The client validates requests and responses, preserves routing and confidence fields, supports cancellation and deadlines, and reports server errors. It does not retry inference automatically. HTTP SDK source and full API.

Native SDKs

The TypeScript SDK now includes predictTournament and cachedEmbedFn. Tournaments compare finalists after elimination; their probabilities describe that final set. The bounded embedding cache reuses label vectors between requests and stays in memory. Clear it when the model changes; it is separate from Python's decision retention policy.

  • TypeScript ONNX SDK: export ONNX artifacts, build with npm ci and npm run build, then install the packed local package.
  • Java SDK: build and test with the checked-in Gradle wrapper and a compatible JDK. The source API namespace is retained for compatibility.
  • .NET SDK: build the solution, then reference the local project or packed artifact. Follow its exporter and tokenizer guide.

Use artifacts built from this checkout for Laya-Pro. Maven Central, NuGet and npm names in upstream examples identify upstream releases until this fork publishes its own artifacts.

Local MCP

Install laya-pro[mcp] from the repository. Configure your editor with the absolute executable path from the environment where it is installed:

{
  "mcpServers": {
    "laya-pro": {
      "command": "/absolute/path/to/venv/bin/laya-mcp-server",
      "env": {
        "LAYA_DEVICE": "cpu",
        "LAYA_PRELOAD": "0",
        "LAYA_CACHE_PATH": "/absolute/path/to/decisions.sqlite",
        "LAYA_CACHE_TTL": "604800",
        "LAYA_CACHE_MAXSIZE": "10000"
      }
    }
  }
}

On Windows, use the environment's Scripts/laya-mcp-server.exe. Keep protocol output on stdout and logs on stderr. laya_status reports runtime readiness and cache statistics when enabled. laya_predict and laya_predict_batch evaluate questions; schema, shortlist and email tools are also available. For a separate server, set LAYA_BASE_URL and configure caching on that server. Tool contracts and remote mode.