100% free AI setup guides — no credit card needed
← GitHub Projects
INTERMEDIATEFeatured1,213 views

Laya

Open-source System 1 decision engine - typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request. A self-hosted, Jev-compatible alternative.

PythonTypeScriptPyTorchHugging FaceMCP

What is this?

Laya answers questions about text. Not chat, not generation — structured decisions. You give it a piece of text (an email, a ticket, a JSON blob) and a set of typed questions, and it gives you back a choice, a score, or a yes/no probability. One forward pass, ~33ms on a T4, in 100+ languages. 27.5k stars, Apache-2.0.

It's also the open-source answer to Jev (TypeSafe's hosted decision API). Same wire protocol, same response shape, but you host it and it costs nothing per token.

What problem does it solve?

Sometimes you don't need a paragraph of text. You need a decision. Which department handles this ticket? How urgent is it? Is this customer about to churn?

You can ask an LLM that, but you're paying 200ms and a handful of tokens to generate text you then have to parse, validate, and hope the model didn't hallucinate an option that doesn't exist. And if you're doing it at scale — thousands of decisions per second — the cost and latency add up fast.

Laya skips generation entirely. It runs a ModernBERT encoder over your text once and reads the answer off the model's output heads. Nothing to parse, nothing to hallucinate, and every answer comes with a calibrated confidence score you can gate on.

How does it work?

your text + questions
      │
      ▼
┌──────────────────────┐
│  Router              │
│  detects the script  │
│  and language        │
└──────────┬───────────┘
           │
     ┌─────┼──────────────┐
     ▼     ▼              ▼
  laya   laya-       laya-typed-
(English) multilingual  decisions
     └─────┬──────────────┘
           ▼
   one forward pass
           ▼
   typed answers + confidence

The router looks at your input, figures out what language it's in, and picks the right checkpoint. English goes to the English model. Everything else goes to the multilingual one. If you've fine-tuned your own checkpoint, that gets used too.

The three question types map to real use cases:

  • choice — pick one option from a list (route this ticket, classify this email)
  • score — rate something on a scale (how urgent, how satisfied)
  • noul — yes/no with a probability (will they churn, is this a refund)

Repository Structure

NandhaKishorM/laya/
├── laya/
│   ├── integrations/   # LangChain, LlamaIndex, CrewAI
│   └── mcp/            # MCP server
├── laya-ts/            # TypeScript / Node / browser version
├── research/           # training scripts, RLCD recipes
├── benchmarks/         # benchmark suites and results
├── docker/             # container images
├── nix/                # Nix packaging
├── scripts/            # CLI and utilities
├── tests/              # test suite
└── notebooks/          # examples

Key Features

  • Typed decisions — choice, score, and noul in a single call. No parsing, no prompt engineering.
  • 100+ languages — the router picks the right checkpoint automatically based on script detection.
  • Fast — 33ms per question on a T4, 7.2ms batched. Independently measured at 6-7x faster than Jev.
  • Calibrated — trained with reinforcement learning against strictly proper scoring rules (RLCD). The confidence number is a real probability, not a vibe.
  • Jev-compatible — laya.serve exposes POST /v1/systemone with the same payload shape Jev returns. Repoint your existing Jev client's baseUrl and nothing else changes.
  • Self-hosted — $0 per token. Your data never leaves your machine.
  • Fine-tunable — train it on your own labeled decisions. A fine-tuned checkpoint beats Jev by 3.9 points on the typed-decisions benchmark.
  • Integrations everywhere — MCP server, LangChain, LlamaIndex, CrewAI, ONNX Runtime, CLI, HTTP server, TypeScript SDK.

What You'll Learn

  • How non-autoregressive decision models differ from autoregressive LLMs — and when to use which
  • How to make structured, calibrated decisions over text without generation or parsing
  • How multilingual routing works in practice
  • How to self-host a drop-in Jev replacement
  • How to fine-tune a decision engine on your own data
  • How to gate agent actions on a calibrated confidence threshold
aiagentsdecision-modelnlpmultilingualopen-sourcepythonmcpself-hosted

See it in action

pip install laya
from laya import Router

router = Router()

state = "Hi, we were billed twice for March. Please refund the duplicate today or we will cancel our plan."
questions = {
    "department": {
        "type": "choice",
        "instructions": "Which department should handle this?",
        "criteria": {
            "billing": "invoices, payments, refunds",
            "technical": "bugs, outages, system errors",
            "other": "everything else",
        },
    },
    "urgency": {
        "type": "score",
        "instructions": "How urgent is this?",
        "criteria": ["not urgent", "soon", "blocking"],
    },
    "churn_risk": {
        "type": "noul",
        "instructions": "Does the user threaten to cancel or leave?",
    },
}

result = router.predict(state, questions)
print(result["answers"]["department"]["choice"])   # billing
print(result["answers"]["churn_risk"]["noul"])     # probability of yes
print(result["routing"]["model"])                  # english

The same call works in any of 100+ languages — pass text in Spanish, Chinese, Arabic, whatever, and the router handles it. Try the HF Space demo, the Colab notebook, or read the docs.

One honest caveat: Laya's edge over Jev is real but narrow. It wins on speed, cost, and most accuracy benchmarks. Jev still handles 50+ option questions better out of the box. If your use case is high-cardinality classification, check both.

View Demo
Hosting partnerHostinger VPS

Need a machine that stays on while yours sleeps?

Self-hosted AI only works if the machine never sleeps. A cheap VPS runs your models, agents and APIs 24/7 — setup takes minutes and costs less than lunch per month.

See Hostinger VPS deals

Disclosure: some links on this page are partner links. If you sign up through them, we may earn a commission at no extra cost to you.

Hosting partnerDigitalOcean

A developer cloud VM in under a minute

The developer-favorite cloud for side projects: spin up a droplet, deploy your self-hosted stack, predictable pricing with no surprise bills.

Try DigitalOcean

Disclosure: some links on this page are partner links. If you sign up through them, we may earn a commission at no extra cost to you.

Want to learn more about this project?

Have questions or want to understand this technology more deeply? Send me a message.

Related Projects

Discussion

Leave a Comment

Loading comments...