class Turbopuffer::Client

def initialize(

Parameters:
  • max_retry_delay (Float) --
  • initial_retry_delay (Float) --
  • timeout (Float) --
  • max_retries (Integer) -- Max number of retries to attempt after a failed retryable request.
  • base_url (String, nil) -- Override the default base URL for the API, e.g.,
  • default_namespace (String, nil) --
  • region (String, nil) -- The turbopuffer region to use. Defaults to `ENV["TURBOPUFFER_REGION"]`
  • api_key (String, nil) -- API key used for authentication Defaults to `ENV["TURBOPUFFER_API_KEY"]`
def initialize(
  api_key: ENV["TURBOPUFFER_API_KEY"],
  region: ENV["TURBOPUFFER_REGION"],
  default_namespace: nil,
  base_url: ENV["TURBOPUFFER_BASE_URL"],
  max_retries: self.class::DEFAULT_MAX_RETRIES,
  timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
  initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
  max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
)
  base_url ||= "https://{region}.turbopuffer.com"
  if api_key.nil?
    raise ArgumentError.new("api_key is required, and can be set via environ: \"TURBOPUFFER_API_KEY\"")
  end
  if base_url.include?("{region}")
    if region.nil?
      raise ArgumentError.new("region is required when base_url contains {region} placeholder: #{base_url}")
    end
    base_url = base_url.gsub("{region}", region)
  elsif !region.nil?
    raise ArgumentError.new("region is set, but would be ignored (baseUrl does not contain {region} placeholder: #{base_url})")
  end
  @default_namespace = default_namespace&.to_s
  @api_key = api_key.to_s
  @region = region&.to_s
  super(
    base_url: base_url,
    timeout: timeout,
    max_retries: max_retries,
    initial_retry_delay: initial_retry_delay,
    max_retry_delay: max_retry_delay
  )
end