Skip to main content

Module request

Module request 

Source
Expand description

Completion request, response, and provider trait definitions.

Provider integrations implement CompletionModel and translate CompletionRequest into their native HTTP request format.

§Low-level request example

use rig_core::{
    client::{CompletionClient, ProviderClient},
    completion::{AssistantContent, CompletionModel},
    providers::openai,
};

let client = openai::Client::from_env()?;
let model = client.completion_model(openai::GPT_5_2);

let request = model
    .completion_request("Who are you?")
    .preamble("You are a concise assistant.".to_string())
    .temperature(0.5)
    .build();

let response = model.completion(request).await?;
for item in response.choice {
    if let AssistantContent::Text(text) = item {
        println!("{}", text.text);
    }
}

Structs§

CompletionRequest
Struct representing a general completion request that can be sent to a completion model provider.
CompletionRequestBuilder
Builder struct for constructing a completion request.
CompletionResponse
General completion response struct: the completion choice plus normalized response metadata. The completion choice contains one or more assistant content items.
Document
ProviderCapabilities
Provider behavior that affects how runtimes prepare completion requests.
ProviderToolDefinition
Provider-native tool definition.
ResponseIdentity
Response identity metadata for one completed model call: which provider objects this exact attempt produced. The three axes stay distinct — message-scoped, response-scoped, and transport — and every field is None when the provider did not report it: a documented outcome, never an error.
ToolDefinition
Usage
Struct representing the token usage for a completion request. If tokens used are 0, then the provider failed to supply token usage metrics.

Enums§

CompletionError
Errors returned by completion models.
FinishReason
Why the model stopped generating, normalized across providers.

Traits§

CompletionModel
Trait defining a completion model that can be used to generate completion responses. This trait is meant to be implemented by the user to define a custom completion model, either from a third party provider (e.g.: OpenAI) or a local model.
NormalizeCompletionResponse
Convert a provider’s own completion payload into the normalized CompletionResponse.