Skip to content
Adapters

Ollaya

The Ollaya adapter calls the laya models on your machine through decide(). It returns a typed answer. It has no chat.

1. Install

shell
npm i @tanstack/ai @tanstack/ai-ollaya

2. Start Ollaya and pull a model

Ollaya needs no API key. It needs a running server with a model.

  1. Install Ollaya:
shell
# macOS or Linux
curl -fsSL https://ollaya.dev/install.sh | sh
plaintext
# Windows (PowerShell)
irm https://ollaya.dev/install.ps1 | iex
  1. Start the server:
shell
ollaya serve
  1. Pull a model:
shell
ollaya pull laya:latest

The server listens on http://127.0.0.1:11435. The adapter uses this URL by default. The download page and the desktop app are on ollaya.dev/download.

3. Ask your first questions from the server

This route reads a support ticket and asks three questions about it:

ts
import { decide, choice, score, boolean } from "@tanstack/ai";
import { ollayaDecider } from "@tanstack/ai-ollaya";

export async function POST(request: Request) {
  const ticket = await request.text();

  const result = await decide({
    adapter: ollayaDecider("laya:latest"),
    state: ticket,
    questions: {
      queue: choice({
        instructions: "Which team should handle this ticket?",
        options: {
          billing: "Payments, invoices, refunds",
          tech: "Bugs, outages, integrations",
          sales: "Pricing, upgrades, new accounts",
        },
      }),
      urgency: score({
        instructions: "How urgent is this ticket?",
        levels: ["low", "medium", "high"],
      }),
      refund: boolean({
        instructions: "Is the customer asking for a refund?",
      }),
    },
  });

  return Response.json({
    queue: result.queue.value,
    urgency: result.urgency.value,
    refund: result.refund.value,
    model: result.meta.model,
  });
}

When you ask for laya:latest, the server picks laya:en or laya:multilingual from the text. result.meta.model tells you which one answered.

4. Call the route from the client

The client sends the ticket text to the route:

ts
export async function evaluateTicket(ticket: string) {
  const response = await fetch("/api/evaluate", {
    method: "POST",
    body: ticket,
  });
  return response.json();
}

Call evaluateTicket("Charged twice for the same invoice. Please refund the extra payment.") and you get back the queue, the urgency, and the refund answer.

For the rest of decide(), see Evaluate. For a full TanStack Start app, see Evaluate a ticket.

Models and options

ModelDescription
laya:latestSends each request to laya:en or laya:multilingual.
laya:enThe English decision model (ModernBERT-large).
laya:multilingualThe decision model for 100+ languages (mmBERT-base).

You can pass any other model tag as a string. The package exports the known tags as OLLAYA_EVALUATE_MODELS.

Advanced

Another host, or an API key

The adapter does not read environment variables.

  • If the server is on another host, pass baseURL.
  • If the server requires OLLAYA_API_KEY, pass the key as apiKey.
ts
import { ollayaDecider } from "@tanstack/ai-ollaya";

const adapter = ollayaDecider("laya:latest", {
  baseURL: "http://my-host:11435",
  apiKey: "local-token",
});

baseUrl and headers are aliases of baseURL and defaultHeaders. If you set both forms, baseURL and defaultHeaders win. A blank baseURL keeps the default host.

Handle a failed request

A wrong apiKey needs a fix, not a retry. When the server sends an error response, the thrown error has the HTTP status code in status:

ts
import { decide, boolean } from "@tanstack/ai";
import { ollayaDecider } from "@tanstack/ai-ollaya";

try {
  await decide({
    adapter: ollayaDecider("laya:latest"),
    state: { body: "Please refund the extra payment." },
    questions: {
      refund: boolean({ instructions: "Is the customer asking for a refund?" }),
    },
  });
} catch (error) {
  if (error instanceof Error && "status" in error && error.status === 401) {
    // The server rejected the apiKey. Check it before you call decide() again.
  }
}

API reference

The adapter sends POST /v1/systemone to the base URL with fetch. There is no Ollaya SDK.

ollayaDecider(model, config?) creates an evaluate adapter. The config fields:

  • baseURL: the server URL. The default is http://127.0.0.1:11435. baseUrl is an alias.
  • apiKey: a bearer token, for a server that requires OLLAYA_API_KEY.
  • defaultHeaders: extra request headers. headers is an alias.
  • fetch: your own fetch function.