Class: Fal::PriceEstimate

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, client: Fal.client) ⇒ PriceEstimate

Returns a new instance of PriceEstimate.

Parameters:

  • attributes (Hash)
  • client (Fal::Client) (defaults to: Fal.client)


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

#currencyString (readonly)

Returns:

  • (String)


41
42
43
# File 'lib/fal/price_estimate.rb', line 41

def currency
  @currency
end

#estimate_typeString (readonly)

Returns:

  • (String)


37
38
39
# File 'lib/fal/price_estimate.rb', line 37

def estimate_type
  @estimate_type
end

#total_costFloat (readonly)

Returns:

  • (Float)


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

Parameters:

Returns:



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