Getting started¶
Prerequisites¶
-
Shared library — LiteRT-LM doesn't distribute a prebuilt C API. You will need to build it yourself following instructions in
LITERTLM-BUILD.md(Linux/macOS) orLITERTLM-BUILD-WINDOWS.md(Windows). At the end you should have a directory containing your library dependencies. -
A
.litertlmmodel file — download a model file from Hugging Face's LiteRT Community.gemma-4-E2B-it.litertlmandgemma-4-E4B-it.litertlmare good starting points. -
Go 1.26 or newer.
First program¶
Install the litertlm-go package:
Instantiate a LiteRT-LM engine client:
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.New:
- Loads the shared library set (calls
Loadinternally). - Builds an
EngineSettingswith the supplied options. - Constructs a LiteRT-LM
Enginefrom those settings. - Returns a
*Clientwith access to the engine.
client.Close() releases internal resources and deletes the engine.
Running the program¶
When executing the program, specify the location of the share libraries and a model file:
LITERTLM_LIB=/abs/path/to/dist/lib \
LITERTLM_MODEL=/abs/path/to/gemma-4-E2B-it.litertlm \
go run main.go
Expected output: a short haiku from the model:
What next¶
- One-shot text generation with sampler / token tuning → Client
- Multi-turn conversations with system prompts and tools → Chat
- Type-safe structured output (model returns JSON, you get a populated struct) → Structured output
- Drop down to the C-API-mirroring surface for prefill/decode, scoring, token introspection → Low-level API
- Hit a quirky model output, empty completion, or stray
default.profrawfiles? → Troubleshooting