Model providers
Model providers are the ModelProvider strategies that connect the kernel to a real model API. @lite-agent/provider ships two maintained adapters — anthropic() for the Anthropic Messages API and openai() for OpenAI Chat Completions — and because the whole Chat Completions family shares one wire format, the same adapter also drives OpenAI-compatible and local endpoints (Ollama, vLLM, LM Studio, llama.cpp). Both adapters translate the provider's SSE stream into normalized ModelChunks and map every failure to ProviderError, so middleware like retry() works uniformly across vendors.
Quick start
Hand a provider to query from @lite-agent/sdk (or to createAgent from core):
anthropic(options?)
Creates a ModelProvider (id: "anthropic") that maps normalized requests to the Anthropic Messages API, wrapping @anthropic-ai/sdk.
Options — AnthropicProviderOptions
The returned provider also advertises context capabilities: automatic prompt caching, countTokens, and — when the client's beta.messages.create surface is present — Anthropic-native context edits (clearToolUses, clearThinking, compact).
There is no headers option. To set default headers, timeouts, or other SDK settings, construct the Anthropic client yourself and pass it via client:
openai(options?)
Creates a ModelProvider (id: "openai") that maps normalized requests to OpenAI Chat Completions, wrapping the openai SDK. Because the whole protocol family shares one wire format, the same adapter works against OpenAI-compatible and local endpoints.
Options — OpenAIProviderOptions
OpenAI-compatible and local endpoints
openai() accepts any server that speaks Chat Completions. Point baseURL at the server's /v1 root:
For loopback runtimes, prefer the strict local assembly: localOpenAI ships presets for ollama, vllm, lm-studio, and llama.cpp, enforces loopback-only endpoints, and runs a startup health probe.
Chat Completions transport working does not mean every endpoint supports native tool calls or usage reporting for every model. See Compatibility levels — verify a specific endpoint/runtime/model profile with the opt-in probe.
Stream translation: SSE → ModelChunk
Each adapter's core job is translating the provider's SSE event stream into the normalized ModelChunk union from @lite-agent/core:
What the translators guarantee:
- Text deltas stream in source order; their concatenation equals the final text block.
- Tool calls are accumulated from provider-native argument fragments and emitted as normalized
{ type: "tool_call", id, name, input }blocks with parsed JSON input. - A successful stream ends with exactly one
message_done, carrying the fullAssistantMessageandUsage(inputTokens/outputTokens).
Adapter-specific behavior worth knowing:
- Anthropic also surfaces
cacheReadTokens/cacheCreationTokensinusagewhen reported, emitscompactioncontent blocks, and wraps unknown block types as{ type: "native", provider: "anthropic", data }. Malformed tool-call JSON throws. - OpenAI assembles tool calls by
indexand falls back to{}when tool-call arguments fail to parse.
Error handling
Both adapters catch SDK errors and rethrow them as ProviderError (from @lite-agent/core), preserving the numeric HTTP status when available:
This applies to failures before output and mid-stream failures alike, so the core retry() middleware can classify them uniformly.
Retries
maxRetries defaults to 0 on both adapters on purpose: retry policy is owned by the core retry() middleware, and SDK-level retries would compound with it. Set maxRetries explicitly only if you want the SDK to retry on its own.
Offline testing with an injected client
Both factories accept a client that only has to satisfy a small structural type — AnthropicClientLike (messages.create returning an async iterable of raw stream events) or OpenAIClientLike (chat.completions.create returning chunks). That makes tests fully deterministic and network-free:
The same seam is how the repo's own conformance suite runs against both adapters without any network access.
Compatibility levels
The repo distinguishes three levels of support — "OpenAI-compatible" is a protocol claim, not a certification:
Probing an endpoint
An opt-in smoke test verifies a real OpenAI-compatible endpoint on demand (never in default CI):
The base profile checks text deltas, a single final message_done, delta/final-text consistency, and usage shape. Passing means verified for this endpoint/runtime/model profile — not that every model on that runtime behaves identically.
API summary
See also
- The nine strategies — the
ModelProviderstrategy interface these adapters implement. - Tool-call codecs — pair
nativeCodec()with these providers, or a prompt codec with local models. - Strict local assembly — maintained presets for local runtimes (Ollama, vLLM, LM Studio, llama.cpp).
- Testing utilities —
providerConformanceandfakeProviderfor network-free tests.