Summary

Functions

Builds a request to the Anthropic Messages API.
Builds a request to an OpenAI-compatible chat completions API.
Decodes JSON text with util.JSONToTable, without depth limits and without turning keys that look like numbers into numbers.
Creates a client.
Turns a reply of the Anthropic Messages API into a response.
Turns a reply of an OpenAI-compatible chat completions API into a response.
Encodes a table as JSON with util.TableToJSON, writing LLM.empty_object as {}.
Creates a message with the result of a tool call.
Creates a user message.

Functions

llm.providers.anthropic.build(client, request)

server packages/llm/lib/llm.lua:426

Builds a request to the Anthropic Messages API.

Parameters

  • client Client
  • request Map the request given to Client:chat

Returns

  • String endpoint path
  • Map headers
  • Map body

llm.providers.openai.build(client, request)

server packages/llm/lib/llm.lua:590

Builds a request to an OpenAI-compatible chat completions API.

Parameters

  • client Client
  • request Map the request given to Client:chat

Returns

  • String endpoint path
  • Map headers
  • Map body

llm.from_json(str)

server packages/llm/lib/llm.lua:100

Decodes JSON text with util.JSONToTable, without depth limits and without turning keys that look like numbers into numbers.

Parameters

  • str String JSON text

Returns

  • Table the decoded table, or nil if the text is not valid JSON

llm.new(options)

server packages/llm/lib/llm.lua:158

Creates a client.

LLM.new { provider = 'anthropic', api_key = key }
LLM.new { provider = 'openai', base_url = 'http://localhost:11434/v1', model = 'qwen3:8b' }

Parameters

  • options Map with the fields: provider='anthropic' [String 'anthropic', 'openai' or another key of LLM.providers] api_key=nil [String API key, may be omitted for local servers] model=nil [String model name; 'claude-opus-5-5' for Anthropic, required for other providers] base_url=nil [String API root that the endpoint path is appended to] max_tokens=16000 [Number maximum number of tokens in a reply, thinking included] max_tokens_key='max_tokens' [String body field of max_tokens for OpenAI-compatible APIs, OpenAI's reasoning models want 'max_completion_tokens'] effort=nil [String 'low', 'medium', 'high', ... sent as output_config.effort to Anthropic and as reasoning_effort to OpenAI-compatible APIs] fallbacks='default' [String/List/Boolean Anthropic refusal fallbacks, false to turn them off] betas=nil [List<String> extra Anthropic beta headers] headers=nil [Map extra HTTP headers] extra=nil [Map extra fields merged into every request body] timeout=120 [Number seconds to wait for a reply] max_retries=2 [Number retries of rate-limited, failed and timed out requests]

Returns

  • Client

llm.providers.anthropic.parse(data)

server packages/llm/lib/llm.lua:488

Turns a reply of the Anthropic Messages API into a response.

Parameters

  • data Map the decoded reply

Returns

  • Map the response

llm.providers.openai.parse(data)

server packages/llm/lib/llm.lua:627

Turns a reply of an OpenAI-compatible chat completions API into a response.

Parameters

  • data Map the decoded reply

Returns

  • Map the response, or nil if the reply has no choices
  • String the reason the reply could not be read

llm.to_json(tab)

server packages/llm/lib/llm.lua:92

Encodes a table as JSON with util.TableToJSON, writing LLM.empty_object as {}.

Parameters

  • tab Table

Returns

  • String JSON text

llm.tool_result(call, content, is_error)

server packages/llm/lib/llm.lua:118

Creates a message with the result of a tool call.

Parameters

  • call Map/String tool call from response.tool_calls, or its ID
  • content String/Table optional, defaults to '' result of the call, tables are sent as JSON
  • is_error Boolean optional, defaults to false whether the call has failed

Returns

  • Map the message

llm.user(content)

server packages/llm/lib/llm.lua:109

Creates a user message.

Parameters

  • content String text of the message, or a List of provider-specific content blocks

Returns

  • Map the message

Defined in