Skip to main content

Module completion

Module completion 

Source
Expand description

Provider-agnostic completion and chat abstractions.

This module contains the low-level request and response types used by provider implementations, plus the high-level traits most callers use through Agent:

  • Prompt sends one user prompt and returns assistant text.
  • Chat sends a prompt with existing history and returns assistant text.
  • TypedPrompt requests structured output and deserializes it into a Rust type.
  • Completion exposes a request builder for call-site overrides.
  • CompletionModel is the provider-facing trait implemented by completion models.

CompletionRequest is Rig’s canonical request representation. Provider modules translate it into provider-specific request bodies and convert responses back into CompletionResponse.

§Example

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

let client = openai::Client::from_env()?;
let agent = client
    .agent(openai::GPT_5_2)
    .preamble("Answer concisely.")
    .build();

let answer = agent.prompt("What is Rig?").await?;
println!("{answer}");

Modules§

message
request
Completion request, response, and provider trait definitions.

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 that contains the high-level completion choice and the raw response. The completion choice contains one or more assistant content.
Document
ProviderToolDefinition
Provider-native tool definition.
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§

AssistantContent
Describes responses from a provider which is either text or a tool call.
CompletionError
Message
A provider-agnostic chat message.
MessageError
Error type to represent issues with converting messages to and from specific provider messages.
PromptError
Prompt errors
StructuredOutputError
Errors that can occur when using typed structured output via TypedPrompt::prompt_typed.

Traits§

Chat
Trait defining a high-level LLM chat interface (i.e.: prompt and chat history in, response out).
Completion
Trait defining a low-level LLM completion interface
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.
GetTokenUsage
A trait for grabbing the token usage of a completion response.
Prompt
Trait defining a high-level LLM simple prompt interface (i.e.: prompt in, response out).
TypedPrompt
Trait defining a high-level typed prompt interface for structured output.