pub struct Response {
pub content: String,
pub structured_response: Option<Value>,
pub tool_calls: Vec<ToolCall>,
pub usage: Option<TokenUsage>,
pub model: Option<String>,
pub raw_body: Option<String>,
}Expand description
Response from an LLM operation.
Contains the model’s output along with metadata about the request.
Check tool_calls first - if non-empty, the model wants to call functions
rather than provide a final response.
§Basic Response
use multi_llm::Response;
// Standard text response
println!("Response: {}", response.content);
// Check token usage
if let Some(usage) = &response.usage {
println!("Used {} tokens", usage.total_tokens);
}§Tool Calling Response
use multi_llm::Response;
// Check if model wants to call tools
if !response.tool_calls.is_empty() {
for call in &response.tool_calls {
println!("Tool: {} with args: {}", call.name, call.arguments);
// Execute tool and return result...
}
}§Structured Response
use multi_llm::Response;
// When using execute_structured_llm
if let Some(json) = &response.structured_response {
let name = json["name"].as_str().unwrap_or("unknown");
println!("Extracted name: {}", name);
}§Note on Trait Implementations
This type intentionally omits Serialize, Deserialize, and PartialEq:
structured_responsecontains arbitraryserde_json::Valuethat may not round-trip cleanlyraw_bodyis provider-specific debug data not meant for serialization- Equality comparison on JSON values can be surprising (object key ordering, number precision)
If you need to serialize responses, extract the specific fields you need.
Fields§
§content: StringPrimary text content of the response.
For standard requests, this is the model’s natural language output. May be empty if the model only returned tool calls.
structured_response: Option<Value>Parsed JSON when using structured output.
Populated when using LlmProvider::execute_structured_llm() with a schema.
Contains the parsed JSON that (should) match the requested schema.
tool_calls: Vec<ToolCall>Tool calls the model wants to execute.
If non-empty, the model is requesting function calls rather than providing a final answer. Execute the tools and continue the conversation.
usage: Option<TokenUsage>Token usage statistics for this request.
May be None if the provider doesn’t report usage or if the request failed.
model: Option<String>The model that generated this response.
Useful when the provider might use different models than requested (e.g., fallback models or model aliases).
raw_body: Option<String>Raw response body for debugging.
Contains the unprocessed JSON response from the provider API. Useful for debugging parsing issues or accessing provider-specific fields.