litertlm-go¶
A Go binding for Google's LiteRT-LM for high-performance local on-device LLM inference.
Inspired by Hybridgroup's Yzma.
📖 Full documentation: vladimirvivien.github.io/litertlm-go
Features¶
Client— single-callGenerate, range-over-funcGenerateStream, richGenerateResponse, plus the*Multivariants for image and audio inputs (Text/Image/ImageFromFile/AudioParts). Functional options for every engine setting. Context-driven cancellation. → Client guideChat— multi-turn conversations with system prompts, tool declarations, and structuredtool_callsparsing. Per-callRuntimeOptionknobs (WithVisualTokenBudget,WithReturnToolRequests,WithMaxConcurrentTools), parallel tool dispatch, multimodal history seeding viaWithInitialMessages, andChat.TokenCount()for cumulative usage. → Chat guideGenerateData[T]/GenerateDataMulti[T]— generic helpers that return*Tpopulated from the model's response via a synthesized tool-call capture (primary path) with a prompt-engineered fallback. TheMultivariant accepts image and audio Parts. → Structured output- Low-level API — every C-API symbol exposed as a Go method. Useful when you need explicit prefill→decode, scoring, token introspection, or deterministic resource lifetimes. → Low-level guide
Install¶
Quickstart¶
package main
import (
"context"
"fmt"
"os"
"github.com/vladimirvivien/litertlm-go/pkg/litertlm"
)
func main() {
ctx := context.Background()
client, err := litertlm.New(ctx,
litertlm.WithLib(os.Getenv("LITERTLM_LIB")),
litertlm.WithModel(os.Getenv("LITERTLM_MODEL")),
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer client.Close()
text, err := client.Generate(ctx, "Write a haiku about the sea.")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(text)
}
LITERTLM_LIB=/abs/path/to/dist/lib \
LITERTLM_MODEL=/abs/path/to/gemma-4-E2B-it.litertlm \
go run main.go
Full walkthrough: Getting started.
Building the C library¶
LiteRT-LM does not ship prebuilt C API shared libraries. Build them
using the platform guide:
LITERTLM-BUILD.md
(Linux/macOS) or
LITERTLM-BUILD-WINDOWS.md.
Minimum supported upstream: LiteRT-LM v0.12.0.
Examples¶
Self-contained programs covering every public API surface live under
examples/.
See the
examples index
for the full list.
License¶
Apache-2.0, same as LiteRT-LM itself.