bf16 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 +29 -0
  4. data/lib/bf16/version.rb +5 -0
  5. data/lib/bf16.rb +90 -0
  6. metadata +54 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f01a59a094a38d063d3e6f77f0102a174c05c182e6e6f2ef9fd0960c1a76d167
4
+ data.tar.gz: 38012c0c0d97841ca36fd9b5dd8082f05d84daf9392415cf8d32a065eb0eb5cf
5
+ SHA512:
6
+ metadata.gz: 511c2afcd4381c2178e630245be93e18e50013ab828b37b9f7447ee8941624b4d8bffbb97554a768f6ea203e959158a8ca37a84e92fbe8ae2237fff460345241
7
+ data.tar.gz: 46c00b92a5968d72a9dda8fa4f4751d38a560df4a9e3aeb96e02bd90ced258d4a991ea6ea093ed47d4f92941fd29aef81512512a1f2dd3a7e2aaeccb3ed9c720
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BF16 Team
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,29 @@
1
+ # bf16 (Official Ruby SDK)
2
+
3
+ Zero-dependency Ruby client for [bf16.ai](https://bf16.ai) — uncensored 1M-context open-weight LLM inference API (`DeepSeek V4.1 Flash`, `GLM-5.3`, `Kimi K3.1 Pro`) with automatic prompt caching and strict Zero Data Retention (ZDR).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install bf16
9
+ ```
10
+
11
+ ## Quickstart
12
+
13
+ ```ruby
14
+ require "bf16"
15
+
16
+ client = Bf16::Client.new(api_key: ENV.fetch("BF16_API_KEY"))
17
+
18
+ response = client.chat(
19
+ model: Bf16::MODEL_DEEPSEEK_V41_FLASH,
20
+ messages: [{ role: "user", content: "Summarize this SQL migration safely." }]
21
+ )
22
+ puts response.dig("choices", 0, "message", "content")
23
+ ```
24
+
25
+ ## Documentation & Links
26
+
27
+ - Website & Console: [bf16.ai](https://bf16.ai)
28
+ - API Documentation: [bf16.ai/docs](https://bf16.ai/docs)
29
+ - Open-Source Grants (`$50` API credits): [bf16.ai/open-source](https://bf16.ai/open-source)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bf16
4
+ VERSION = "0.1.0"
5
+ end
data/lib/bf16.rb ADDED
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/http"
5
+ require "uri"
6
+ require_relative "bf16/version"
7
+
8
+ module Bf16
9
+ DEFAULT_BASE_URL = "https://api.bf16.ai/v1"
10
+ ANTHROPIC_BASE_URL = "https://api.bf16.ai"
11
+
12
+ MODEL_DEEPSEEK_V41_FLASH = "deepseek/deepseek-v4.1-flash-uncensored"
13
+ MODEL_DEEPSEEK_V41_FLASH_FAST = "deepseek/deepseek-v4.1-flash-uncensored-fast"
14
+ MODEL_GLM_53_FLASH = "zai-org/glm-5.3-flash-uncensored"
15
+ MODEL_GLM_53 = "zai-org/glm-5.3-uncensored"
16
+ MODEL_KIMI_K31_PRO = "moonshotai/kimi-k3.1-pro-uncensored"
17
+ MODEL_AUTO = "bf16/auto"
18
+
19
+ class Error < StandardError
20
+ attr_reader :status_code
21
+
22
+ def initialize(message, status_code = nil)
23
+ super(message)
24
+ @status_code = status_code
25
+ end
26
+ end
27
+
28
+ class Client
29
+ attr_reader :base_url, :timeout
30
+
31
+ def initialize(api_key: ENV["BF16_API_KEY"], base_url: DEFAULT_BASE_URL, timeout: 120)
32
+ @api_key = api_key
33
+ @base_url = base_url.to_s.sub(%r{/+$}, "")
34
+ @timeout = timeout
35
+ end
36
+
37
+ def models
38
+ request_json("GET", "/models", auth: false)
39
+ end
40
+
41
+ def me
42
+ request_json("GET", "/me", auth: true)
43
+ end
44
+
45
+ def chat(model:, messages:, **options)
46
+ payload = options.merge(model: model, messages: messages)
47
+ request_json("POST", "/chat/completions", payload: payload, auth: true)
48
+ end
49
+
50
+ def responses(model:, input:, **options)
51
+ payload = options.merge(model: model, input: input)
52
+ request_json("POST", "/responses", payload: payload, auth: true)
53
+ end
54
+
55
+ private
56
+
57
+ def request_json(method, path, payload: nil, auth: true)
58
+ if auth && (@api_key.nil? || @api_key.empty?)
59
+ raise Error.new("Missing BF16_API_KEY", nil)
60
+ end
61
+
62
+ uri = URI.parse("#{@base_url}#{path}")
63
+ http = Net::HTTP.new(uri.host, uri.port)
64
+ http.use_ssl = (uri.scheme == "https")
65
+ http.read_timeout = @timeout
66
+
67
+ req = method == "GET" ? Net::HTTP::Get.new(uri.request_uri) : Net::HTTP::Post.new(uri.request_uri)
68
+ req["Accept"] = "application/json"
69
+ req["User-Agent"] = "bf16-ruby/#{VERSION}"
70
+ req["Authorization"] = "Bearer #{@api_key}" if auth && @api_key && !@api_key.empty?
71
+
72
+ if payload
73
+ req["Content-Type"] = "application/json"
74
+ req.body = JSON.generate(payload)
75
+ end
76
+
77
+ res = http.request(req)
78
+ parsed = begin
79
+ JSON.parse(res.body.to_s)
80
+ rescue JSON::ParserError
81
+ { "raw" => res.body.to_s }
82
+ end
83
+
84
+ code = res.code.to_i
85
+ raise Error.new("bf16.ai HTTP #{code}: #{res.body}", code) if code >= 400
86
+
87
+ parsed
88
+ end
89
+ end
90
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bf16
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - BF16 Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-11-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Zero-dependency Ruby client for bf16.ai OpenAI-compatible (/v1/chat/completions,
14
+ /v1/responses) and Anthropic Messages (/v1/messages) APIs with strict Zero Data
15
+ Retention.
16
+ email:
17
+ - hello@bf16.ai
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE
23
+ - README.md
24
+ - lib/bf16.rb
25
+ - lib/bf16/version.rb
26
+ homepage: https://bf16.ai
27
+ licenses:
28
+ - MIT
29
+ metadata:
30
+ homepage_uri: https://bf16.ai
31
+ documentation_uri: https://bf16.ai/docs
32
+ source_code_uri: https://github.com/BF16-AI/bf16-ruby
33
+ changelog_uri: https://bf16.ai/changelog
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.0
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.5.22
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Official zero-dependency Ruby SDK for bf16.ai (1M-context uncensored LLM
53
+ API).
54
+ test_files: []