reapi 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +46 -0
  4. data/lib/reapi/version.rb +5 -0
  5. data/lib/reapi.rb +69 -0
  6. metadata +50 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b49e6591f185469ba7cb8eb7ecf24a834aad9d0faabd709ba3983a5693b24b73
4
+ data.tar.gz: cf2f91a7c58558a5d95afcdf0fade6f2080ebb1bba5e12e635421f3ff1a4b82d
5
+ SHA512:
6
+ metadata.gz: 9d47a2b0738c3964c21f69734f640621215f1fccea9f539d0f14af035ddea645ba604da49c89c66e5c572a481dac9771f4553c13596db303879ae660732c653d
7
+ data.tar.gz: 5933b74b60c790e34fc63d7eba6cf95ee5bc437540c8d075977d2cbe71be325fb8b8d0f8c75cc7c812da51abb8bf6f9adbfb199bd59e2db2d1528c8235feac1a
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 reAPI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # reapi
2
+
3
+ OpenAI-compatible Ruby SDK for the [reAPI](https://reapi.ai) gateway.
4
+
5
+ reAPI speaks the OpenAI API. This gem is a thin client over
6
+ `https://api.reapi.ai/v1`, using only the Ruby standard library (no dependencies).
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ gem install reapi
12
+ ```
13
+
14
+ ## Quick start
15
+
16
+ ```ruby
17
+ require "reapi"
18
+
19
+ # Reads ENV["REAPI_API_KEY"], or pass api_key:
20
+ client = Reapi.client
21
+
22
+ # Discover available models at runtime:
23
+ models = client.models
24
+
25
+ res = client.chat_completions(
26
+ model: models["data"].first["id"],
27
+ messages: [{ role: "user", content: "Hello from reAPI" }],
28
+ )
29
+ puts res.dig("choices", 0, "message", "content")
30
+ ```
31
+
32
+ ## API key
33
+
34
+ Get an API key at [reapi.ai](https://reapi.ai):
35
+
36
+ ```ruby
37
+ client = Reapi.client(api_key: "YOUR_KEY")
38
+ ```
39
+
40
+ ```bash
41
+ export REAPI_API_KEY=YOUR_KEY
42
+ ```
43
+
44
+ ## License
45
+
46
+ MIT
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reapi
4
+ VERSION = "0.1.0"
5
+ end
data/lib/reapi.rb ADDED
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "uri"
6
+
7
+ require_relative "reapi/version"
8
+
9
+ # OpenAI-compatible Ruby client for the reAPI gateway (https://reapi.ai).
10
+ module Reapi
11
+ # Public base URL of the reAPI gateway.
12
+ BASE_URL = "https://api.reapi.ai/v1"
13
+
14
+ # Create a client. Reads ENV["REAPI_API_KEY"] when +api_key+ is nil.
15
+ #
16
+ # client = Reapi.client
17
+ # client.models # discover models at runtime
18
+ # client.chat_completions(
19
+ # model: "<model-id>",
20
+ # messages: [{ role: "user", content: "Hello from reAPI" }],
21
+ # )
22
+ def self.client(api_key: nil)
23
+ Client.new(api_key: api_key)
24
+ end
25
+
26
+ class Client
27
+ def initialize(api_key: nil)
28
+ @api_key = api_key || ENV["REAPI_API_KEY"]
29
+ if @api_key.nil? || @api_key.empty?
30
+ raise ArgumentError,
31
+ "reapi: missing API key. Pass api_key: or set REAPI_API_KEY. Get one at https://reapi.ai"
32
+ end
33
+ end
34
+
35
+ # POST /chat/completions. +params+ mirrors the OpenAI request body
36
+ # (model, messages, ...). Returns the parsed JSON response.
37
+ def chat_completions(**params)
38
+ post("/chat/completions", params)
39
+ end
40
+
41
+ # GET /models — discover available models at runtime.
42
+ def models
43
+ get("/models")
44
+ end
45
+
46
+ private
47
+
48
+ def post(path, body)
49
+ uri = URI("#{BASE_URL}#{path}")
50
+ req = Net::HTTP::Post.new(uri)
51
+ req["Authorization"] = "Bearer #{@api_key}"
52
+ req["Content-Type"] = "application/json"
53
+ req.body = JSON.generate(body)
54
+ send_request(uri, req)
55
+ end
56
+
57
+ def get(path)
58
+ uri = URI("#{BASE_URL}#{path}")
59
+ req = Net::HTTP::Get.new(uri)
60
+ req["Authorization"] = "Bearer #{@api_key}"
61
+ send_request(uri, req)
62
+ end
63
+
64
+ def send_request(uri, req)
65
+ res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
66
+ JSON.parse(res.body)
67
+ end
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - reAPI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-05-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Thin Ruby client for the reAPI gateway. reAPI speaks the OpenAI API;
14
+ this gem talks to https://api.reapi.ai/v1 using only the Ruby standard library.
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE
21
+ - README.md
22
+ - lib/reapi.rb
23
+ - lib/reapi/version.rb
24
+ homepage: https://reapi.ai
25
+ licenses:
26
+ - MIT
27
+ metadata:
28
+ homepage_uri: https://reapi.ai
29
+ source_code_uri: https://github.com/reAPIAI/reapi-rb
30
+ bug_tracker_uri: https://github.com/reAPIAI/reapi-rb/issues
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '2.6'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.0.3.1
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: OpenAI-compatible Ruby SDK for the reAPI gateway (https://reapi.ai).
50
+ test_files: []