Skip to content

Elixir API Reference

Create a new LLM client with simple scalar configuration.

This is the primary binding entry-point. All parameters except api_key are optional — omitting them uses the same defaults as ClientConfigBuilder.

Errors:

Returns LiterLlmError if the underlying HTTP client cannot be constructed, or if the resolved provider configuration is invalid.

Signature:

@spec create_client(api_key, base_url, timeout_secs, max_retries, model_hint) :: {:ok, term()} | {:error, term()}
def create_client(api_key, base_url, timeout_secs, max_retries, model_hint)

Example:

{:ok, result} = create_client("value", "value", 42, 42, "value")

Parameters:

Name Type Required Description
api_key String.t() Yes The api key
base_url String.t() | nil No The base url
timeout_secs integer() | nil No The timeout secs
max_retries integer() | nil No The max retries
model_hint String.t() | nil No The model hint

Returns: DefaultClient

Errors: Returns {:error, reason}


Create a new LLM client from a JSON string.

The JSON object accepts the same fields as liter-llm.toml (snake_case).

Errors:

Returns LiterLlmError.BadRequest if json is not valid JSON or contains unknown fields.

Signature:

@spec create_client_from_json(json) :: {:ok, term()} | {:error, term()}
def create_client_from_json(json)

Example:

{:ok, result} = create_client_from_json("value")

Parameters:

Name Type Required Description
json String.t() Yes The json

Returns: DefaultClient

Errors: Returns {:error, reason}


Encode bytes as a base64 data URL: data:<mime>;base64,<b64>.

mime defaults to IMAGE_PNG when nil.

Signature:

@spec encode_data_url(bytes, mime) :: {:ok, term()} | {:error, term()}
def encode_data_url(bytes, mime)

Example:

{:ok, result} = encode_data_url(<<100, 97, 116, 97>>, "value")

Parameters:

Name Type Required Description
bytes binary() Yes The bytes
mime String.t() | nil No The mime

Returns: String.t()


Decode a base64 data URL into DecodedDataUrl.

Returns nil for:

  • Non-data URLs (strings that do not start with "data:").
  • Malformed prefixes (missing ";base64," marker).
  • Invalid base64 payloads.

The returned MIME string is extracted verbatim from the URL prefix — it is not validated or normalised.

Signature:

@spec decode_data_url(url) :: {:ok, term()} | {:error, term()}
def decode_data_url(url)

Example:

{:ok, result} = decode_data_url("value")

Parameters:

Name Type Required Description
url String.t() Yes The URL to fetch

Returns: DecodedDataUrl | nil


Register a custom provider in the global runtime registry.

The provider will be checked before all built-in providers during model detection. If a provider with the same name already exists it is replaced.

Errors:

Returns an error if the config is invalid (empty name, empty base_url, or no model prefixes).

Signature:

@spec register_custom_provider(config) :: {:ok, term()} | {:error, term()}
def register_custom_provider(config)

Example:

:ok = register_custom_provider(%{{}})

Parameters:

Name Type Required Description
config CustomProviderConfig Yes The configuration options

Returns: No return value.

Errors: Returns {:error, reason}


Remove a previously registered custom provider by name.

Returns true if a provider with the given name was found and removed, false if no such provider existed.

Errors:

Returns an error if the custom-provider registry cannot be updated.

Signature:

@spec unregister_custom_provider(name) :: {:ok, term()} | {:error, term()}
def unregister_custom_provider(name)

Example:

{:ok, result} = unregister_custom_provider("value")

Parameters:

Name Type Required Description
name String.t() Yes The name

Returns: boolean()

Errors: Returns {:error, reason}


Return the capability flags for a named provider.

Performs an O(n) linear scan over the embedded registry (165 entries). Returns an owned value so bindings can pass capability data without borrowing registry internals.

For unknown provider_name values the function returns an all-false sentinel so callers never need to handle Option.

Signature:

@spec capabilities(provider_name) :: {:ok, term()} | {:error, term()}
def capabilities(provider_name)

Example:

{:ok, result} = capabilities("value")

Parameters:

Name Type Required Description
provider_name String.t() Yes The provider name

Returns: ProviderCapabilities


Return all provider configs from the registry.

Useful for tooling, documentation generation, or runtime enumeration. Returns the public ProviderConfig slice (without capability flags). To query capability flags for a specific provider use capabilities.

Signature:

@spec all_providers() :: {:ok, term()} | {:error, term()}
def all_providers()

Example:

{:ok, result} = all_providers()

Returns: list(ProviderConfig)

Errors: Returns {:error, reason}


Return the set of complex provider names.

Complex providers require custom auth/routing logic beyond simple bearer tokens (e.g. AWS Bedrock SigV4, Vertex AI OAuth2).

The returned reference points into the static registry — no allocation.

Signature:

@spec complex_provider_names() :: {:ok, term()} | {:error, term()}
def complex_provider_names()

Example:

{:ok, result} = complex_provider_names()

Returns: list(String.t())

Errors: Returns {:error, reason}


Calculate the estimated cost of a completion given a model name and token counts.

Returns nil if the model is not present in the embedded pricing registry. Returns Some(cost_usd) otherwise, where the value is in US dollars.

When an exact model name match is not found, progressively shorter prefixes are tried by stripping from the last - or . separator. For example, gpt-4-0613 will match gpt-4 if no gpt-4-0613 entry exists.

Signature:

@spec completion_cost(model, prompt_tokens, completion_tokens) :: {:ok, term()} | {:error, term()}
def completion_cost(model, prompt_tokens, completion_tokens)

Example:

{:ok, result} = completion_cost("value", 42, 42)

Parameters:

Name Type Required Description
model String.t() Yes The model
prompt_tokens integer() Yes The prompt tokens
completion_tokens integer() Yes The completion tokens

Returns: float() | nil


Calculate the estimated cost of a completion, accounting for cached (cache-hit) prompt tokens billed at the provider’s discounted rate.

cached_tokens is the count of prompt tokens served from the provider’s prompt cache. It must be <= prompt_tokens (cached tokens are a subset of the prompt). The non-cached portion is billed at input_cost_per_token and the cached portion at cache_read_input_token_cost when the model has cache pricing; otherwise the entire prompt is billed at the regular input rate.

Returns nil if the model is not present in the embedded pricing registry, mirroring completion_cost.

When the model has ModelPricing.tiers, the tier whose min_context_tokens is the highest value <= prompt_tokens supplies the input/output/cache rates for the whole call; models without tiers (or when prompt_tokens is below every tier threshold) use the base rates unchanged, matching the original flat-rate behaviour.

Signature:

@spec completion_cost_with_cache(model, prompt_tokens, cached_tokens, completion_tokens) :: {:ok, term()} | {:error, term()}
def completion_cost_with_cache(model, prompt_tokens, cached_tokens, completion_tokens)

Example:

{:ok, result} = completion_cost_with_cache("value", 42, 42, 42)

Parameters:

Name Type Required Description
model String.t() Yes The model
prompt_tokens integer() Yes The prompt tokens
cached_tokens integer() Yes The cached tokens
completion_tokens integer() Yes The completion tokens

Returns: float() | nil


Look up FFI-friendly pricing and capability metadata for a model.

Returns nil if the model is not present in the active pricing registry. Uses the same exact-match-then-prefix-fallback resolution as model_pricing; unlike model_pricing, the result is an owned ModelInfo value safe to hand across the FFI boundary.

When a runtime catalog refresh has succeeded, this reflects the refreshed (overlay) catalog; otherwise it reflects the embedded catalog. See model_pricing for the embedded-only alternative.

Signature:

@spec model_info(model) :: {:ok, term()} | {:error, term()}
def model_info(model)

Example:

{:ok, result} = model_info("value")

Parameters:

Name Type Required Description
model String.t() Yes The model

Returns: ModelInfo | nil


Remove all guardrails from the global registry.

Primarily useful in tests to reset state between test cases.

Panics:

Panics if the global registry lock is poisoned.

Signature:

@spec clear() :: {:ok, term()} | {:error, term()}
def clear()

Example:

:ok = clear()

Returns: No return value.


