routerbase-client 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a0bbc0d84f35cfafc7c9403eb02408d2ca06d311b8794b5268b61550a8ea3503
4
+ data.tar.gz: 660e84a0786913247bb0177df877314cf366f00a54df32fe3de041fc76357fb3
5
+ SHA512:
6
+ metadata.gz: 594aed71a20bf6b8241bb7d8c3b2c15a513b99cd4564816859f72cdd3011676097da357c0c441aed79316c9fdac74c7b3bf5c6df820367896e72d37b088b67ed
7
+ data.tar.gz: 3449c0fec7ea0244eb354ce40a116a583f0e2db59a912c33410286ef13054edcaedc5b839403beb721742c7c9b9d131ad6b7de61c2ae54be4beb430d692f6a35
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RouterBase Contributors
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,53 @@
1
+ # RouterBase Ruby Client
2
+
3
+ [RouterBase](https://routerbase.com) provides an OpenAI-compatible API for calling many AI models through `https://routerbase.com/v1`.
4
+
5
+ `routerbase-client` is a dependency-free Ruby client and CLI for chat completions and model listing. It is prepared for RubyGems publishing without GitHub metadata while that publishing line is paused.
6
+
7
+ ## Install
8
+
9
+ After publishing to RubyGems:
10
+
11
+ ```bash
12
+ gem install routerbase-client
13
+ ```
14
+
15
+ For local testing:
16
+
17
+ ```bash
18
+ gem build routerbase-client.gemspec
19
+ gem install ./routerbase-client-0.1.0.gem
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require "routerbase"
26
+
27
+ client = RouterBase::Client.new(api_key: ENV.fetch("ROUTERBASE_API_KEY"))
28
+ response = client.chat_completion(
29
+ messages: [
30
+ { role: "user", content: "Write a short RouterBase tagline." }
31
+ ]
32
+ )
33
+
34
+ puts response.fetch("choices").first.fetch("message").fetch("content")
35
+ ```
36
+
37
+ ## CLI
38
+
39
+ ```bash
40
+ export ROUTERBASE_API_KEY="sk-rb-..."
41
+ routerbase-chat "Write a five-word launch tagline"
42
+ ```
43
+
44
+ ## Links
45
+
46
+ - [RouterBase](https://routerbase.com)
47
+ - RouterBase docs: https://docs.routerbase.com/
48
+ - Chat completions docs: https://docs.routerbase.com/api-reference/chat-completions
49
+ - npm quickstart package: https://www.npmjs.com/package/routerbase-quickstart
50
+
51
+ ## License
52
+
53
+ MIT
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+ require "routerbase"
6
+
7
+ prompt = ARGV.join(" ").strip
8
+
9
+ if prompt.empty?
10
+ warn "Usage: routerbase-chat \"Write a short RouterBase tagline\""
11
+ exit 1
12
+ end
13
+
14
+ client = RouterBase::Client.new
15
+ response = client.chat_completion(
16
+ messages: [
17
+ {
18
+ role: "user",
19
+ content: prompt
20
+ }
21
+ ]
22
+ )
23
+
24
+ puts response.fetch("choices").first.fetch("message").fetch("content")
@@ -0,0 +1,81 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ module RouterBase
6
+ class Error < StandardError; end
7
+
8
+ class Client
9
+ attr_reader :api_key, :base_url, :transport
10
+
11
+ def initialize(api_key: ENV["ROUTERBASE_API_KEY"], base_url: BASE_URL, transport: nil)
12
+ raise ArgumentError, "RouterBase API key is required" if api_key.nil? || api_key.empty?
13
+
14
+ @api_key = api_key
15
+ @base_url = base_url.sub(%r{/+\z}, "")
16
+ @transport = transport || NetHTTPTransport.new
17
+ end
18
+
19
+ def chat_completion(messages:, model: DEFAULT_MODEL, **options)
20
+ raise ArgumentError, "messages must be a non-empty array" if messages.nil? || messages.empty?
21
+
22
+ post_json(
23
+ "/chat/completions",
24
+ {
25
+ model: model,
26
+ messages: messages
27
+ }.merge(options)
28
+ )
29
+ end
30
+
31
+ def list_models
32
+ request_json(:get, "/models")
33
+ end
34
+
35
+ private
36
+
37
+ def post_json(path, payload)
38
+ request_json(:post, path, payload)
39
+ end
40
+
41
+ def request_json(method, path, payload = nil)
42
+ uri = URI("#{base_url}#{path}")
43
+ response = transport.request(
44
+ method: method,
45
+ uri: uri,
46
+ headers: headers(payload),
47
+ body: payload.nil? ? nil : JSON.generate(payload)
48
+ )
49
+
50
+ parsed = response.body.nil? || response.body.empty? ? {} : JSON.parse(response.body)
51
+ return parsed if response.code.to_i.between?(200, 299)
52
+
53
+ message = parsed.dig("error", "message") || parsed["msg"] || response.body
54
+ raise Error, "RouterBase request failed (#{response.code}): #{message}"
55
+ end
56
+
57
+ def headers(payload)
58
+ values = {
59
+ "Authorization" => "Bearer #{api_key}"
60
+ }
61
+ values["Content-Type"] = "application/json" unless payload.nil?
62
+ values
63
+ end
64
+ end
65
+
66
+ class NetHTTPTransport
67
+ Response = Struct.new(:code, :body, keyword_init: true)
68
+
69
+ def request(method:, uri:, headers:, body: nil)
70
+ http = Net::HTTP.new(uri.host, uri.port)
71
+ http.use_ssl = uri.scheme == "https"
72
+
73
+ request = method == :get ? Net::HTTP::Get.new(uri) : Net::HTTP::Post.new(uri)
74
+ headers.each { |key, value| request[key] = value }
75
+ request.body = body unless body.nil?
76
+
77
+ response = http.request(request)
78
+ Response.new(code: response.code, body: response.body)
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module RouterBase
2
+ VERSION = "0.1.0"
3
+ end
data/lib/routerbase.rb ADDED
@@ -0,0 +1,7 @@
1
+ require_relative "routerbase/client"
2
+ require_relative "routerbase/version"
3
+
4
+ module RouterBase
5
+ BASE_URL = ENV.fetch("ROUTERBASE_BASE_URL", "https://routerbase.com/v1").sub(%r{/+\z}, "")
6
+ DEFAULT_MODEL = "google/gemini-2.5-flash"
7
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: routerbase-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - RouterBase Contributors
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-07-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A dependency-free Ruby client and CLI for RouterBase chat completions
14
+ and model listing.
15
+ email:
16
+ executables:
17
+ - routerbase-chat
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - exe/routerbase-chat
24
+ - lib/routerbase.rb
25
+ - lib/routerbase/client.rb
26
+ - lib/routerbase/version.rb
27
+ homepage: https://routerbase.com
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ homepage_uri: https://routerbase.com
32
+ documentation_uri: https://docs.routerbase.com/
33
+ bug_tracker_uri: https://routerbase.com
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '2.6'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.0.3.1
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Dependency-free Ruby client for the RouterBase OpenAI-compatible API.
53
+ test_files: []