Skip to main content

Module request

Module request 

Source
Expand description

Completion requests, normalized responses, and provider model contracts.

use rig_core::completion::CompletionRequest;

let request = CompletionRequest::new("Who are you?")
    .preamble("You are a concise assistant.")
    .temperature(0.5);
assert_eq!(request.temperature, Some(0.5));

Structs§

CompletionRequest
A completion request to any provider’s model.
CompletionResponse
Assistant content and normalized completion metadata. The choice may be empty, including for truncated or filtered turns. Provider-specific data is available through Self::raw without retaining a concrete model type.
ContextUse
The context a conversation’s next request sends, against the model’s window.
Cost
What one or more turns cost, in USD. total is what was charged, or when Self::is_complete is false, a lower bound of it.
Document
A document sent with a request as context, rendered before the chat history.
ProviderCapabilities
Model capabilities used by runtimes when preparing requests. Defaults are conservative; construct through Self::new and setters.
ProviderToolDefinition
Provider-native tool definition.
ResponseIdentity
Distinct response and transport identifiers for one model call. Unreported identifiers remain None.
ToolAnnotations
What calling a tool does to the world, as the Model Context Protocol’s tool annotations state it, and spelled as they are on its wire (readOnlyHint, …), so an MCP tool’s annotations read straight into one. Each is a hint a tool’s author gives: a host’s policies read them (approval, plan mode, which calls run side by side), never trusting a tool it does not trust for them. A hint left unset takes the protocol’s default, which the accessors apply: not read-only, destructive, not idempotent, open world.
ToolDefinition
A tool the model may call: its name, description and argument schema, sent to the model, and what the tool does to the world (ToolAnnotations), which stays with the host.
Usage
The token usage a provider reported for one completion.
UsageTotals
Many calls’ Usage summed for a running account: the token counters, the known cost, and how many calls the sum holds and how many of them were not fully priced.

Enums§

CachePoint
A point in a CompletionRequest that ends a stable prefix, for CompletionRequest::cache_points. Prefixes run in the order a request is sent: tools, then the system prompt, then the messages.
FinishReason
Normalized generation ending. Unmapped provider values remain in Self::Other. Failure statuses may accompany parseable output; callers must decide whether such output is usable rather than treating every response as successful.

Functions§

tokens_label
A token count in at most four characters plus a unit: 999, 1.2k, 45k, 1.2M.