Count tokens in a text string using the tokenizer for the given model.

The tokenizer is resolved from the model name prefix (e.g. "gpt-4o" maps to the Xenova/gpt-4o HuggingFace tokenizer). Tokenizers are cached after first load.

Errors:

Returns LiterLlmError.BadRequest if the tokenizer cannot be loaded (e.g. network failure on first use) or if tokenization itself fails.

Signature:

@spec count_tokens(model, text) :: {:ok, term()} | {:error, term()}
def count_tokens(model, text)

Example:

{:ok, result} = count_tokens("value", "value")

Parameters:

Name Type Required Description
model String.t() Yes The model
text String.t() Yes The text

Returns: integer()

Errors: Returns {:error, reason}


Count tokens for a full ChatCompletionRequest.

Sums tokens across all message text contents plus a per-message overhead of ~4 tokens (for role, separators, and formatting metadata). Tool definitions and multimodal content parts (images, audio, documents) are not counted — only textual content contributes to the token total.

Errors:

Returns LiterLlmError.BadRequest if the tokenizer cannot be loaded or if tokenization fails for any message.

Signature:

@spec count_request_tokens(model, req) :: {:ok, term()} | {:error, term()}
def count_request_tokens(model, req)

Example:

{:ok, result} = count_request_tokens("value", %{{}})

Parameters:

Name Type Required Description
model String.t() Yes The model
req ChatCompletionRequest Yes The chat completion request

Returns: integer()

Errors: Returns {:error, reason}


Assert that current_len + incoming does not exceed limit.

Call this before appending incoming bytes to any buffer that must stay below limit. Returns Err(LiterLlmError.Streaming) on overflow and emits a tracing.warn! with context.

Signature:

@spec check_bound(context, current_len, incoming, limit) :: {:ok, term()} | {:error, term()}
def check_bound(context, current_len, incoming, limit)

Example:

:ok = check_bound("value", 42, 42, 42)

Parameters:

Name Type Required Description
context String.t() Yes The context
current_len integer() Yes The current len
incoming integer() Yes The incoming
limit integer() Yes The limit

Returns: No return value.

Errors: Returns {:error, reason}


Install the ring crypto provider as the rustls process default, idempotently.

rustls 0.23+ removed the implicit default provider. This function installs ring once per process. Subsequent calls are no-ops. Calling it after another rustls crypto provider has already been installed is safe: the Err from install_default() is silently ignored.

Called automatically by every internal reqwest.Client constructor (auth providers, default HTTP client). Bindings and downstream consumers reach those constructors transitively, so no manual init is required.

WASM builds are exempt — the WASM target uses the browser/Node.js fetch API instead of rustls, so no crypto provider is needed.

Windows builds use native-tls (SChannel) via reqwest, so rustls is not present and no crypto provider installation is needed.

Signature:

@spec ensure_crypto_provider() :: {:ok, term()} | {:error, term()}
def ensure_crypto_provider()

Example:

:ok = ensure_crypto_provider()

Returns: No return value.


No-op on Windows: reqwest uses native-tls (SChannel), so no rustls provider installation is needed. All callers use the same call site regardless of platform.

Signature:

@spec ensure_crypto_provider() :: {:ok, term()} | {:error, term()}
def ensure_crypto_provider()

Example:

:ok = ensure_crypto_provider()

Returns: No return value.


Install the overlay registry from a raw catalog JSON string, bypassing the network and disk cache entirely.

Parses and flattens catalog_json with the same registry_from_catalog_str logic used for the embedded catalog and the network refresh path, then atomically swaps it in as the active overlay. A parse failure returns CatalogRefreshError.Parse and leaves any existing overlay untouched.

This is primarily a testable seam: it lets tests exercise overlay installation and the embedded/overlay fallback behavior in completion_cost / model_info without a real network call.

Signature:

@spec install_catalog_overlay_from_str(catalog_json) :: {:ok, term()} | {:error, term()}
def install_catalog_overlay_from_str(catalog_json)

Example:

:ok = install_catalog_overlay_from_str("value")

Parameters:

Name Type Required Description
catalog_json String.t() Yes The catalog json

Returns: No return value.

Errors: Returns {:error, reason}


Clear the overlay registry, reverting completion_cost, completion_cost_with_cache, and model_info to the embedded catalog.

Primarily a test seam (see install_catalog_overlay_from_str); also usable by long-running processes that want to abandon a runtime refresh.

Signature:

@spec clear_catalog_overlay() :: {:ok, term()} | {:error, term()}
def clear_catalog_overlay()

Example:

:ok = clear_catalog_overlay()

Returns: No return value.


Refresh the runtime catalog overlay per config.

  • config.enabled == false: returns Ok(RefreshOutcome.Disabled) immediately. No network, filesystem, or overlay activity.

  • A fresh on-disk cache (age < config.ttl_seconds) exists at the resolved cache path (config.cache_path, or a default under std.env.temp_dir()): read + flatten it and install the overlay, returning Ok(RefreshOutcome.FromCache). No network request is made.

  • Otherwise: validate config.source_url uses https (CatalogRefreshError.InsecureUrl otherwise), fetch it, flatten it, install the overlay, best-effort write the raw JSON to the cache path (a cache write failure does not fail the refresh), and return Ok(RefreshOutcome.Fetched).

On any error return, the overlay is left untouched: the previously active registry (a prior successful overlay, or the embedded catalog if none was ever installed) remains in effect. This is what makes the feature air-gap-safe — an unreachable or invalid source_url never degrades completion_cost / model_info below embedded-catalog availability.

Signature:

@spec refresh_catalog(config) :: {:ok, term()} | {:error, term()}
def refresh_catalog(config)

Example:

{:ok, result} = refresh_catalog(%{{}})

Parameters:

Name Type Required Description
config CatalogRefreshConfig Yes The configuration options

Returns: RefreshOutcome

Errors: Returns {:error, reason}


Assistant’s response to a user message.

Field Type Default Description
content AssistantContent | nil nil The assistant’s response: plain text, structured parts, or absent. nil is valid when the model replies with tool calls only.
name String.t() | nil nil Optional name for the assistant.
tool_calls list(ToolCall) | nil \[\] Tool calls the model wants to execute, if any.
refusal String.t() | nil nil Refusal reason, if the model declined to respond per safety policies.
function_call FunctionCall | nil nil Deprecated legacy function_call field; retained for API compatibility.
reasoning_content String.t() | nil nil Reasoning/thinking tokens returned by the provider, if any (e.g. DeepSeek R1, Qwen reasoning_content, or Anthropic extended thinking).

Return the assistant’s textual response, concatenating all Text parts if the content is structured.

Returns nil for Refusal-only or OutputImage-only responses.

Signature:

def text()

Example:

{:ok, result} = instance.text()

Returns: String.t() | nil

Return the refusal message, if the model declined to respond.

Checks both the top-level refusal field and any Refusal parts inside a structured content.

Signature:

def refusal_text()

Example:

{:ok, result} = instance.refusal_text()

Returns: String.t() | nil

Return the model’s reasoning/thinking tokens, if the provider returned any.

Signature:

def reasoning_text()

Example:

{:ok, result} = instance.reasoning_text()

Returns: String.t() | nil

Return all AssistantPart.OutputImage parts in the response.

Signature:

def output_images()

Example:

{:ok, result} = instance.output_images()

Returns: list(ImageUrl)

Return all AssistantPart.OutputAudio parts in the response.

Signature:

def output_audio()

Example:

{:ok, result} = instance.output_audio()

Returns: list(AudioContent)


Audio content part for speech-capable models.

Field Type Default Description
data String.t() Base64-encoded audio data.
format String.t() Audio format (e.g., “wav”, “mp3”, “ogg”).

Auth configuration block.

Field Type Default Description
auth_type AuthType Auth scheme classification.
env_var String.t() | nil nil Name of the environment variable that holds the API key (e.g. "OPENAI_API_KEY"). Holds the variable name, never the secret value.

Query parameters for listing batches.

Field Type Default Description
limit integer() | nil nil Maximum number of results to return. Defaults to 20.
after String.t() | nil nil Pagination cursor: return results after this batch ID.

