struct

Arcana::AI::Chat::Response

Inherits Struct < Value < Object

Constructors

from_openai_json(raw : String, provider : String = "openai") : self

Parse from an OpenAI-compatible JSON response body.

Source
new(content : String | Nil = nil, tool_calls : Array(ToolCall) = [] of ToolCall, finish_reason : String | Nil = nil, model : String = "", provider : String = "", raw_request : String = "", raw_json : String = "", prompt_tokens : Int32 | Nil = nil, completion_tokens : Int32 | Nil = nil, cache_read_tokens : Int32 | Nil = nil, cache_creation_tokens : Int32 | Nil = nil, thinking_content : String | Nil = nil, reasoning_tokens : Int32 | Nil = nil, server_tool_results : Array(JSON::Any) = [] of JSON::Any)
Source

Instance methods

cache_creation_tokens
Source
cache_creation_tokens=(cache_creation_tokens : Int32 | Nil)
Source
cache_read_tokens

Anthropic prompt caching tokens.

Source
cache_read_tokens=(cache_read_tokens : Int32 | Nil)

Anthropic prompt caching tokens.

Source
completion_tokens
Source
completion_tokens=(completion_tokens : Int32 | Nil)
Source
content
Source
content=(content : String | Nil)
Source
finish_reason
Source
finish_reason=(finish_reason : String | Nil)
Source
has_tool_calls?

Did the model return any tool calls?

Source
model
Source
model=(model : String)
Source
prompt_tokens

Token usage from the API response.

Source
prompt_tokens=(prompt_tokens : Int32 | Nil)

Token usage from the API response.

Source
provider
Source
provider=(provider : String)
Source
raw_json
Source
raw_json=(raw_json : String)
Source
raw_request
Source
raw_request=(raw_request : String)
Source
reasoning_tokens
Source
reasoning_tokens=(reasoning_tokens : Int32 | Nil)
Source
server_tool_results

Server-side tool results (e.g. web_search results).

Source
server_tool_results=(server_tool_results : Array(JSON::Any))

Server-side tool results (e.g. web_search results).

Source
thinking_content

Chain-of-thought / reasoning fields, when the model supports them.

thinking_content — the raw reasoning text if the provider surfaces it (Anthropic extended thinking, Gemini with includeThoughts). OpenAI o-series never surfaces the reasoning itself, so this stays nil for OpenAI even when reasoning ran.

reasoning_tokens — the token count the model spent on reasoning, when reported (OpenAI's completion_tokens_details.reasoning_tokens, Anthropic's cached thinking budget). Useful for cost tracking.

Source
thinking_content=(thinking_content : String | Nil)

Chain-of-thought / reasoning fields, when the model supports them.

thinking_content — the raw reasoning text if the provider surfaces it (Anthropic extended thinking, Gemini with includeThoughts). OpenAI o-series never surfaces the reasoning itself, so this stays nil for OpenAI even when reasoning ran.

reasoning_tokens — the token count the model spent on reasoning, when reported (OpenAI's completion_tokens_details.reasoning_tokens, Anthropic's cached thinking budget). Useful for cost tracking.

Source
tool_call(name : String) : ToolCall | Nil

Find the first tool call matching a given function name.

Source
tool_calls
Source
tool_calls=(tool_calls : Array(ToolCall))
Source