---
name: layahost
description: Classify, moderate, route or score short text with the layahost typed-decisions API (Jev-compatible, open Laya model). Use when writing code that needs a decision about text - spam or toxicity filtering, support-ticket intent or routing, sentiment, priority, language detection, or any custom choice / yes-no / score question - and the project uses or could use layahost (LAYAHOST_API_KEY, layahost.com, or the TypeSafe Jev SDKs pointed at layahost).
---

# layahost

layahost answers typed questions about text. You send the text and a question with fixed options; you get one of your options back, with probabilities and a confidence. No prompt parsing, no free-form output.

- Base URL: `https://layahost.com`
- Auth: `Authorization: Bearer $LAYAHOST_API_KEY` (keys start with `lh_`, created at https://layahost.com/keys)
- Price: $5 per million decisions ($0.000005 each), prepaid. Failed and rejected requests are free.
- Full docs for agents: https://layahost.com/llms-full.txt (index: https://layahost.com/llms.txt)

## Pick the endpoint

| Need | Endpoint |
| --- | --- |
| One decision about one text, simplest response | `POST /v1/decide` |
| The same decision for up to 64 texts | `POST /v1/decide/batch` |
| Several questions about one text, or existing Jev code | `POST /v1/systemone` (Jev-compatible) |
| Up to 64 Jev requests in one call | `POST /v1/systemone/batch` |
| Ready-made templates | `GET /v1/templates` |
| Balance and usage | `GET /v1/usage` (free) |

Templates for `/v1/decide`: `moderation`, `spam`, `support_intent`, `routing`, `sentiment`, `priority` (score), `language`. Pass `options` to replace a template's options (e.g. your own departments for `routing`).

## /v1/decide

```python
import os, requests

res = requests.post(
    "https://layahost.com/v1/decide",
    headers={"Authorization": f"Bearer {os.environ['LAYAHOST_API_KEY']}"},
    json={"text": message, "template": "spam"},
    timeout=10,
)
res.raise_for_status()
result = res.json()  # {"decision": "spam", "confidence": 0.33, "probabilities": {"spam": 0.83, "legit": 0.17}, ...}
```

Your own question instead of a template:

```json
{
  "text": "Can I get an invoice with my VAT number on it?",
  "type": "choice",
  "question": "Which team should answer this email?",
  "options": {"billing": "invoices, payments, refunds", "technical": "bugs, errors, API", "sales": "pricing, plans, quotes"}
}
```

- `type`: `choice` (2+ options), `yes_no` (no options; `decision` is a boolean and `probability` is P(yes)), `score` (2-10 levels, lowest first; `decision` is the nearest level name).
- Short descriptions per option improve accuracy a lot. Wording matters: prefer a `choice` with described options over a bare `yes_no`.
- Limits: text 32,000 characters, question 2,000, option description 500.

## Jev compatibility

Existing Jev code works by changing the base URL and key. With the official SDKs (`typesafe-sdk` for Python, `@typesafe-ai/sdk` for JS) set `TYPESAFE_BASE_URL=https://layahost.com` and `TYPESAFE_API_KEY=$LAYAHOST_API_KEY`. Jev model names such as `jev-latest` map to `laya-auto`. Up to 32 questions per request; each answered question is one decision.

## Using the answer

- `confidence` is 0-1 but not a probability: for `choice`/`score` it is 1 minus the normalised entropy (0.3 can still mean a clear favourite), for `yes_no` it is max(p, 1-p).
- Branch on `probabilities` (or `probability`) with a threshold chosen on real data, and send low-confidence cases to a person. Do not hard-code thresholds from another model; Laya's probabilities differ from Jev's.
- The model is English-first. Other languages work through `laya-multilingual` but are less accurate.

## Errors and retries

Errors use the Jev shape: `{"detail": {"error_type": "...", "message": "..."}}`, or a list of `{"loc", "msg", "type"}` for `422`.

- `401` bad key, `402` balance too low (top up at https://layahost.com/billing), `422` invalid body - do not retry these.
- `429` rate limit (600 requests/min per key), `503`/`529` busy or unavailable - retry with backoff, honour `retry-after`.
- Every response has `x-request-id`; include it in bug reports. `x-layahost-cost-micros` and `x-layahost-balance-micros` show what the call cost and what is left.

## Batches

```json
POST /v1/decide/batch
{"template": "support_intent", "texts": ["Refund please, I was charged twice", "The app crashes on login"]}
```

Returns `results` in order, each with `index` and `status`. Items are billed one by one; if the balance runs out mid-batch the rest get `402`. Use an HTTP timeout of at least 30 seconds.

## MCP

For ad-hoc decisions from an agent (not application code), the same account works as a remote MCP server at `https://layahost.com/mcp` with the same bearer key. Tools: `decide`, `decide_batch`, `list_templates`, `get_usage`.
