struct
OpenRouter::Message
- OpenRouter::Message
- Struct
- Value
- Object
Included Modules
- JSON::Serializable
Defined in:
openrouter/types/message.crConstructors
-
.new(role : Role, content : Content | Nil, name : String | Nil = nil, tool_call_id : String | Nil = nil, tool_calls : Array(ToolCall) | Nil = nil, reasoning : String | Nil = nil, reasoning_details : JSON::Any | Nil = nil, images : Array(JSON::Any) | Nil = nil)
Initialize for user/assistant/system messages
-
.new(pull : JSON::PullParser)
Override JSON::Serializable's generated self.new(pull) so that response deserialization routes through our custom from_json(JSON::Any), which correctly handles the nested image_url/video_url format from the API.
-
.new(tool_call : ToolCall)
Create a tool result message.
Class Method Summary
Instance Method Summary
- #add_tool_call(tool_call : ToolCall)
- #add_tool_call(name : String, arguments : Array(ToolCallArgument) = [] of ToolCallArgument, tool_call_type : String = "function", tool_call_id : String | Nil = nil)
- #content : Content | Nil
- #content=(content : Content | Nil)
-
#content_string : String
Get the content, or in case of a multi-modal message, the content of the first part.
-
#image_urls : Array(String)
Returns image URLs from the message — either from a separate
#imagesfield (some models) or fromimage_urlcontent parts (others). -
#images : Array(JSON::Any) | Nil
Generated images returned by image generation models.
-
#images=(images : Array(JSON::Any) | Nil)
Generated images returned by image generation models.
- #length : Int32
-
#multi_modal? : Bool
Check if content is an Array
- #name : String | Nil
- #name=(name : String | Nil)
-
#reasoning : String | Nil
Reasoning tokens - visible reasoning trace from the model
-
#reasoning=(reasoning : String | Nil)
Reasoning tokens - visible reasoning trace from the model
-
#reasoning_details : JSON::Any | Nil
Reasoning details for preserving reasoning blocks (used in tool calling)
-
#reasoning_details=(reasoning_details : JSON::Any | Nil)
Reasoning details for preserving reasoning blocks (used in tool calling)
-
#role : Role | Nil
Common fields
-
#role=(role : Role | Nil)
Common fields
-
#to_json(json : JSON::Builder)
Custom serialization for complex multi-modal content and tool calls
-
#tool_call_id : String | Nil
Optional fields for specific roles
-
#tool_call_id=(tool_call_id : String | Nil)
Optional fields for specific roles
- #tool_calls : Array(ToolCall) | Nil
- #tool_calls=(tool_calls : Array(ToolCall) | Nil)
Constructor Detail
Initialize for user/assistant/system messages
Override JSON::Serializable's generated self.new(pull) so that response deserialization routes through our custom from_json(JSON::Any), which correctly handles the nested image_url/video_url format from the API.
Create a tool result message.
Role will be Role::Tool @name will be set to tool_call.name @tool_call_id will be set to tool_call.id @content will be set to serializd string of tool_call.arguments.to_json()
Class Method Detail
Instance Method Detail
Get the content, or in case of a multi-modal message, the content of the first part.
Returns image URLs from the message — either from a separate #images
field (some models) or from image_url content parts (others).
Generated images returned by image generation models.
Each entry is an object, typically {"url": "data:image/png;base64,..."}.
Generated images returned by image generation models.
Each entry is an object, typically {"url": "data:image/png;base64,..."}.
Reasoning tokens - visible reasoning trace from the model
Reasoning details for preserving reasoning blocks (used in tool calling)
Reasoning details for preserving reasoning blocks (used in tool calling)
Custom serialization for complex multi-modal content and tool calls