Response from listing batches.

Field Type Default Description
object String.t() Object type (always "list").
data list(BatchObject) \[\] List of batch objects.
has_more boolean() | nil nil Whether more results are available.
first_id String.t() | nil nil First batch ID in the result set (for pagination).
last_id String.t() | nil nil Last batch ID in the result set (for pagination).

A batch job object.

Field Type Default Description
id String.t() Unique batch ID.
object String.t() Object type (always "batch").
endpoint String.t() API endpoint (e.g., "/v1/chat/completions").
input_file_id String.t() ID of the input file.
completion_window String.t() Completion window (e.g., "24h").
status BatchStatus :validating Current job status.
output_file_id String.t() | nil nil ID of the output file (present when completed).
error_file_id String.t() | nil nil ID of the error file (present if some requests failed).
created_at integer() Unix timestamp of batch creation.
completed_at integer() | nil nil Unix timestamp of completion (if completed).
failed_at integer() | nil nil Unix timestamp of failure (if failed).
expired_at integer() | nil nil Unix timestamp of expiration (if expired).
request_counts BatchRequestCounts | nil nil Request processing counts.
metadata term() | nil nil Metadata attached to the batch.

Request processing counts for a batch.

Field Type Default Description
total integer() Total requests in the batch.
completed integer() Completed requests.
failed integer() Failed requests.

AWS Bedrock configuration.

All fields are optional; anything left unset falls back to the standard AWS environment variables (AWS_DEFAULT_REGION / AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, BEDROCK_CROSS_REGION).

Field Type Default Description
region String.t() | nil nil AWS region (e.g. "us-east-1").
cross_region_prefix String.t() | nil nil Cross-region inference profile prefix (e.g. "us").
access_key_id String.t() | nil nil Explicit AWS access key ID.
secret_access_key String.t() | nil nil Explicit AWS secret access key.
session_token String.t() | nil nil Explicit AWS session token (temporary credentials).

Configuration for budget enforcement.

Field Type Default Description
global_limit float() | nil nil Maximum total spend across all models, in USD. nil means unlimited.
model_limits map() %{} Per-model spending limits in USD. Models not listed here are only constrained by global_limit.
enforcement Enforcement :hard Whether to reject requests or merely warn when a limit is exceeded.

Signature:

def default()

Example:

{:ok, result} = BudgetConfig.default()

Returns: BudgetConfig


Configuration for the response cache.

Field Type Default Description
max_entries integer() 256 Maximum number of cached entries.
ttl integer() 300000ms Time-to-live for each cached entry.
backend CacheBackend :memory Storage backend to use.

Signature:

def default()

Example:

{:ok, result} = CacheConfig.default()

Returns: CacheConfig


Plain-data configuration for refresh_catalog.

Deliberately FFI/binding-friendly: no Duration or PathBuf, just primitives that translate directly across language boundaries.

Field Type Default Description
enabled boolean() false Runtime catalog refresh is entirely opt-in: when false, refresh_catalog is a no-op that returns Ok(RefreshOutcome.Disabled) without touching the network, the filesystem, or the overlay registry.
source_url String.t() Source URL to fetch catalog.json from. Must be https. Defaults to DEFAULT_CATALOG_URL; configurable so self-hosted mirrors work.
ttl_seconds integer() 86400 How long a cached catalog.json remains valid before a network refetch is attempted, in seconds.
cache_path String.t() | nil nil Filesystem path for the on-disk cache. nil uses a default path under std.env.temp_dir().

Signature:

def default()

Example:

{:ok, result} = CatalogRefreshConfig.default()

Returns: CatalogRefreshConfig


A streamed chunk of a chat completion response.

Field Type Default Description
id String.t() Unique identifier for this stream.
object String.t() Always "chat.completion.chunk" from OpenAI-compatible APIs. Stored as a plain String so non-standard provider values do not fail parsing.
created integer() Unix timestamp of chunk creation.
model String.t() Model used to generate the chunk.
choices list(StreamChoice) \[\] Streaming choices (delta updates).
usage Usage | nil nil Token usage (typically only in the final chunk).
system_fingerprint String.t() | nil nil Fingerprint of the system configuration (OpenAI-specific).
service_tier String.t() | nil nil Service tier used (OpenAI-specific).

Chat completion request (compatible with OpenAI and similar APIs).

Field Type Default Description
model String.t() Model ID (e.g., "gpt-4o-mini", "claude-3-5-sonnet").
messages list(Message) \[\] Conversation history from oldest to newest.
temperature float() | nil nil Sampling temperature in \[0.0, 2.0\]. Higher increases randomness. Defaults to 1.0.
top_p float() | nil nil Nucleus sampling parameter in \[0.0, 1.0\]. Lower is more focused.
n integer() | nil nil Number of chat completions to generate. Defaults to 1.
stream boolean() | nil nil Whether to stream the response. Managed by the client layer — do not set directly.
stop StopSequence | nil nil Stop sequence(s) that halt token generation.
max_tokens integer() | nil nil Max output tokens. Different from max_completion_tokens in some providers.
presence_penalty float() | nil nil Presence penalty in \[-2.0, 2.0\]. Positive discourages repeated topics.
frequency_penalty float() | nil nil Frequency penalty in \[-2.0, 2.0\]. Positive discourages repeated tokens.
logit_bias map() | nil %{} Token bias map. Uses BTreeMap (sorted keys) for deterministic serialization order — important when hashing or signing requests.
user String.t() | nil nil User identifier for request tracking and abuse detection.
tools list(ChatCompletionTool) | nil \[\] Tools the model can invoke.
tool_choice ToolChoice | nil nil Tool usage mode (auto, required, none, or specific tool).
parallel_tool_calls boolean() | nil nil Whether the model can call multiple tools in parallel. Defaults to true.
response_format ResponseFormat | nil nil Output format constraint (text, JSON, JSON schema).
stream_options StreamOptions | nil nil Streaming options (e.g., include_usage).
seed integer() | nil nil Random seed for reproducible outputs. Provider support varies.
reasoning_effort ReasoningEffort | nil nil Reasoning effort level (minimal, low, medium, high, max) for extended-thinking models.
modalities list(Modality) | nil \[\] Output modalities to request from the model. For OpenAI audio models, pass \["text", "audio"\]. Vertex AI / Gemini translates these to generationConfig.responseModalities (uppercase).
extra_body term() | nil nil Provider-specific extra parameters merged into the request body. Use for guardrails, safety settings, grounding config, etc.

Chat completion response from the API.

Field Type Default Description
id String.t() Unique identifier for this response.
object String.t() Always "chat.completion" from OpenAI-compatible APIs. Stored as a plain String so non-standard provider values do not break deserialization.
created integer() Unix timestamp of response creation.
model String.t() Model used to generate the response.
choices list(Choice) \[\] List of completion choices.
usage Usage | nil nil Token usage statistics.
system_fingerprint String.t() | nil nil Fingerprint of the system configuration (OpenAI-specific).
service_tier String.t() | nil nil Service tier used (OpenAI-specific).

A tool the model can invoke (currently, all tools are functions).

Field Type Default Description
tool_type ToolType Tool type (always “function” in OpenAI spec).
function FunctionDefinition Function definition with name, description, and JSON schema parameters.

A single completion choice.

Field Type Default Description
index integer() Index of this choice in the choices array.
message AssistantMessage The assistant’s message response.
finish_reason FinishReason | nil nil Why the model stopped generating (stop, length, tool_calls, content_filter, etc.).

A per-chunk transformation in the StreamPipeline.

Each middleware receives a typed chunk and returns Ok(Some(chunk)) to pass it through (optionally modified), Ok(None) to drop the chunk, or Err(e) to propagate a stream error.

The trait is object-safe so multiple middleware implementations can be chained inside StreamPipeline.

Process a single chunk.

  • Ok(Some(chunk)) — emit (possibly transformed) chunk.
  • Ok(None) — drop this chunk silently.
  • Err(e) — propagate as a stream error.

Signature:

def process(chunk)

Example:

{:ok, result} = instance.process(%{{}})

