Skip to content

Generate a Ruby SDK for your API

Octri generates a Ruby gem for your API with keyword arguments and typed models on Net::HTTP, publishes it to RubyGems under your gem name, and regenerates it whenever your API changes.

Start from scratch

Or upload a file: OpenAPI 3.0 or 3.1, Swagger 2.0, Postman or AsyncAPI.

Install from RubyGems
gem install acme_api

The Ruby API client your users get

What your users write once the Ruby package is installed.

Two call styles come out of the same generator. class-namespaced is the default: one client object with operations grouped by resource, the shape most popular SDKs use and the one your API reference already shows. functions is the alternative: no client object, one configure call, and each operation imported on its own. It is one setting per language, and nothing else about the client changes with it.

Parameters are keyword arguments named after your API’s properties, so a call reads the same as the request body it sends. Pagination is a plain Enumerator, and .lazy.select or .first(10) stop fetching as soon as they have enough.

Published with your RubyGems API key. The gem name also decides the module, so acme_api is required as "acme_api" and called as AcmeApi.

Ruby
require "acme_api"

config = AcmeApi::ClientConfig.new
config.base_url = "https://api.acme.com/v1"
auth = AcmeApi::ClientAuthConfig.new
auth.bearer = ENV.fetch("ACME_TOKEN")
config.auth = auth

acme = AcmeApi::Acme.new(config)

# list_paginated returns an Enumerator, so each, lazy, first and take all work.
acme.users.list_paginated(limit: 100).each do |user|
  puts user.id
end

invoice = acme.invoices.create(customer_id: "cus_123", amount_cents: 4900)

The Ruby SDK at a glance

What a developer checks before adding the Ruby package to a project.

Runs on
Ruby 3.0+
Transport
Net::HTTP from the standard library
Runtime dependencies
None
Models
Plain Ruby classes with attribute readers
Pagination
Enumerator, lazy by construction
Ships to
RubyGems, installable with gem or Bundler

When a call fails

Each common status is its own subclass of SdkHttpError, so rescue clauses can be as narrow as the handler. A declared error model arrives decoded on e.data.

Typed errors
begin
  acme.invoices.create(customer_id: "cus_123", amount_cents: 4900)
rescue AcmeApi::SdkRateLimitError
  # 429 after the built-in retries. Re-enqueue the job.
  retry_later
rescue AcmeApi::SdkHttpError => e
  Rails.logger.error("acme failed status=#{e.status_code} request=#{e.request_id}")
end

Configure your Ruby SDK

Ruby has no engine or data-model setting. Net::HTTP and plain classes keep the gem free of runtime dependencies.

  • Client style

    class-namespaced (default), class, namespaced, functions

    A client object with a reader per resource, the shape Ruby developers expect from AcmeApi::Acme.new. Functions are module methods under AcmeApi::Methods, sharing one thread-safe global config.

  • Argument style

    positional (default), object

    Keyword arguments named after your API, with optional ones defaulting to nil. Object collects them into a request object.

  • Doc comments

    full (default), minimal

    Full carries your API’s descriptions into the comment above each method, so it reads well in an editor and in generated docs.

Method naming and namespacing work the same in every language: operations are grouped by your API’s tags or by path, and the namespace word is dropped from the method name unless you ask to keep the operationId whole.

Publishing to RubyGems: a yanked version stays taken

RubyGems lets you yank a version, which stops new installs, but the number stays claimed and the name stays yours for good. A bad 1.0.0 means the fix ships as 1.0.1. Generate, read the package and run it against your staging API before the first push, since the first version is the one people pin.

RubyGems gem name
acme_api
  • Not possible: Rename the gem
  • Not possible: Reuse a yanked version number
  • Still possible: Yank a version

Retries, pagination and typed errors, built in

The parts nobody wants to hand-write, and the parts a hand-written client usually skips.

  • Retries with exponential backoff and jitter, on the statuses that mean "try again", with a per-attempt timeout.
  • Idempotency keys on the methods that need them, so a retried write does not become two.
  • Auth wired in from your API’s security schemes, read from wherever your users keep secrets.
  • Typed errors split by cause: a failed constraint, an HTTP status, a network failure and a timeout are four different things.
  • Pagination that follows whichever style your API uses, cursor, offset, page number or next URL, without prefetching the collection.
  • Server-sent events as a native stream, for the operations that stream.
  • Error reporting to Octri’s monitoring, pre-wired and switched off until a consumer opts in.
  1. Add your API

    Upload an OpenAPI or Swagger file, paste a URL, connect the repository it lives in, or add endpoints in the editor.

  2. Read the audit

    Octri scores your API out of 10 on what a generator can do with it and names every missing schema and clashing operationId. 8 of the 14 rules come with a button that writes the fix.

  3. Shape the client

    Client style, argument style, namespacing, auth, retries and pagination, set once for the project and overridden per language or per endpoint.

  4. Generate and read it

    The package is generated, compiled and handed to you as source you can read before anyone installs it.

  5. Publish, then keep publishing

    Release to the registry under your own account. Every later change to your API regenerates the client, and the version number follows the version your API declares.

Ruby SDK generator questions

OpenAPI Generator’s Ruby client defaults to Typhoeus, with Faraday and httpx as options, and leaves packaging and publishing the gem to you. Octri generates a gem on Net::HTTP with no runtime dependencies, publishes it to RubyGems under your name, and regenerates it when your API changes.