Class: Kie::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kie/client.rb

Overview

HTTP client for Kie.ai API

Constant Summary collapse

BASE_URL =
"https://api.kie.ai"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil) ⇒ Client

Returns a new instance of Client.

Raises:



12
13
14
15
16
17
18
# File 'lib/kie/client.rb', line 12

def initialize(api_key: nil)
  @api_key = api_key || ENV.fetch("KIE_API_KEY", nil)

  return unless @api_key.nil? || @api_key.empty?

  raise ConfigurationError, "API key is required. Pass it as an argument or set KIE_API_KEY environment variable."
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



10
11
12
# File 'lib/kie/client.rb', line 10

def api_key
  @api_key
end

Instance Method Details

#connectionObject



20
21
22
23
24
25
26
# File 'lib/kie/client.rb', line 20

def connection
  @connection ||= Faraday.new(url: BASE_URL) do |conn|
    conn.headers["Authorization"] = "Bearer #{api_key}"
    conn.headers["Content-Type"] = "application/json"
    conn.use Middleware::RaiseError
  end
end

#generalObject



28
29
30
# File 'lib/kie/client.rb', line 28

def general
  @general ||= GeneralEngine.new(client: self)
end

#sunoObject



32
33
34
# File 'lib/kie/client.rb', line 32

def suno
  @suno ||= SunoEngine.new(client: self)
end