Parameters:

Name Type Required Description
chunk ChatCompletionChunk Yes The chat completion chunk

Returns: ChatCompletionChunk | nil

Errors: Returns {:error, reason}


Request to create a batch job.

Field Type Default Description
input_file_id String.t() ID of the uploaded input file (JSONL format).
endpoint String.t() API endpoint (e.g., "/v1/chat/completions").
completion_window String.t() Completion window (e.g., "24h").
metadata term() | nil nil Optional metadata to attach to the batch.

Request to upload a file.

Field Type Default Description
file String.t() Base64-encoded file data.
purpose FilePurpose :assistants Purpose for the file.
filename String.t() | nil nil Optional filename to associate with the upload.

Request to create images from a text prompt.

Field Type Default Description
prompt String.t() Text description of the image to generate.
model String.t() | nil nil Model ID (e.g., "dall-e-3"). Optional; API may use default if unset.
n integer() | nil nil Number of images to generate. Defaults to 1.
size String.t() | nil nil Image size (e.g., "1024x1024", "1792x1024").
quality String.t() | nil nil Image quality: "standard" or "hd".
style String.t() | nil nil Style: "natural" or "vivid" (DALL-E 3 only).
response_format String.t() | nil nil Response format: "url" or "b64_json".
user String.t() | nil nil User identifier for request tracking.

Request to create a structured response.

Field Type Default Description
model String.t() Model ID.
input term() Input data to process (e.g., a document to extract from).
instructions String.t() | nil nil Instructions for processing the input.
tools list(ResponseTool) | nil \[\] Available tools the model can use.
temperature float() | nil nil Sampling temperature in \[0.0, 2.0\]. Defaults to 1.0.
max_output_tokens integer() | nil nil Maximum output tokens.
metadata term() | nil nil Optional metadata.
stream boolean() | nil nil Whether to stream the response. Managed by the client layer — do not set directly.

Request to generate speech audio from text.

Field Type Default Description
model String.t() Model ID (e.g., "tts-1", "tts-1-hd").
input String.t() Text to synthesize into speech.
voice String.t() Voice name (e.g., "alloy", "echo", "fable", "onyx", "nova", "shimmer").
response_format String.t() | nil nil Audio format (e.g., "mp3", "opus", "aac", "flac", "wav", "pcm").
speed float() | nil nil Playback speed in \[0.25, 4.0\]. Defaults to 1.0.

Request to transcribe audio into text.

Field Type Default Description
model String.t() Model ID (e.g., "whisper-1").
file String.t() Base64-encoded audio file data.
language String.t() | nil nil Language ISO-639-1 code (e.g., "en", "fr", "de"). Optional; model auto-detects.
prompt String.t() | nil nil Optional text to guide the model (improves accuracy for domain-specific terms).
response_format String.t() | nil nil Output format (e.g., "json", "text", "vtt", "srt", "verbose_json").
temperature float() | nil nil Sampling temperature in \[0.0, 1.0\]. Higher increases variability. Defaults to 0.

Configuration for registering a custom LLM provider at runtime.

