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, usage : Usage | Nil = nil)
Source

Instance methods

cache_creation_tokens

DEPRECATED Use usage.cache_write + usage.cache_write_1h, the same for every provider, and #cost for what the call cost. Removed in arcana-ai 0.6.0.

Source
cache_creation_tokens=(cache_creation_tokens : Int32 | Nil)

DEPRECATED Set #usage. Removed in arcana-ai 0.6.0.

Source
cache_read_tokens

DEPRECATED Use usage.cache_read, the same for every provider, and #cost for what the call cost. Removed in arcana-ai 0.6.0.

Source
cache_read_tokens=(cache_read_tokens : Int32 | Nil)

DEPRECATED Set #usage. Removed in arcana-ai 0.6.0.

Source
completion_tokens

DEPRECATED Use usage.output (reasoning included), the same for every provider, and #cost for what the call cost. Removed in arcana-ai 0.6.0.

Source
completion_tokens=(completion_tokens : Int32 | Nil)

DEPRECATED Set #usage. Removed in arcana-ai 0.6.0.

Source
content
Source
content=(content : String | Nil)
Source
cost(at : Time = Time.utc, table : Pricing::Table = Pricing::Table.default) : Pricing::Cost | Pricing::Unpriced

What this call cost; see Pricing. at is when it was made.

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

DEPRECATED Use usage.prompt (the whole prompt) or usage.input (uncached input), the same for every provider, and #cost for what the call cost. Removed in arcana-ai 0.6.0.

Source
prompt_tokens=(prompt_tokens : Int32 | Nil)

DEPRECATED Set #usage. Removed in arcana-ai 0.6.0.

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

DEPRECATED Use usage.reasoning, the same for every provider, and #cost for what the call cost. Removed in arcana-ai 0.6.0.

Source
reasoning_tokens=(reasoning_tokens : Int32 | Nil)

DEPRECATED Set #usage. Removed in arcana-ai 0.6.0.

Source
retries

Retries the call needed (rate limits, server or network errors) and the time spent waiting between tries. See RetryPolicy.

Source
retries=(retries : Int32)

Retries the call needed (rate limits, server or network errors) and the time spent waiting between tries. See RetryPolicy.

Source
retry_wait
Source
retry_wait=(retry_wait : Time::Span)
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

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.

Source
thinking_content=(thinking_content : String | Nil)

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.

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
usage

What the call used, in the same billing categories for every provider (see Usage); nil when the provider reported none. Pricing prices it.

Source
usage=(usage : Usage | Nil)

What the call used, in the same billing categories for every provider (see Usage); nil when the provider reported none. Pricing prices it.

Source
with_retries(stats : RetryStats) : self

This response with the retry record of the call that produced it.

Source