Class: Payloop::Client
- Inherits:
-
Object
- Object
- Payloop::Client
- Defined in:
- lib/payloop/client.rb
Overview
Main Payloop client for tracking AI costs
Instance Attribute Summary collapse
-
#collector ⇒ Object
readonly
Returns the value of attribute collector.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#sentinel ⇒ Object
readonly
Returns the value of attribute sentinel.
Instance Method Summary collapse
-
#anthropic ⇒ Object
Anthropic provider wrapper.
-
#attribution(parent_id:, parent_name: nil, subsidiary_id: nil, subsidiary_name: nil) ⇒ Object
Set attribution for cost tracking.
-
#geminiai ⇒ Object
Google GenAI provider wrapper (Tied to gemini-ai Gem version 4.3.0) Google doesn’t have an official Ruby library, so this is seems to be the most popular unofficial one.
-
#google ⇒ Object
Google GenAI provider wrapper (Tied to google-genai Gem) This is a port of the official Python library, but it does not support system prompts which is used for sentinel.
-
#groq ⇒ Object
Groq provider wrapper (groq gem, drnic/groq-ruby) Groq hosts third-party models (Meta Llama, OpenAI gpt-oss, Qwen, etc.).
-
#initialize(api_key: nil, collector_url: nil, api_url: nil, timeout: nil) ⇒ Client
constructor
A new instance of Client.
-
#new_transaction ⇒ Object
Start a new transaction.
-
#openai ⇒ Object
OpenAI provider wrapper.
-
#ruby_llm ⇒ Object
RubyLLM provider wrapper (ruby_llm gem) Supports any provider available via RubyLLM (Anthropic, OpenAI, Google, etc.).
-
#shutdown ⇒ Object
Gracefully shutdown the client.
-
#workflows ⇒ Object
Get workflows API client.
Constructor Details
#initialize(api_key: nil, collector_url: nil, api_url: nil, timeout: nil) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/payloop/client.rb', line 10 def initialize(api_key: nil, collector_url: nil, api_url: nil, timeout: nil) api_key ||= ENV.fetch("PAYLOOP_API_KEY", nil) raise MissingAPIKeyError if api_key.nil? || api_key.empty? @config = Config.new( api_key: api_key, collector_url: collector_url, api_url: api_url, timeout: timeout ) @collector = Collector.new(@config) @sentinel = Sentinel.new(@config) end |
Instance Attribute Details
#collector ⇒ Object (readonly)
Returns the value of attribute collector.
8 9 10 |
# File 'lib/payloop/client.rb', line 8 def collector @collector end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/payloop/client.rb', line 8 def config @config end |
#sentinel ⇒ Object (readonly)
Returns the value of attribute sentinel.
8 9 10 |
# File 'lib/payloop/client.rb', line 8 def sentinel @sentinel end |
Instance Method Details
#anthropic ⇒ Object
Anthropic provider wrapper
30 31 32 |
# File 'lib/payloop/client.rb', line 30 def anthropic @anthropic ||= Wrappers::Anthropic.new(@config, @collector, @sentinel) end |
#attribution(parent_id:, parent_name: nil, subsidiary_id: nil, subsidiary_name: nil) ⇒ Object
Set attribution for cost tracking
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/payloop/client.rb', line 63 def attribution(parent_id:, parent_name: nil, subsidiary_id: nil, subsidiary_name: nil) attr = Attribution.new( parent_id: parent_id, parent_name: parent_name, subsidiary_id: subsidiary_id, subsidiary_name: subsidiary_name ) @config.attribution = attr self end |
#geminiai ⇒ Object
Google GenAI provider wrapper (Tied to gemini-ai Gem version 4.3.0) Google doesn’t have an official Ruby library, so this is seems to be the most popular unofficial one.
45 46 47 |
# File 'lib/payloop/client.rb', line 45 def geminiai @geminiai ||= Wrappers::GeminiAI.new(@config, @collector, @sentinel) end |
#google ⇒ Object
Google GenAI provider wrapper (Tied to google-genai Gem) This is a port of the official Python library, but it does not support system prompts which is used for sentinel. This still works for non-sentinel use cases.
38 39 40 |
# File 'lib/payloop/client.rb', line 38 def google @google ||= Wrappers::Google.new(@config, @collector, @sentinel) end |
#groq ⇒ Object
Groq provider wrapper (groq gem, drnic/groq-ruby) Groq hosts third-party models (Meta Llama, OpenAI gpt-oss, Qwen, etc.). Telemetry sets provider=“groq” and title from the model-ID prefix.
58 59 60 |
# File 'lib/payloop/client.rb', line 58 def groq @groq ||= Wrappers::Groq.new(@config, @collector, @sentinel) end |
#new_transaction ⇒ Object
Start a new transaction
76 77 78 79 |
# File 'lib/payloop/client.rb', line 76 def new_transaction @config.new_transaction self end |
#openai ⇒ Object
OpenAI provider wrapper
25 26 27 |
# File 'lib/payloop/client.rb', line 25 def openai @openai ||= Wrappers::OpenAI.new(@config, @collector, @sentinel) end |
#ruby_llm ⇒ Object
RubyLLM provider wrapper (ruby_llm gem) Supports any provider available via RubyLLM (Anthropic, OpenAI, Google, etc.)
51 52 53 |
# File 'lib/payloop/client.rb', line 51 def ruby_llm @ruby_llm ||= Wrappers::RubyLLM.new(@config, @collector, @sentinel) end |
#shutdown ⇒ Object
Gracefully shutdown the client
91 92 93 |
# File 'lib/payloop/client.rb', line 91 def shutdown @collector.shutdown end |