Class: Fal::PriceEstimate
- Inherits:
-
Object
- Object
- Fal::PriceEstimate
- Defined in:
- lib/fal/price_estimate.rb
Overview
Represents a cost estimate response from the Platform API. Computes estimates via POST /models/pricing/estimate.
Defined Under Namespace
Modules: EstimateType Classes: Endpoint
Constant Summary collapse
- ESTIMATE_PATH =
"/models/pricing/estimate"
Instance Attribute Summary collapse
- #currency ⇒ String readonly
- #estimate_type ⇒ String readonly
- #total_cost ⇒ Float readonly
Class Method Summary collapse
-
.create(estimate_type:, endpoints:, client: Fal.client) ⇒ Fal::PriceEstimate
Create a new cost estimate.
Instance Method Summary collapse
-
#initialize(attributes, client: Fal.client) ⇒ PriceEstimate
constructor
A new instance of PriceEstimate.
Constructor Details
#initialize(attributes, client: Fal.client) ⇒ PriceEstimate
Returns a new instance of PriceEstimate.
45 46 47 48 |
# File 'lib/fal/price_estimate.rb', line 45 def initialize(attributes, client: Fal.client) @client = client reset_attributes(attributes) end |
Instance Attribute Details
#currency ⇒ String (readonly)
41 42 43 |
# File 'lib/fal/price_estimate.rb', line 41 def currency @currency end |
#estimate_type ⇒ String (readonly)
37 38 39 |
# File 'lib/fal/price_estimate.rb', line 37 def estimate_type @estimate_type end |
#total_cost ⇒ Float (readonly)
39 40 41 |
# File 'lib/fal/price_estimate.rb', line 39 def total_cost @total_cost end |
Class Method Details
.create(estimate_type:, endpoints:, client: Fal.client) ⇒ Fal::PriceEstimate
Create a new cost estimate. Corresponds to POST api.fal.ai/v1/models/pricing/estimate
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fal/price_estimate.rb', line 57 def create(estimate_type:, endpoints:, client: Fal.client) endpoint_map = {} Array(endpoints).each do |ep| endpoint = ep.is_a?(Endpoint) ? ep : Endpoint.new(**ep) quantity = endpoint.unit_quantity || endpoint.call_quantity if estimate_type == EstimateType::UNIT_PRICE # Accept either unit_quantity or call_quantity (treated as units) for convenience. endpoint_map[endpoint.endpoint_id] = { "unit_quantity" => quantity } else endpoint_map[endpoint.endpoint_id] = { "call_quantity" => quantity } end end payload = { estimate_type: estimate_type, endpoints: endpoint_map } attributes = client.post_api(ESTIMATE_PATH, payload) new(attributes, client: client) end |