Module: RubyLLM::Protocols::Responses::TokenCounting

Included in:
RubyLLM::Providers::OpenAI::Responses
Defined in:
lib/ruby_llm/protocols/responses/token_counting.rb

Overview

The Responses input-token counting endpoint.

Constant Summary collapse

COUNT_TOKENS_KEYS =
%i[model input instructions tools tool_choice parallel_tool_calls reasoning text].freeze

Class Method Summary collapse

Class Method Details

.count_tokens_urlObject



12
13
14
# File 'lib/ruby_llm/protocols/responses/token_counting.rb', line 12

def count_tokens_url
  "#{completion_url}/input_tokens"
end

.parse_count_tokens_response(response) ⇒ Object



20
21
22
# File 'lib/ruby_llm/protocols/responses/token_counting.rb', line 20

def parse_count_tokens_response(response)
  response.body.fetch('input_tokens')
end

.render_count_tokens_payload(messages, model:, **options) ⇒ Object



16
17
18
# File 'lib/ruby_llm/protocols/responses/token_counting.rb', line 16

def render_count_tokens_payload(messages, model:, **options)
  render_payload(messages, model: model, temperature: nil, **options).slice(*COUNT_TOKENS_KEYS)
end