# Decision templates

Templates are ready-made questions for common tasks. Send a `template` and your `text` to [POST /v1/decide](https://layahost.com/docs/decide) and you get a decision without writing a question or options.

## Available templates

| Template | Type | Options | What it decides |
| --- | --- | --- | --- |
| `moderation` | choice | `safe`, `toxic` | Flags insults, harassment, hate speech and threats. |
| `spam` | choice | `spam`, `legit` | Separates spam, scams and phishing from genuine messages. |
| `support_intent` | choice | `question`, `bug_report`, `refund`, `cancellation`, `feature_request`, `praise`, `other` | What the customer wants from a support ticket. |
| `routing` | choice | `billing`, `technical`, `sales`, `other` | Which team should handle a message. Pass your own teams in `options`. |
| `sentiment` | choice | `positive`, `neutral`, `negative` | The tone of a message. |
| `priority` | score | `low`, `normal`, `high`, `urgent` | How urgent a message is. |
| `language` | choice | ISO 639-1 codes | Which language the text is written in. See [Language detection](#language). |

Each template is a single decision and is billed like any other: $0.000005 per request.

## How the options are defined

The model sees a short description of each option, not just its name. These descriptions decide where the borderline cases go:

| Template | Option | Description given to the model |
| --- | --- | --- |
| `moderation` | `safe` | polite, neutral or harshly critical content about a product, service or idea, without attacking a person |
|  | `toxic` | insults or slurs aimed at a person, harassment, hate speech, threats of violence or revenge, telling someone to hurt themselves |
| `spam` | `spam` | unsolicited advertising, scam, phishing, fake prizes, suspicious links |
|  | `legit` | genuine message: question, complaint, refund request, bug report or thanks |
| `support_intent` | `question` | asks for information or instructions |
|  | `bug_report` | reports an error or something not working |
|  | `refund` | wants money back or reports a wrong charge |
|  | `cancellation` | wants to cancel or close the account |
|  | `feature_request` | asks for a new feature or improvement |
|  | `praise` | says thanks or compliments |
|  | `other` | anything else |
| `routing` | `billing` | existing charges, invoices, payments, refunds, billing details |
|  | `technical` | bugs, errors, outages, crashes, API and integrations |
|  | `sales` | prices of plans, quotes, buying, upgrading, new contracts |
|  | `other` | jobs, office locations, partnerships and anything else |

`sentiment` and `priority` use the option names alone. If a template's definitions don't match your policy, override them as shown below.

## Example

POST /v1/decide

```bash
curl https://layahost.com/v1/decide \
  -H "Authorization: Bearer $LAYAHOST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Congratulations! You won a $500 gift card. Claim it now at bit.ly/prize-claim",
    "template": "spam"
  }'
```

Response · 200

```json
{
  "decision": "spam",
  "confidence": 0.4058,
  "probabilities": {
    "spam": 0.8562,
    "legit": 0.1438
  },
  "template": "spam",
  "model": "laya-english",
  "usage": {
    "decisions": 1,
    "input_tokens": 83,
    "cost_micros": 5,
    "cost_usd": 5.0e-6
  },
  "latency_ms": 130.72,
  "request_id": "req_y4k2bsiy6d7gatbik1y82rnk"
}
```

## Override a template

Any template accepts the same `question` and `options` fields as a custom question. They replace the template's own, so you can keep the template's slug in your logs while using your own wording or categories:

- `options` as a list of names or as an object of names and descriptions. For `routing`, pass your own teams.
- `question` to reword the question.

There is a full example in [POST /v1/decide](https://layahost.com/docs/decide). Wording changes can move results a lot, so test your version on real messages.

## Language detection

The `language` template does not use Laya. It runs a dedicated language detector and returns ISO 639-1 codes. Without `options`, it considers every supported language and returns the five most likely:

POST /v1/decide

```bash
curl https://layahost.com/v1/decide \
  -H "Authorization: Bearer $LAYAHOST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Dzień dobry, mam pytanie o fakturę.",
    "template": "language"
  }'
```

Response · 200

```json
{
  "decision": "pl",
  "confidence": 0.919,
  "probabilities": {
    "pl": 0.919,
    "sk": 0.0184,
    "sv": 0.0138,
    "da": 0.0084,
    "nb": 0.005
  },
  "template": "language",
  "model": "lingua",
  "usage": {
    "decisions": 1,
    "input_tokens": 0,
    "cost_micros": 5,
    "cost_usd": 5.0e-6
  },
  "latency_ms": 44.7,
  "request_id": "req_aelx2cghpfzvdnoz7nriwqzn"
}
```

Pass `options` with the codes you expect to choose among them only. The probabilities are then normalised over your list:

POST /v1/decide

```bash
curl https://layahost.com/v1/decide \
  -H "Authorization: Bearer $LAYAHOST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Dzień dobry, mam pytanie o fakturę.",
    "template": "language",
    "options": ["en", "pl", "de"]
  }'
```

Response · 200

```json
{
  "decision": "pl",
  "confidence": 0.9964,
  "probabilities": {
    "pl": 0.9964,
    "de": 0.0029,
    "en": 0.0007
  },
  "template": "language",
  "model": "lingua",
  "usage": {
    "decisions": 1,
    "input_tokens": 0,
    "cost_micros": 5,
    "cost_usd": 5.0e-6
  },
  "latency_ms": 0.84,
  "request_id": "req_igquswea95s7kdti2jwezefc"
}
```

Supported codes: `en`, `pl`, `de`, `fr`, `es`, `it`, `pt`, `nl`, `uk`, `cs`, `sk`, `ru`, `sv`, `da`, `nb`, `fi`, `hu`, `ro`, `tr`, `ja`, `zh`, `ko`, `ar`, `hi`, `el`, `bg`, `hr`, `lt`, `lv`, `et`, `sl`, `sr`, `he`, `vi` and `id`. `GET /v1/templates` lists the same codes.

- `confidence` is the probability of the detected language.
- `model` is `lingua` and `usage.input_tokens` is `0`. The `model` and `lang` request fields are ignored.
- An unsupported code in `options` returns `422` on `["body", "options"]`, with the message “Unsupported language codes: xx. See GET /v1/templates.”
- Very short texts (a word or two) are hard to identify in any language. Check `confidence`.

## List templates

`GET /v1/templates` returns every template with its type, option names and an example text. Use it to build a picker or to check what a slug does.

GET /v1/templates

```bash
curl https://layahost.com/v1/templates \
  -H "Authorization: Bearer $LAYAHOST_API_KEY"
```

Response · 200

```json
{
  "templates": [
    {
      "template": "moderation",
      "name": "Moderation",
      "description": "Flags insults, harassment, hate speech and threats.",
      "type": "choice",
      "options": ["safe", "toxic"],
      "example": "You are all idiots and I hope you get fired."
    },
    {
      "template": "spam",
      "name": "Spam",
      "description": "Separates spam and scams from genuine messages.",
      "type": "choice",
      "options": ["spam", "legit"],
      "example": "Earn $5000 a day from home! Message me on WhatsApp."
    },
    {
      "template": "support_intent",
      "name": "Support intent",
      "description": "What the customer wants from a support ticket.",
      "type": "choice",
      "options": ["question", "bug_report", "refund", "cancellation", "feature_request", "praise", "other"],
      "example": "I was charged twice this month, please refund one payment."
    },
    {
      "template": "routing",
      "name": "Routing",
      "description": "Sends a message to the right team. Pass your own departments in \"options\".",
      "type": "choice",
      "options": ["billing", "technical", "sales", "other"],
      "example": "The API returns 502 errors since this morning."
    },
    {
      "template": "sentiment",
      "name": "Sentiment",
      "description": "Positive, neutral or negative tone.",
      "type": "choice",
      "options": ["positive", "neutral", "negative"],
      "example": "Thanks for the quick help, everything works great!"
    },
    {
      "template": "priority",
      "name": "Priority",
      "description": "How urgent a message is, on a 4-level scale.",
      "type": "score",
      "options": ["low", "normal", "high", "urgent"],
      "example": "Our whole checkout is down and we are losing orders right now!"
    },
    {
      "template": "language",
      "name": "Language",
      "description": "Which language the text is written in (ISO 639-1, 35 languages). Pass \"options\" to narrow the list.",
      "type": "choice",
      "options": ["en", "pl", "de", "fr", "es", "it", "pt", "nl", "uk", "cs", "sk", "ru", "sv", "da", "nb", "fi", "hu", "ro", "tr", "ja", "zh", "ko", "ar", "hi", "el", "bg", "hr", "lt", "lv", "et", "sl", "sr", "he", "vi", "id"],
      "example": "Dzień dobry, mam pytanie o fakturę."
    }
  ]
}
```

Listing templates is free and counts towards your [rate limit](https://layahost.com/docs/rate-limits) like any other request.