Field Type Default Description
name String.t() Unique name for this provider (e.g., “my-provider”).
base_url String.t() Base URL for the provider’s API (e.g., <https://api.my-provider.com/v1>).
auth_header AuthHeaderFormat Authentication header format.
model_prefixes list(String.t()) Model name prefixes that route to this provider (e.g., \["my-"\]).

Result of decoding a data: URL — MIME type and the decoded byte payload.

Named struct (rather than a tuple) so polyglot bindings can extract decode_data_url with a typed return rather than a sanitized scalar.

Field Type Default Description
mime String.t() MIME type extracted from the URL prefix (verbatim, not normalised).
data binary() Decoded base64 payload.

Default client implementation backed by reqwest.

Sends requests to 165 LLM providers with automatic provider detection and per-request routing. The provider is resolved at construction time from model_hint (or defaults to OpenAI), but individual requests can override the provider via model name prefix (e.g. "anthropic/claude-3-5-sonnet" routes to Anthropic regardless of construction-time setting).

When the model prefix does not match any known provider, the construction-time provider is used as the fallback. This enables seamless migration between providers by changing only the model name.

The provider is stored behind an Arc so it can be shared cheaply into async closures and streaming tasks. Pre-computed auth headers and extra headers are cached at construction to avoid redundant encoding on every request.

Signature:

def fetch_batch_for_polling(batch_id)

Example:

{:ok, result} = instance.fetch_batch_for_polling("value")

Parameters:

Name Type Required Description
batch_id String.t() Yes The batch id

Returns: BatchObject

Errors: Returns {:error, reason}

Poll a batch until it reaches a terminal status (Completed, Failed, Expired, Cancelled).

Uses exponential backoff with configurable initial interval, maximum interval, and backoff multiplier. Optionally supports a timeout that aborts polling if exceeded.

Errors:

Returns BatchWaitError.Failed if the batch reaches a failure terminal status. Returns BatchWaitError.Timeout if the configured timeout is exceeded. Returns BatchWaitError.Client for underlying client errors.

Signature:

def wait_for_batch(batch_id, config)

Example:

{:ok, result} = instance.wait_for_batch("value", %{{}})

Parameters:

Name Type Required Description
batch_id String.t() Yes The batch id
config WaitForBatchConfig Yes The configuration options

Returns: BatchObject

Errors: Returns {:error, reason}


Response from a delete operation.

Field Type Default Description
id String.t() ID of the deleted resource.
object String.t() Object type.
deleted boolean() Confirmation that the resource was deleted.

Developer message (system-like message for Claude models).

Field Type Default Description
content String.t() Developer-specific instructions or context.
name String.t() | nil nil Optional name for the developer message source.

PDF/document content part for vision-capable models.

Field Type Default Description
data String.t() Base64-encoded document data or URL.
media_type String.t() MIME type (e.g., “application/pdf”, “text/csv”).

A single embedding vector.

Field Type Default Description
object String.t() Always "embedding" from OpenAI-compatible APIs. Stored as a plain String so non-standard provider values do not break deserialization.
embedding list(float()) The embedding vector. Providers may return this as a JSON float array or, when encoding_format: "base64" was requested, as a base64 string of little-endian f32 bytes. Base64 responses are decoded on read; this field always serializes back out as a JSON float array.
index integer() Index in the batch (corresponds to input order).

Embedding request.

Field Type Default Description
model String.t() Model ID (e.g., "text-embedding-3-small").
input EmbeddingInput :single Text or texts to embed.
encoding_format EmbeddingFormat | nil nil Output format: float (native) or base64.
dimensions integer() | nil nil Requested embedding dimensions (if supported by the model).
user String.t() | nil nil User identifier for request tracking.

Embedding response.

Field Type Default Description
object String.t() Always "list" from OpenAI-compatible APIs. Stored as a plain String so non-standard provider values do not break deserialization.
data list(EmbeddingObject) List of embeddings.
model String.t() Model used to generate embeddings.
usage Usage | nil /* serde(default) */ Token usage (input tokens only; embeddings have zero output tokens).

Query parameters for listing files.

Field Type Default Description
purpose String.t() | nil nil Filter by file purpose (e.g., "batch", "fine-tune").
limit integer() | nil nil Maximum number of results to return. Defaults to 20.
after String.t() | nil nil Pagination cursor: return results after this file ID.

Response from listing files.

Field Type Default Description
object String.t() Object type (always "list").
data list(FileObject) \[\] List of file objects.
has_more boolean() | nil nil Whether more results are available.

An uploaded file object.

Field Type Default Description
id String.t() Unique file ID.
object String.t() Object type (always "file").
bytes integer() File size in bytes.
created_at integer() Unix timestamp of file creation.
filename String.t() Filename.
purpose String.t() File purpose.
status String.t() | nil nil Processing status (e.g., "uploaded", "processed").

Function call details.

Field Type Default Description
name String.t() Function name.
arguments String.t() Arguments as a JSON string (parse with serde_json.from_str).

Function definition exposed to the model.

Field Type Default Description
name String.t() Name of the function. Required and must be alphanumeric + underscores.
description String.t() | nil /* serde(default) */ Human-readable description explaining what the function does.
parameters term() | nil /* serde(default) */ JSON Schema defining the function’s parameters.
strict boolean() | nil /* serde(default) */ If true, enforce strict JSON schema validation for arguments.

Deprecated legacy function-role message body.

Field Type Default Description
content String.t() The extracted text content
name String.t() The name

Abstraction over a health probe strategy.

Implementors issue a lightweight probe against upstream (typically a provider base URL or named identifier) and report HealthStatus.

Probe upstream and return its current HealthStatus.

The parameter is taken by value (String) so that implementations can move it into the returned future without a clone, making the 'static + Send bound on the future trivially satisfiable.

Signature:

def check(upstream)

Example:

{:ok, result} = instance.check("value")

Parameters:

Name Type Required Description
upstream String.t() Yes The upstream

Returns: HealthStatus


A single generated image, returned as either a URL or base64 data.

Field Type Default Description
url String.t() | nil nil Image URL (if response_format was “url”).
b64_json String.t() | nil nil Base64-encoded image data (if response_format was “b64_json”).
revised_prompt String.t() | nil nil The final prompt used to generate the image (DALL-E 3).

An image URL reference with optional detail level for processing.

Field Type Default Description
url String.t() URL of the image (data URI or HTTP/HTTPS URL).
detail ImageDetail | nil nil Detail level: low (512x512), high (2x2 tiles), or auto (model-selected).

Response containing generated images.

Field Type Default Description
created integer() Unix timestamp of image creation.
data list(Image) \[\] List of generated images.

An intent prototype: (intent_name, prototype_embedding, target_model_id).

Field Type Default Description
name String.t() Human-readable name for the intent (used in logs/metrics).
embedding list(float()) Pre-computed embedding vector for this intent.
model String.t() Model to route to when this intent is detected.

JSON Schema specification for constrained output.

Field Type Default Description
name String.t() Name of the schema (must be unique in the request).
description String.t() | nil nil Description of what the schema represents.
schema term() JSON Schema object defining the output structure.
strict boolean() | nil nil If true, enforce strict schema validation.

Budget enforcement configuration.

Field Type Default Description
global_limit float() | nil nil Global spend limit in USD.
model_limits map() | nil %{} Per-model spend limits in USD, keyed by model name.
enforcement String.t() | nil nil Enforcement mode: "hard" (reject over-budget requests) or "soft" (log only).

Response cache configuration.

Field Type Default Description
max_entries integer() | nil nil Maximum number of cached entries.
ttl_seconds integer() | nil nil Cache entry time-to-live, in seconds.
backend String.t() | nil nil Cache backend name (e.g. "memory", or an opendal scheme).
backend_config map() | nil %{} Backend-specific configuration key/value pairs.

Canonical configuration for an LLM client.

All fields except model are optional so that partially-specified configs (e.g. from environment-driven defaults) round-trip cleanly. Convert to a runtime client configuration via LlmConfig.into_client_builder.

temperature and max_tokens are request-time parameters rather than client-level settings; they are carried on this struct for callers to read when building individual requests, and are intentionally not mapped by LlmConfig.into_client_builder.

Field Type Default Description
model String.t() Model identifier (e.g. "gpt-4o", "bedrock/anthropic.claude-3-sonnet-20240229-v1:0").
api_key String.t() | nil nil API key for authentication.
base_url String.t() | nil nil Override base URL. When set, all requests go here and provider auto-detection is skipped.
timeout_secs integer() | nil nil Request timeout, in seconds.
max_retries integer() | nil nil Maximum number of retries on 429 / 5xx responses.
temperature float() | nil nil Sampling temperature for requests built from this config.
max_tokens integer() | nil nil Maximum number of tokens to generate for requests built from this config.
load_env boolean() | nil nil Automatically load the API key from the provider’s environment variable when no explicit key is provided (default: true).
headers map() | nil %{} Extra headers sent on every request.
providers list(LlmProviderConfig) | nil \[\] Custom provider configurations, in addition to the built-in providers.
cache LlmCacheConfig | nil nil Response cache configuration.
budget LlmBudgetConfig | nil nil Budget enforcement configuration.
rate_limit LlmRateLimitConfig | nil nil Per-model rate limiting configuration.
cost_tracking boolean() | nil nil Enable per-request cost tracking.
tracing boolean() | nil nil Enable OpenTelemetry-compatible tracing spans.
cooldown_secs integer() | nil nil Cooldown duration after transient errors, in seconds.
health_check_secs integer() | nil nil Background health check interval, in seconds.
bedrock BedrockConfig | nil nil AWS Bedrock configuration (region, credentials, cross-region routing).

Get the custom provider configurations from this config.

Signature:

def providers()

Example:

{:ok, result} = instance.providers()

Returns: list(LlmProviderConfig)


A custom provider configuration entry.

Field Type Default Description
name String.t() Provider name, used to key model prefix matching.
base_url String.t() Base URL for the provider’s OpenAI-compatible API.
auth_header String.t() | nil nil Header name used to carry the API key (defaults to Authorization when unset).
model_prefixes list(String.t()) \[\] Model name prefixes routed to this provider (e.g. \["my-provider/"\]).

Per-model rate limiting configuration.

Field Type Default Description
rpm integer() | nil nil Requests per minute limit.
tpm integer() | nil nil Tokens per minute limit.
window_seconds integer() | nil nil Rate limit window, in seconds.

Public, FFI-friendly snapshot of a model’s pricing and capability metadata, projected from ModelPricing.

Unlike ModelPricing (which is excluded from binding generation), ModelInfo is an owned plain-data DTO safe to hand across the FFI boundary — see model_info.

Field Type Default Description
input_cost_per_token float() Cost in USD per input (prompt) token.
output_cost_per_token float() Cost in USD per output (completion) token.
cache_read_input_token_cost float() | nil nil Cost in USD per cached input token (cache hit / read).
cache_creation_input_token_cost float() | nil nil Cost in USD per token written to the prompt cache.
input_cost_per_audio_token float() | nil nil Cost in USD per input audio token.
output_cost_per_audio_token float() | nil nil Cost in USD per output audio token.
output_cost_per_reasoning_token float() | nil nil Cost in USD per reasoning (extended-thinking) output token.
max_tokens integer() | nil nil Total context window size in tokens (input + output).
max_input_tokens integer() | nil nil Maximum input (prompt) tokens accepted.
max_output_tokens integer() | nil nil Maximum output (completion) tokens the model can generate.
mode String.t() | nil nil Best-effort operating mode, e.g. "chat", "embedding".
supports_vision boolean() | nil nil The model accepts image input.
supports_function_calling boolean() | nil nil The model supports tool / function calling.
supports_reasoning boolean() | nil nil The model supports extended-thinking / reasoning tokens.
supports_structured_output boolean() | nil nil The model supports JSON-mode or response_format structured output.
supports_audio_input boolean() | nil nil The model accepts audio input.
supports_audio_output boolean() | nil nil The model can generate audio output.
supports_prompt_caching boolean() | nil nil The model supports prompt caching.
tiers list(ModelTier) \[\] Context-tiered pricing overrides, sorted by ascending min_context_tokens. Empty when the model has flat pricing.

A model available from the API.

Field Type Default Description
id String.t() Model ID (e.g., "gpt-4o", "claude-3-5-sonnet").
object String.t() Always "model" from OpenAI-compatible APIs. Stored as a plain String so non-standard provider values do not break deserialization. Defaults to empty when a provider omits the field.
created integer() Unix timestamp of model creation (or release date). Defaults to 0 when a provider omits it — DeepSeek and some other OpenAI-compatible providers do not return created from /v1/models.
owned_by String.t() Organization or entity that owns the model. Defaults to empty when a provider omits the field.

Public, FFI-friendly snapshot of a single context-window pricing tier, projected from PricingTier.

Field Type Default Description
min_context_tokens integer() The tier applies when the prompt/context token count is at least this value.
input_cost_per_token float() Cost in USD per input (prompt) token within this tier.
output_cost_per_token float() Cost in USD per output (completion) token within this tier.
cache_read_input_token_cost float() | nil nil Cost in USD per cached input token within this tier.
cache_creation_input_token_cost float() | nil nil Cost in USD per cache-write token within this tier.
input_cost_per_audio_token float() | nil nil Cost in USD per input audio token within this tier.
output_cost_per_audio_token float() | nil nil Cost in USD per output audio token within this tier.
output_cost_per_reasoning_token float() | nil nil Cost in USD per reasoning output token within this tier.

Response listing available models.

Field Type Default Description
object String.t() Always "list" from OpenAI-compatible APIs. Stored as a plain String so non-standard provider values do not break deserialization. Defaults to empty when a provider omits the field.
data list(ModelObject) \[\] List of available models.

Boolean flags for each moderation category.

Field Type Default Description
sexual boolean() Sexual content.
hate boolean() Hate speech.
harassment boolean() Harassment.
self_harm boolean() Self-harm content.
sexual_minors boolean() Sexual content involving minors.
hate_threatening boolean() Hate speech that threatens violence.
violence_graphic boolean() Graphic violence.
self_harm_intent boolean() Intent to self-harm.
self_harm_instructions boolean() Instructions for self-harm.
harassment_threatening boolean() Harassment that threatens violence.
violence boolean() Non-graphic violence.

Confidence scores for each moderation category.

Field Type Default Description
sexual float() Sexual content score.
hate float() Hate speech score.
harassment float() Harassment score.
self_harm float() Self-harm content score.
sexual_minors float() Sexual content involving minors score.
hate_threatening float() Hate speech that threatens violence score.
violence_graphic float() Graphic violence score.
self_harm_intent float() Intent to self-harm score.
self_harm_instructions float() Instructions for self-harm score.
harassment_threatening float() Harassment that threatens violence score.
violence float() Non-graphic violence score.

Request to classify content for policy violations.

Field Type Default Description
input ModerationInput :single Text or texts to check.
model String.t() | nil nil Model ID (e.g., "text-moderation-latest"). Optional; API uses default if unset.

Response from the moderation endpoint.

Field Type Default Description
id String.t() Unique identifier for this moderation request.
model String.t() Model used for classification.
results list(ModerationResult) Results for each input string.

A single moderation classification result.

Field Type Default Description
flagged boolean() True if any category was flagged.
categories ModerationCategories Boolean flags for each moderation category.
category_scores ModerationCategoryScores Confidence scores for each category.

An image extracted from an OCR page.

Field Type Default Description
id String.t() Unique image identifier within the document.
image_base64 String.t() | nil /* serde(default) */ Base64-encoded image data (if include_image_base64 was true).

A single page of OCR output.

Field Type Default Description
index integer() Page index (0-based).
markdown String.t() Extracted page content as Markdown.
images list(OcrImage) | nil /* serde(default) */ Embedded images extracted from the page (if include_image_base64 was true).
dimensions PageDimensions | nil /* serde(default) */ Page dimensions in pixels, if available.

An OCR request.

Field Type Default Description
model String.t() The model/provider to use (e.g. "mistral/mistral-ocr-latest").
document OcrDocument :url The document to process (URL or base64).
pages list(integer()) | nil \[\] Specific pages to process (1-indexed). nil means all pages.
include_image_base64 boolean() | nil nil Whether to include base64-encoded images of each processed page.

An OCR response.

Field Type Default Description
pages list(OcrPage) Extracted pages in order.
model String.t() Model/provider used for OCR.
usage Usage | nil /* serde(default) */ Token usage, if reported by the provider.

Page dimensions in pixels.

Field Type Default Description
width integer() Width in pixels.
height integer() Height in pixels.

Breakdown of tokens used in the prompt portion of a request.

cached_tokens is included in Usage.prompt_tokens — it is not an additional charge on top of the prompt token count. When pricing supports a cache_read_input_token_cost, the cached portion is billed at the discounted rate and the remainder at the regular input rate.

Field Type Default Description
cached_tokens integer() Cached tokens present in the prompt. Defaults to 0 when absent.
audio_tokens integer() Audio input tokens present in the prompt. Defaults to 0 when absent.

Static capability flags for a provider.

Each flag indicates whether the provider’s models generally support that feature. For providers that aggregate many underlying models (e.g. Bedrock, OpenRouter, vLLM) the flags reflect the superset of available model capabilities — a flag being true means at least one model supports the feature, not every model.

All flags default to false so that newly added providers are safe.

Access via the crate-level capabilities function:

Field Type Default Description
vision boolean() The provider accepts image input in chat messages.
reasoning boolean() The provider supports extended-thinking / reasoning tokens.
structured_output boolean() The provider supports JSON-mode or response_format structured output.
function_calling boolean() The provider supports tool / function calling.
audio_in boolean() The provider accepts audio as input.
audio_out boolean() The provider can generate audio / TTS output.
video_in boolean() The provider accepts video as input.

Static configuration for a single provider entry in providers.json.

This struct deliberately does not include capability flags or streaming format, which are accessed via the capabilities function.

Field Type Default Description
name String.t() Provider identifier (matches the entry key in providers.json).
display_name String.t() | nil nil Human-readable provider name shown in UIs.
base_url String.t() | nil nil Base URL used as the default for this provider’s HTTP client.
auth AuthConfig | nil nil Authentication scheme metadata (auth type + env var holding the key).
endpoints list(String.t()) | nil nil Supported endpoint kinds (e.g. chat, embeddings).
model_prefixes list(String.t()) | nil nil Model-name prefixes claimed by this provider (e.g. \["gpt-", "o1-"\]).
param_mappings map() | nil nil Parameter key renaming for this provider. Each entry maps an OpenAI-spec field name (e.g. "max_completion_tokens") to the name this provider expects (e.g. "max_tokens"). Applied automatically by ConfigDrivenProvider.transform_request.

Configuration for per-model rate limits.

Field Type Default Description
rpm integer() | nil nil Maximum requests per window. nil means unlimited.
tpm integer() | nil nil Maximum tokens per window. nil means unlimited.
window integer() 60000ms Fixed window duration (defaults to 60 s).

Signature:

def default()

Example:

{:ok, result} = RateLimitConfig.default()

Returns: RateLimitConfig


Request to rerank documents by relevance to a query.

Field Type Default Description
model String.t() Model ID (e.g., "cohere/rerank-english-v3.0").
query String.t() The search query.
documents list(RerankDocument) \[\] Documents to rerank.
top_n integer() | nil nil Return only the top N results. Optional.
return_documents boolean() | nil nil Include the document content in results. Defaults to false.

Response from the rerank endpoint.

Field Type Default Description
id String.t() | nil nil Unique identifier for this rerank request.
results list(RerankResult) Reranked documents in order of relevance.
meta term() | nil /* serde(default) */ Optional metadata about the reranking operation.

A single reranked document with its relevance score.

Field Type Default Description
index integer() Original document index in the input list.
relevance_score float() Relevance score in \[0, 1\]. Higher indicates more relevant.
document RerankResultDocument | nil /* serde(default) */ Original document content (if return_documents was true).

The text content of a reranked document, returned when return_documents is true.

Field Type Default Description
text String.t() Document text.

Response from a structured response request.

Field Type Default Description
id String.t() Unique response ID.
object String.t() Object type (e.g., "response").
created_at integer() Unix timestamp of response creation.
model String.t() Model used to generate the response.
status String.t() Status (e.g., "succeeded", "failed").
output list(ResponseOutputItem) \[\] Output items from the response.
usage ResponseUsage | nil nil Token usage.
error term() | nil nil Error details (if status is “failed”).

A single output item from the response.

Field Type Default Description
item_type String.t() Output type (e.g., "text", "object", "error").
content term() Output content (flattened into the object).

A tool available for the response request.

Field Type Default Description
tool_type String.t() Tool type (e.g., “extractor”, “search”).
config term() Tool configuration (flattened into the object).

Token usage for a response.

Field Type Default Description
input_tokens integer() Input tokens used.
output_tokens integer() Output tokens used.
total_tokens integer() Total tokens used.

A search request.

Field Type Default Description
model String.t() The model/provider to use (e.g. "brave/web-search", "tavily/search").
query String.t() The search query string.
max_results integer() | nil nil Maximum number of results to return.
search_domain_filter list(String.t()) | nil \[\] Domain filter — restrict results to specific domains.
country String.t() | nil nil Country code for localized results (ISO 3166-1 alpha-2, e.g., "US", "FR").

A search response.

Field Type Default Description
results list(SearchResult) List of search results.
model String.t() Model/provider that performed the search.

An individual search result.

Field Type Default Description
title String.t() Result title.
url String.t() Result URL.
snippet String.t() Text snippet or excerpt from the page.
date String.t() | nil /* serde(default) */ Publication or last-updated date, if available.

The value broadcast from a singleflight leader to all followers.

The error value is shared so every follower receives the same upstream failure without cloning the underlying error.


Name of the specific function to invoke.

Field Type Default Description
name String.t() Function name.

Directive to call a specific tool.

Field Type Default Description
choice_type ToolType :function Tool type (always “function”).
function SpecificFunction The specific function to invoke.

A streaming choice with incremental delta.

Field Type Default Description
index integer() Index of this choice in the choices array.
delta StreamDelta Incremental update to the message (content, tool calls, etc.).
finish_reason FinishReason | nil nil Why the stream ended (present only in final chunk).

Incremental delta in a stream chunk.

Field Type Default Description
role String.t() | nil nil Role (typically present only in the first chunk).
content String.t() | nil nil Partial content chunk (e.g., a few words of the response).
tool_calls list(StreamToolCall) | nil \[\] Partial tool calls being streamed.
function_call StreamFunctionCall | nil nil Deprecated legacy function_call delta; retained for API compatibility.
refusal String.t() | nil nil Partial refusal message.
reasoning_content String.t() | nil nil Partial reasoning/thinking tokens (OpenAI-compatible extension used by DeepSeek R1, Qwen, etc.).

Partial function call details in a stream.

Field Type Default Description
name String.t() | nil nil Function name (typically in the first chunk).
arguments String.t() | nil nil Partial JSON arguments chunk.

Options for streaming responses.

Field Type Default Description
include_usage boolean() | nil nil If true, include token usage in the final stream chunk.

A streaming tool call being built incrementally.

Field Type Default Description
index integer() Index of this tool call in the tool_calls array.
id String.t() | nil nil Tool call ID (typically in the first chunk for this call).
call_type ToolType | nil nil Tool type (typically “function”).
function StreamFunctionCall | nil nil Partial function name and arguments.

System message guiding model behavior for the entire conversation.

Field Type Default Description
content UserContent :text Instructions or context that apply throughout the conversation. Accepts either a plain text string or an array of content parts, mirroring UserContent so that Message.system_with_parts works.
name String.t() | nil nil Optional name for the system message source.

A tool call the model wants to execute.

Field Type Default Description
id String.t() Unique ID for this call, used to reference in tool result messages.
call_type ToolType Tool type (always “function”).
function FunctionCall Function name and arguments.

Tool execution result returned to the model.

Field Type Default Description
content UserContent :text Result of the tool execution as plain text or an array of content parts (text, images, documents, audio), mirroring UserMessage.content. #\[serde(untagged)\] on UserContent means a bare JSON string still deserialises into Text, so tool results persisted before this field carried structured content continue to round-trip.
tool_call_id String.t() ID of the tool call this result responds to.
name String.t() | nil nil Optional tool/function name.

Response from a transcription request.

Field Type Default Description
text String.t() The transcribed text.
language String.t() | nil nil Detected language (ISO-639-1 code).
duration float() | nil nil Total audio duration in seconds.
segments list(TranscriptionSegment) | nil \[\] Detailed segment-level transcription (if response_format is “verbose_json”).

A segment of transcribed audio with timing information.

Field Type Default Description
id integer() Segment index (0-based).
start float() Start time in seconds.
end float() End time in seconds.
text String.t() Transcribed text for this segment.

Token-usage accounting returned by the provider on each completion / embedding call.

Field Type Default Description
prompt_tokens integer() Prompt tokens used. Defaults to 0 when absent (some providers omit this).
completion_tokens integer() Completion tokens used. Defaults to 0 when absent (e.g. embedding responses).
total_tokens integer() Total tokens used. Defaults to 0 when absent (some providers omit this).
prompt_tokens_details PromptTokensDetails | nil nil Breakdown of tokens used in the prompt, including cached tokens served at the provider’s discounted cache-read rate. Absent when the provider does not return prompt-token details.

User message in the conversation.

Field Type Default Description
content UserContent :text Message content as plain text or array of content parts (text, images, documents, audio).
name String.t() | nil nil Optional name for the user.

Configuration for polling a batch until terminal status.

All time values are in seconds as f64 so the struct bridges across FFI boundaries without requiring a Duration shim.

Field Type Default Description
initial_interval_secs float() 5 Initial interval between polls, in seconds.
max_interval_secs float() 60 Maximum interval between polls (backoff plateau), in seconds.
backoff_multiplier float() 1.5 Exponential backoff multiplier (e.g., 1.5 increases delay by 50% each poll).
timeout_secs float() | nil nil Optional timeout in seconds — polling fails if this duration is exceeded.

Signature:

def default()

Example:

{:ok, result} = WaitForBatchConfig.default()

Returns: WaitForBatchConfig


A chat message in a conversation.

Value Description
system System — Fields: 0: SystemMessage
user User — Fields: 0: UserMessage
assistant Assistant — Fields: 0: AssistantMessage
tool Tool — Fields: 0: ToolMessage
developer Developer — Fields: 0: DeveloperMessage
function Deprecated legacy function-role message; retained for API compatibility. — Fields: 0: FunctionMessage

User message content as either plain text or a list of multimodal parts.

Value Description
text Plain text content. — Fields: 0: String.t()
parts Array of content parts (text, images, documents, audio). — Fields: 0: list(ContentPart)

A single content part in a user message — text, image, document, or audio.

Value Description
text Plain text. — Fields: text: String.t()
image_url Image identified by URL (with optional detail level). — Fields: image_url: ImageUrl
document Document file (PDF, CSV, etc.) as base64 or URL. — Fields: document: DocumentContent
input_audio Audio input as base64. — Fields: input_audio: AudioContent

Image detail level controlling token cost and processing.

Value Description
low Low detail: scales image to 512x512, uses fewer tokens.
high High detail: processes up to 2x2 grid of tiles, higher token cost.
auto Auto: model chooses low or high based on image dimensions.

Content shape for assistant messages.

#[serde(untagged)] means providers returning a plain scalar string for the content field still deserialise correctly into AssistantContent.Text(_). Providers returning an array of typed parts (e.g. after an image-generation or audio-synthesis request) deserialise into AssistantContent.Parts(_).

Value Description
text Plain text response (the common case for text-only models). — Fields: 0: String.t()
parts Structured parts — text, refusals, output images, output audio. — Fields: 0: list(AssistantPart)

One part of a structured assistant response.

#[serde(tag = "type", rename_all = "snake_case")] matches OpenAI’s parts-spec discriminator ("type": "text", "type": "output_image", …).

Value Description
text A text segment of the response. — Fields: text: String.t()
refusal A refusal — the model declined to respond. — Fields: refusal: String.t()
output_image An image produced by the model (e.g. gpt-image-1, Gemini Imagen). — Fields: image_url: ImageUrl
output_audio Audio produced by the model (e.g. gpt-4o-audio-preview). — Fields: audio: AudioContent

The type discriminator for tool/tool-call objects.

Per the OpenAI spec this is always "function". Using an enum enforces that constraint at the type level and rejects any other value on deserialization.

Value Description
function Function

Tool usage mode or a specific tool to call.

Value Description
mode Predefined mode: auto, required, or none. — Fields: 0: ToolChoiceMode
specific Force a specific tool to be called. — Fields: 0: SpecificToolChoice

Tool choice mode.

Value Description
auto Model may or may not call tools; default behavior.
required Model must call at least one tool.
none Model must not call any tools.

Wire format for the chat completions response_format field.

  • OpenAI (and OpenAI-compatible providers): emitted verbatim as {"type": "json_schema", "json_schema": {...}} per the chat-completions spec.

  • Gemini / Vertex AI: translated to generationConfig.responseMimeType = "application/json" and generationConfig.responseSchema = <schema>. The name, description, and strict fields are dropped — Gemini’s structured-output API does not consume them.

  • Anthropic: no native JSON mode. A system instruction is prepended asking the model to respond with valid JSON. strict is advisory only; callers should still validate the returned JSON if the schema is load-bearing.

Value Description
text Plain text output (default).
json_object Output must be valid JSON object (no schema validation).
json_schema Output must conform to the specified JSON schema. — Fields: json_schema: JsonSchemaFormat

Stop sequence(s) that cause the model to stop generating.

Value Description
single Single stop sequence. — Fields: 0: String.t()
multiple Multiple stop sequences. — Fields: 0: list(String.t())

Output modality requested from the model.

Passed as modalities: ["text", "audio"] (OpenAI) or translated to generationConfig.responseModalities (Gemini / Vertex AI).

Value Description
text Text output (the default for all providers).
audio Audio / speech output.
image Image output (Gemini Imagen, gpt-image-1).

Why a choice stopped generating tokens.

Value Description
stop Stop
length Length
tool_calls Tool calls
content_filter Content filter
function_call Deprecated legacy finish reason; retained for API compatibility.
other Catch-all for unknown finish reasons returned by non-OpenAI providers. Note: this intentionally does not carry the original string (e.g. Other(String)). Using #\[serde(other)\] requires a unit variant, and switching to #\[serde(untagged)\] would change deserialization semantics for all variants. The original value can be recovered by inspecting the raw JSON if needed.

Controls how much reasoning effort the model should use.

Value Description
low Low
medium Medium
high High
minimal Minimal
max Max

The format in which the embedding vectors are returned.

Value Description
float 32-bit floating-point numbers (default).
base64 Base64-encoded string representation of the floats.

Text or texts to embed.

Value Description
single Single text string. — Fields: 0: String.t()
multiple Multiple text strings (batch embedding). — Fields: 0: list(String.t())

Input to the moderation endpoint — a single string or multiple strings.

Value Description
single Single text string. — Fields: 0: String.t()
multiple Multiple text strings (batch moderation). — Fields: 0: list(String.t())

A document to be reranked — either a plain string or an object with a text field.

Value Description
text Plain text document content. — Fields: 0: String.t()
object Document with explicit text field (may include metadata). — Fields: text: String.t()

Document input for OCR — either a URL or inline base64 data.

Value Description
url A publicly accessible document URL. — Fields: url: String.t()
base64 Inline base64-encoded document data. — Fields: data: String.t(), media_type: String.t()

Purpose of an uploaded file.

Value Description
assistants File for use with Assistants API.
batch File for batch processing.
fine_tune File for fine-tuning.
vision File for vision/image tasks.

Status of a batch job.

Value Description
validating Validating the input file.
failed Job failed.
in_progress Job is running.
finalizing Finalizing results.
completed Job completed successfully.
expired Job expired before completion.
cancelling Job is being cancelled.
cancelled Job has been cancelled.

How the API key is sent in the HTTP request.

Value Description
bearer Bearer token: Authorization: Bearer <key>
api_key Custom header: e.g., X-Api-Key: <key> — Fields: 0: String.t()
none No authentication required.

The streaming wire format a provider uses for its response stream.

Most providers use standard Server-Sent Events (SSE). AWS Bedrock uses a proprietary binary EventStream framing.

Deserialized from the streaming_format JSON field via serde.

Value Description
sse Standard Server-Sent Events (text/event-stream).
aws_event_stream AWS EventStream binary framing (application/vnd.amazon.eventstream).

Auth scheme used by a provider.

Value Description
bearer Standard Authorization: Bearer <key> header.
api_key x-api-key: <key> header (also handles "header" and "x-api-key" aliases).
none No authentication header required.
unknown Unrecognised auth scheme — falls back to bearer.

How budget limits are enforced.

Value Description
hard Reject requests that would exceed the budget with LiterLlmError.BudgetExceeded.
soft Allow requests through but emit a tracing.warn! when the budget is exceeded.

Storage backend for the response cache.

Value Description
memory In-memory LRU cache (default). No external dependencies.
open_dal OpenDAL-backed storage. Supports 40+ backends (S3, Redis, GCS, local FS, etc.). — Fields: scheme: String.t(), config: map()

Observable state of a circuit breaker.

Value Description
closed Requests flow through normally.
open All requests are rejected; the circuit is waiting for the backoff to elapse.
half_open One probe request is allowed through to test service health.

The result of a single health probe.

Value Description
healthy The probe succeeded; the upstream is reachable.
unhealthy The probe failed; the upstream may be down.

Result of a refresh_catalog call.

Value Description
disabled config.enabled was false; no network, filesystem, or overlay activity occurred.
from_cache The on-disk cache was fresh (age < ttl_seconds); the overlay was installed from the cached file without a network request.
fetched The catalog was fetched over the network, the cache file was (best-effort) refreshed, and the overlay was installed from the fetched catalog.

All errors that can occur when using liter-llm.

Variant Description
authentication status preserves the exact HTTP status code received (401 or 403).
rate_limited rate limited: {message}
bad_request status preserves the exact HTTP status code received (400, 405, 413, 422, …).
context_window_exceeded context window exceeded: {message}
content_policy content policy violation: {message}
not_found not found: {message}
server_error status preserves the exact HTTP status code received (500, or other 5xx not covered by ServiceUnavailable).
service_unavailable status preserves the exact HTTP status code received (502, 503, or 504).
timeout request timeout
streaming A catch-all for errors that occur during streaming response processing. This variant covers multiple sub-conditions including UTF-8 decoding failures, CRC/checksum mismatches (AWS EventStream), JSON parse errors in individual SSE chunks, and buffer overflow conditions. The message field contains a human-readable description of the specific failure.
endpoint_not_supported provider {provider} does not support {endpoint}
invalid_header invalid header {name:?}: {reason}
serialization serialization error: {0}
budget_exceeded budget exceeded: {message}
hook_rejected hook rejected: {message}
internal_error An internal logic error (e.g. unexpected Tower response variant). This should never surface in normal operation — if it does, it indicates a bug in the library.
outbound_forbidden An outbound request was blocked by the active OutboundPolicy. Returned when register_custom_provider is called with a base_url that violates the policy (e.g. a private-range IP under DenyPrivate), or when the per-connection DNS resolver detects a forbidden address at connect time.
idempotency_conflict A different request body was submitted for an existing Idempotency-Key. Per the OpenAI Idempotency-Key convention, once a key is used with a particular request body, subsequent requests using the same key must carry an identical body. A body mismatch is a hard error (not retryable). HTTP equivalent: 409 Conflict.
idempotency_in_flight The same Idempotency-Key is already in-flight (another request with the same key is currently being processed). The caller should wait briefly and retry. The response is not yet available, and this request has been short-circuited to avoid running the operation twice. HTTP equivalent: 409 Conflict (retryable after a brief delay).

Errors from refresh_catalog and install_catalog_overlay_from_str.

On every variant, the overlay registry is left untouched: a previously installed overlay (or the embedded catalog, if none was ever installed) remains active. This is the air-gap-safety contract — a failed refresh never degrades pricing/model-info availability.

Variant Description
disabled Runtime catalog refresh was not enabled. refresh_catalog itself never returns this — it returns Ok(RefreshOutcome.Disabled) instead — but the variant is part of the public error surface for callers that want to treat “disabled” as a hard error.
insecure_url source_url did not use the https scheme, or failed to parse as a URL at all. There is no host allowlist: the URL is user-configurable for self-hosted catalog mirrors, so only the scheme is enforced.
fetch The network fetch failed, timed out, or returned a non-success status.
parse The fetched or cached catalog JSON failed to parse.
cache A cache file read failed on an otherwise-fresh cache file. Cache write failures are best-effort and never surface as this error (see refresh_catalog).