layahost

n8n community node for layahost: typed decisions about text (classify, yes/no, score) and decision flows

Package Information

Released: this month
Downloads: 0 weekly / 0 monthly
Latest Version: 0.1.2
Author: layahost

Documentation

n8n-nodes-layahost

This is an n8n community node. It lets you use layahost in your n8n workflows.

layahost is a hosted typed-decision API: send a text and a question, and get back a structured answer (one option out of a list, yes/no with a probability, or a level on a scale) with a confidence, in a fraction of a second. You can also chain questions into decision flows in the layahost console and run them with one call.

n8n is a fair-code licensed workflow automation platform.

Installation

Follow the installation guide in the n8n community nodes documentation.

In short, on a self-hosted n8n: Settings → Community Nodes → Install, enter n8n-nodes-layahost, and confirm. Or from the command line in your n8n user folder:

cd ~/.n8n/nodes
npm install n8n-nodes-layahost
# restart n8n

Credentials

  1. Sign up at layahost.com and create an API key on the API keys page. Keys start with lh_.
  2. In n8n, create a Layahost API credential:
    • API Key: your lh_... key. It is sent as Authorization: Bearer <key>.
    • Base URL: leave https://layahost.com unless you run your own instance.
  3. Click Test. n8n calls GET /v1/usage, which is free.

Operations

Decision → Decide

One text in, one decision out (POST /v1/decide).

  • Text: the text to decide about, usually an expression such as {{ $json.body }}.
  • Question Source:
    • Template: pick a ready-made question from the list (loaded from GET /v1/templates): moderation, spam, support intent, routing, sentiment, priority, language.
    • Custom Question: choose a Type and write the Question:
      • Choice: add 2 or more Answers, each with a name and an optional description.
      • Yes / No: no options needed.
      • Score: add 2 to 10 Levels, lowest first.
  • Options (optional): model (laya-auto, laya-english, laya-multilingual), language hint, cache on/off, and a question override for templates.

Output: the API response, with decision at the top level:

{
  "decision": "billing",
  "confidence": 0.6506,
  "probabilities": { "billing": 0.9036, "technical": 0.0506, "sales": 0.0458 },
  "template": null,
  "model": "laya-english",
  "usage": { "decisions": 1, "input_tokens": 52, "cost_micros": 15, "cost_usd": 0.000015 },
  "latency_ms": 169.63,
  "request_id": "req_iazyijj7zo5nmmoxzhnivu9d"
}
  • decision is the chosen option (choice), true/false (yes/no), or the level name (score).
  • yes/no answers have probability (of yes) instead of probabilities; score answers also have score.

Decision → Decide Batch

The same decision for the text of every input item, in as few requests as possible (POST /v1/decide/batch, 64 texts per request). The question settings are read from the first item; the Text is read from each item. You get one output item per input item, in the same order, each with the same fields as Decide. A text that fails on its own (for example an empty one) fails only its item when Continue On Fail is on.

Batching saves round trips, not money: each text is billed as one decision.

Flow → Run

Runs a decision flow drawn in the layahost console (POST /v1/flows/{flow}/run).

  • Flow: pick one from the list (loaded from GET /v1/flows). Each entry shows the flow's possible outcomes.
  • Text: the text to run through the flow.
  • Options → Language Hint (optional).

Output: the run, with outcome at the top level so a Switch node can branch on {{ $json.outcome }}:

{
  "flow": "support-inbox",
  "version": 1,
  "outcome": "billing-queue",
  "ended_at": "billing",
  "steps": [
    { "step": "spam", "label": "Spam?", "answer": "legit", "probability": 0.8049, "followed": "legit" },
    { "step": "intent", "label": "What do they want?", "answer": "refund", "probability": 0.9977, "followed": "refund" }
  ],
  "usage": { "decisions": 2, "cost_micros": 10, "cost_usd": 0.00001 },
  "request_id": "req_pebc6fszrqvqwhetxbxruttk"
}

Account → Get Usage

Balance, plan and usage totals of the account (GET /v1/usage), over the last Days (1 to 90). Free to call.

Errors

API errors are shown with layahost's own message, for example Invalid or revoked API key. [authentication_error] or options: A score needs 2 to 10 levels. [validation_error]. 402 means the balance does not cover the request.

With Settings → On Error → Continue (Continue On Fail), a failed item is passed on as { "error": "...", "statusCode": 402 } instead of stopping the workflow. For 429, 503 and 529, turn on Retry On Fail: those requests are not billed.

Examples

Route support emails with a flow

Gmail Trigger → Layahost (Flow → Run, flow: support-inbox, text: {{ $json.text }}) → Switch on {{ $json.outcome }}

Add one Switch rule per outcome (billing-queue, engineering-queue, page-on-call, discard, …). The flow list in the node shows every outcome the flow can return.

Moderate comments, with a human in the loop

Webhook → Layahost (Decision → Decide, template: Moderation, text: {{ $json.body.comment }}) → IF

  • {{ $json.decision === 'toxic' && $json.confidence > 0.3 }} → hide
  • otherwise → publish, or send low-confidence ones to a person.

Tag a spreadsheet of reviews in one go

Google Sheets (read rows) → Layahost (Decision → Decide Batch, custom Score question "How happy is the customer?", levels: angry, unhappy, neutral, happy, delighted, text: {{ $json.review }}) → Google Sheets (update rows with {{ $json.decision }})

Custom choice with descriptions

Custom Question, Type Choice, question Which team should answer this email?, options:

Name Description
billing invoices, payments, refunds
technical bugs, errors, API
sales pricing, plans, quotes

Using it as an AI agent tool

The node is marked usableAsTool, so you can attach it to an AI Agent node as a tool. Let the model fill the Text (and, for custom questions, the Question) with $fromAI(), and keep the template, flow and options fixed so the agent gets a fast, cheap and consistent classifier.

Compatibility

Built with @n8n/node-cli 0.49 against n8n-workflow 2.x. Tested with n8n 2.40. No runtime dependencies.

Resources

License

MIT

Discussion