Log inGet started

Calling a language model or a judge from your code

Updated December 1, 2026

A language model

The language-model offering is origozero/llm, endpoint chat. It answers as a stream, and stream reads it to the end and hands back the reply's text:

local ServiceCall = require("@builtin::modules.serviceCall")

local resp, err = ServiceCall.stream("origozero/llm", "chat", {
    body = {
        model = "deepseek/deepseek-v4.1-flash-1017",
        messages = {
            { role = "system", content = "You are a grumpy shopkeeper." },
            { role = "user", content = "Greet the customer who just walked in, in one line." },
        },
        stream = true,
        stream_options = { include_usage = true },
        max_tokens = 600,
    },
})
if resp then
    print(resp.text, resp.charged)
else
    print("no answer: " .. err)
end

stream(offering, endpoint, opts, onEvent?) returns { text, events, charged, balance } once the stream settles, or nil and the reason. Pass onEvent to receive each piece the moment it arrives, to show a reply while it is being written; each event carries its data and, for JSON, json.

The body is a chat-completion request. A refusal comes back at once, charges nothing, and names what the endpoint takes: the models it accepts, or a body field it does not take. So a call naming a model or a field the offering does not take answers with the ones it does. A model that reasons spends part of max_tokens before it writes, so a budget sized for the reply alone can come back with an empty text; the stream's last chunk states its finish_reason and usage.

An endpoint that answers in one response

ServiceCall.call(offering, endpoint, opts) makes the same direct call to an endpoint that answers in one response, and returns its { status, body, charged, balance }. A judge is one: Jev (origozero/jev, endpoint decide) answers questions about a state with probabilities.

local resp = ServiceCall.call("origozero/jev", "decide", {
    body = {
        model = "typesafe/jev-1.14",
        state = { text = "The door is open and the lights are off." },
        questions = { open = { type = "noul", instructions = "The door is open." } },
    },
})
print(resp and resp.body.answers.open.noul)   -- e.g. 0.92

A provider's own refusal arrives as a response whose status is 300 or more; ServiceCall.refusal(resp) reads it into a sentence.

A service operation whose answer is the point

A .service declares operations against an offering. One whose answer is the point is called with :call, which runs it directly and returns { value }, with no run behind it:

local text = asset.resolve("describe", "service"):call({
    instructions = "Answer in one word.",
    content = "Name a colour.",
}).value

:call checks the operation's inputs the way :invoke does and refuses asset_path and durable, since it writes nothing. The service asset type's README (types/service) covers both.

Where to make the call

A direct call yields while it waits, so make it from a task (task.spawn) or a component's own coroutine, never inside a frame-critical loop that cannot wait. World code runs on every peer, so make a call on the one peer that needs the answer (the player's own client for a line that player sees), or every peer pays for one request each. Keep a fixed fallback for a call that answers nil: signed out, out of credits, or offline.

  • documentation
  • guide
  • services
  • language-model
  • llm
  • ai