Class: Reapi::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil) ⇒ Client

Returns a new instance of Client.



27
28
29
30
31
32
33
# File 'lib/reapi.rb', line 27

def initialize(api_key: nil)
  @api_key = api_key || ENV["REAPI_API_KEY"]
  if @api_key.nil? || @api_key.empty?
    raise ArgumentError,
          "reapi: missing API key. Pass api_key: or set REAPI_API_KEY. Get one at https://reapi.ai"
  end
end

Instance Method Details

#chat_completions(**params) ⇒ Object

POST /chat/completions. params mirrors the OpenAI request body (model, messages, …). Returns the parsed JSON response.



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

def chat_completions(**params)
  post("/chat/completions", params)
end

#modelsObject

GET /models — discover available models at runtime.



42
43
44
# File 'lib/reapi.rb', line 42

def models
  get("/models")
end