Skip to Content
unii.docs
Sdks

Ruby SDK

Official Ruby client library for Unii platform with block-based streaming and clean error handling.

Overview

The Unii Ruby SDK (unii gem) provides an idiomatic client for Ruby 3.x applications with block-based SSE streaming, synchronous requests, and structured error handling.

Installation

Install the gem via your terminal:

gem install unii

Or add it to your Gemfile:

Gemfile
gem "unii", "~> 0.1.0"

Initialize and use the client

app.rb
require "unii"

client = Unii::Client.new(api_key: ENV["UNII_API_KEY"])

# 1. Verify credentials

auth = client.verify_auth
puts "Authenticated: " + auth["keyName"]

# 2. Synchronous chat completion

response = client.create_chat_completion(
  messages: [{ role: "user", content: "What is the return window?" }]
)
puts response.dig("choices", 0, "message", "content")

# 3. Stream tokens

client.stream_chat_completion(
  messages: [{ role: "user", content: "Explain warranty." }]
) do |chunk|
  print chunk.dig("choices", 0, "delta", "content")
end

# 4. Error handling

begin
  client.verify_auth
rescue Unii::ApiError => e
  puts "HTTP Error: #{e.status} - #{e.message}"
end

On this page