Tracked LLM Calls
Use kitaru.llm() with model aliases, transported runtime config, and optional secret-backed credentials
kitaru.llm() lets you make a single tracked model call with automatic:
prompt artifact capture
response artifact capture
usage/latency metadata logging
If you want the full setup path from stored credentials to an actual flow run, start with Secrets + Model Registration.
Model selection order
When you call kitaru.llm(), Kitaru resolves the model in this order:
the explicit
model=argumentKITARU_DEFAULT_MODELthe default alias from the effective model registry in the current environment
If KITARU_DEFAULT_MODEL matches a registered alias, Kitaru resolves that alias. Otherwise it treats the value as a raw provider/model string.
When you submit or replay a flow, Kitaru automatically transports your local model registry into the execution environment. That means remote runs can still resolve aliases with kitaru.llm() and kitaru model list. If KITARU_MODEL_REGISTRY is already set in the runtime environment, its aliases and default alias take precedence over matching local entries.
Register a model alias
kitaru model register fast --model openai/gpt-5-nano --secret openai-credsYou can also register an alias without a linked secret:
List aliases with:
kitaru model register writes aliases to local Kitaru config, but submitted and replayed runs automatically receive that registry as a transported runtime snapshot. KITARU_MODEL_REGISTRY is available as an advanced manual override for adding aliases or overriding matching ones.
Supported providers
Built-in runtime support covers:
openai/*— OpenAI models (requireskitaru[openai])anthropic/*— Anthropic models (requireskitaru[anthropic])ollama/*— local Ollama models (requireskitaru[openai], no API key needed)openrouter/*— OpenRouter meta-router (requireskitaru[openai])
Ollama and OpenRouter use the OpenAI-compatible API, so they share the kitaru[openai] extra — no additional packages needed.
Credential resolution order
For built-in providers that require credentials (OpenAI, Anthropic, OpenRouter), Kitaru resolves credentials in this order:
provider credentials already present in the environment
the secret linked to the resolved alias
otherwise, fail with a setup error
That means environment variables win over a linked secret for known providers.
Ollama does not require credentials (local server). Use OLLAMA_HOST to point to a non-default server address (default: http://localhost:11434).
Environment-backed setup
Secret-backed setup
Store provider keys in a Kitaru secret:
When an alias includes --secret openai-creds, kitaru.llm() loads that secret at runtime if the required environment variable is not already set.
Call kitaru.llm() inside a flow
kitaru.llm() inside a flowFlow-body kitaru.llm() calls are durable call boundaries. Use .load() when you need the text in flow-body Python, such as composing the next prompt. If you pass a checkpoint or LLM output into a downstream checkpoint, keep passing the original output handle. See In flow bodies for the general pattern.
Advanced options
kitaru.llm() also accepts system=, temperature=, and max_tokens=:
Chat-style message lists
Instead of a plain string, you can pass a chat-style message list:
Each message must include role and content keys. If system= is provided alongside a message list, Kitaru prepends a system message automatically.
When to use kitaru.llm() vs your own client
kitaru.llm() vs your own clientkitaru.llm() is designed for simple text-in/text-out model calls. It handles credential resolution, prompt/response capture, and usage tracking automatically. Built-in runtime support covers openai/*, anthropic/*, ollama/*, and openrouter/* models.
kitaru.llm() requires a provider SDK to be installed. Install with pip install kitaru[openai] (also covers Ollama and OpenRouter), pip install kitaru[anthropic], or pip install kitaru[llm] for both.
For advanced patterns — tool calling, structured outputs, streaming, vision inputs, or multi-turn conversation management — use your provider SDK directly inside a @checkpoint. You still get durable checkpointing and replay; you just manage the model interaction yourself:
For a full example of a tool-calling agent built this way, see examples/end_to_end/coding_agent/.
Tool calling and structured output support for kitaru.llm() is on the roadmap. For now, use your provider SDK directly inside checkpoints for these patterns.
Runtime behavior by context
Inside a flow (outside checkpoints):
kitaru.llm()runs as a synthetic durable call boundary.Inside a checkpoint: it is tracked as a child event; the enclosing checkpoint remains the replay boundary.
What Kitaru records
Each kitaru.llm() call records:
prompt artifacts
response artifacts
token usage
latency
credential source metadata (
environmentorsecret)
Example in this repository
If you want the full credential-backed setup path first, start with Secrets + Model Registration.
For the broader catalog, see Examples.
Related pages
Last updated
Was this helpful?