# Introduction

layahost is a hosted API for typed decisions. You send a piece of text and a question with a fixed set of answers. You get back one of those answers, with probabilities, as JSON your code can branch on.

It runs **Laya**, the open-source decision model by Convai Innovations (Apache-2.0), and implements the wire format of TypeSafe AI's Jev System One API. Code written for Jev, including the official Jev SDKs, works after you change the base URL and the API key.

layahost is an unofficial hosted service. It is not affiliated with, endorsed by or sponsored by Convai Innovations or TypeSafe AI.

## How it works

Every question has a type, and every answer is typed to match:

| Type | You define | You get back |
| --- | --- | --- |
| `choice` | 2 or more named options, optionally with a description each | The chosen option and a probability for every option |
| yes/no (`noul` in Jev) | A yes/no question | The probability that the answer is yes |
| `score` | 2 to 10 ordered levels, lowest first | The expected level and a probability for every level |

Laya is a classifier, not a text generator: it never writes free text, so every answer is one of the options you defined. There is nothing to parse and no malformed output to retry. Server-side processing typically takes tens of milliseconds, and every response reports its own `latency_ms`.

Typical uses are content moderation, spam filtering, support-ticket intent and routing, sentiment and urgency scoring. Accuracy depends on your data and on how you word the question, so test on a sample of real traffic before you rely on it.

## Two endpoints

| Endpoint | Use it when |
| --- | --- |
| [`POST /v1/decide`](https://layahost.com/docs/decide) | You want one decision about one text. Use a ready-made [template](https://layahost.com/docs/templates) (moderation, spam, routing and more) or your own question. The response is flat and easy to read. |
| [`POST /v1/systemone`](https://layahost.com/docs/systemone) | You want the Jev-compatible API: up to 32 questions about the same text in one request, and the official Jev SDKs for Python and JavaScript. |

## Quickstart

1. [Create an account](https://layahost.com/register) and add credit on the [Billing](https://layahost.com/billing) page. Verifying your email adds $1 of welcome credit (200K decisions), enough to try everything. The smallest top-up is $10, which buys 2,000,000 decisions.
2. Create a key on the [API keys](https://layahost.com/keys) page and store it as `LAYAHOST_API_KEY`. The key is shown only once.
3. Send your first request:

POST /v1/decide

```bash
curl https://layahost.com/v1/decide \
  -H "Authorization: Bearer $LAYAHOST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "I was charged twice this month, please refund one payment.",
    "template": "support_intent"
  }'
```

POST /v1/decide

```javascript
const res = await fetch("https://layahost.com/v1/decide", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.LAYAHOST_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    text: "I was charged twice this month, please refund one payment.",
    template: "support_intent",
  }),
});

const result = await res.json();
console.log(result.decision, result.confidence);
```

POST /v1/decide

```python
import os
import requests

res = requests.post(
    "https://layahost.com/v1/decide",
    headers={"Authorization": f"Bearer {os.environ['LAYAHOST_API_KEY']}"},
    json={
        "text": "I was charged twice this month, please refund one payment.",
        "template": "support_intent",
    },
    timeout=10,
)
res.raise_for_status()
result = res.json()
print(result["decision"], result["confidence"])
```

POST /v1/decide

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://layahost.com']);

$res = $client->post('/v1/decide', [
    'headers' => ['Authorization' => 'Bearer ' . getenv('LAYAHOST_API_KEY')],
    'json' => [
        'text' => 'I was charged twice this month, please refund one payment.',
        'template' => 'support_intent',
    ],
]);

$result = json_decode($res->getBody(), true);
echo $result['decision'], ' ', $result['confidence'], PHP_EOL;
```

The response names the decision, how sure the model is, and what the request cost:

Response · 200

```json
{
  "decision": "refund",
  "confidence": 0.9902,
  "probabilities": {
    "refund": 0.9979,
    "cancellation": 0.0006,
    "other": 0.0005,
    "bug_report": 0.0004,
    "feature_request": 0.0003,
    "question": 0.0002,
    "praise": 0.0002
  },
  "template": "support_intent",
  "model": "laya-english",
  "usage": {
    "decisions": 1,
    "input_tokens": 91,
    "cost_micros": 5,
    "cost_usd": 5.0e-6
  },
  "latency_ms": 207.74,
  "request_id": "req_iauupwcy6zdiagjozndye5ls"
}
```

You can also try templates and your own questions in the [Playground](https://layahost.com/playground) without writing code. Playground runs are billed like API calls.

## Base URL

All endpoints live under `https://layahost.com/v1`, with no `/api` prefix, exactly like the Jev API. Requests and responses are JSON, so send `Content-Type: application/json` with every `POST`.

| Method | Path | Description |
| --- | --- | --- |
| `POST` | [`/v1/decide`](https://layahost.com/docs/decide) | One decision about one text, from a template or your own question |
| `GET` | [`/v1/templates`](https://layahost.com/docs/templates) | List the ready-made templates |
| `POST` | [`/v1/systemone`](https://layahost.com/docs/systemone) | Jev-compatible: many typed questions about one state |
| `GET` | [`/v1/models`](https://layahost.com/docs/models) | List the available models |

## Next steps

- [Authentication](https://layahost.com/docs/authentication): create and use API keys.
- [Migrate from Jev](https://layahost.com/docs/migrate-from-jev): switch existing Jev code in two lines.
- [POST /v1/decide](https://layahost.com/docs/decide): the full request and response reference.
- [Pricing & billing](https://layahost.com/docs/pricing): $5 per million decisions, prepaid.
