mod response#
- module response#
Normalized LLM response types produced by response codecs.
This module defines
AnnotatedLlmResponseand its supporting types for structured, API-agnostic access to LLM response data.Enums
- enum ApiSpecificResponse#
API-specific response data that cannot be normalized across providers.
Each variant captures fields unique to a particular LLM API, stored via internal tagging on the
"api"key.- OpenAIChat#
OpenAI Chat Completions-specific fields.
- system_fingerprint: Option<String>#
System fingerprint for reproducibility.
- service_tier: Option<String>#
Processing tier used (e.g., “default”).
- OpenAIResponses#
OpenAI Responses API-specific fields.
- status: Option<String>#
Response status (e.g., “completed”, “incomplete”).
- enum FinishReason#
Normalized reason why the model stopped generating.
Maps from provider-specific stop reasons:
Complete: OpenAI Chat
"stop", Anthropic"end_turn", Responses"completed"Length: OpenAI Chat
"length", Anthropic"max_tokens", Responses incomplete+max_output_tokensToolUse: OpenAI Chat
"tool_calls", Anthropic"tool_use"ContentFilter: OpenAI Chat
"content_filter", Responses incomplete+content_filterUnknown: Forward-compatible catch-all for unrecognized reasons
- Complete#
Model naturally completed its response.
- Length#
Maximum token limit reached.
- ToolUse#
Model requested a tool call.
- ContentFilter#
Content was filtered by safety systems.
- Unknown(String)#
Unknown or forward-compatible reason.
Implementations
- impl FinishReason#
Functions
- fn is_complete(&self) -> bool#
Returns
trueif the model naturally completed its response.Only the
FinishReason::Completevariant returnstrue.
Structs and Unions
- struct AnnotatedLlmResponse#
Structured view of an LLM response, produced by a response codec from raw JSON API output.
The
extrafield captures any top-level keys not modeled by the known fields, ensuring lossless round-trip through serde.- id: Option<String>#
Response ID from the API (e.g., “chatcmpl-abc123”, “resp_abc123”, “msg_abc123”).
- model: Option<String>#
The model that actually served the request (may differ from requested model).
- message: Option<MessageContent>#
The assistant’s response content, reusing
MessageContentfrom request types.
- tool_calls: Option<Vec<ResponseToolCall>>#
Tool calls requested by the model, normalized across APIs.
Uses
ResponseToolCall(arguments asJson) NOT the request-sideToolCall(arguments asString).
- finish_reason: Option<FinishReason>#
Why generation stopped, normalized across APIs.
- api_specific: Option<ApiSpecificResponse>#
API-specific response data that cannot be normalized across providers.
- extra: serde_json::Map<String, Json>#
Catch-all for unmodeled top-level fields, ensuring lossless round-trip.
Implementations
- impl AnnotatedLlmResponse#
Functions
- fn has_tool_calls(&self) -> bool#
Check if the response contains any tool calls.
Returns
trueiftool_callsisSomewith at least one element.
- fn response_text(&self) -> Option<&str>#
Extract the text content of the response message.
For
MessageContent::Text, returns the string directly. ForMessageContent::Parts, returns the text of the firstsuper::request::ContentPart::Textpart. ReturnsNoneifmessageisNone.
- struct ResponseToolCall#
A tool call requested by the model in its response.
Unlike the request-side
ToolCall(which stores arguments as a JSON string per OpenAI convention), response tool calls store arguments as parsedJson. Codecs parse OpenAI’s string arguments during decode; Anthropic’sinputis already parsed JSON.- id: String#
Unique identifier for this tool call.
- name: String#
The function/tool name.
- struct Usage#
Token usage statistics from an LLM API response.
All fields are
Option<u64>because not every provider supplies every field. For example, cache token counts are only available from providers that support prompt caching.- prompt_tokens: Option<u64>#
Tokens consumed by the prompt/input.
- completion_tokens: Option<u64>#
Tokens generated in the completion/output.
- total_tokens: Option<u64>#
Total tokens (prompt + completion).
- cache_read_tokens: Option<u64>#
Tokens served from prompt cache (read).
- cache_write_tokens: Option<u64>#
Tokens written to prompt cache.