Ruby SDK for the Infinite API with an ActiveRecord-like DSL.
customer = Infinite::Customer.find("cus_abc123")
customer.update!(customerName: "Ada") # or: customer.customer_name = "Ada"; customer.save
Infinite::Customer.where(status: "ACTIVE").each { |c| puts c.email }
transfer = Infinite::Transfer.create(
sourceCustomerId: customer.id,
destAccountId: "acc_xyz",
sourceAmount: "100.00",
sourceCurrency: "USD",
paymentRail: "ach"
)
transfer.submit!# Gemfile
gem "infinite-api"The gem name is infinite-api (hyphenated) but the Ruby namespace is Infinite::*. During local development you can point at the checked-out gem directory:
gem "infinite-api", path: "../infinite"Then:
bundle installbin/rails g infinite:installThis creates config/initializers/infinite.rb. Add your API key:
bin/rails credentials:editinfinite:
access_token: sk_sandbox_your_key_here…or export INFINITE_ACCESS_TOKEN in your environment.
require "infinite"
Infinite.configure do |c|
c.access_token = ENV.fetch("INFINITE_ACCESS_TOKEN")
c.environment = :sandbox # or :production
end| Option | Default | Description |
|---|---|---|
access_token |
nil | sk_live_... / sk_sandbox_.... Required. |
environment |
:production |
:sandbox or :production. Drives default base URL. |
base_url |
derived from environment |
Explicit override |
timeout |
30 |
Request timeout (seconds) |
open_timeout |
10 |
Connection open timeout (seconds) |
retries |
2 |
Retry attempts on 429/502/503/504 |
logger |
Rails.logger when on Rails |
Logger-compatible sink for Faraday |
user_agent |
"infinite-ruby/#{VERSION}" |
User-Agent header |
dev_org_id |
nil |
Optional x-dev-org-id (development only) |
auto_idempotency_key |
true |
Auto-attach a UUID Idempotency-Key on every POST |
Infinite.with(access_token: tenant.api_key) do
Infinite::Customer.find(params[:id])
endThread-safe — uses thread-local storage. Overrides revert after the block.
# Read
customer = Infinite::Customer.find("cus_abc123")
# Create — use the type-specific factories (recommended)
customer = Infinite::Customer.create_individual(
email: "ada@example.com",
countryCode: "GB",
customerDetails: { firstName: "Ada", lastName: "Lovelace" }
)
# Update — only changed attributes are PATCHed
customer.customerName = "Augusta" # or: customer.customer_name = "Augusta"
customer.save
# Destroy (archives, for customers)
customer.archive!Attribute naming. API fields are camelCase; the SDK also generates snake_case aliases for Ruby ergonomics.
customer.customerNameandcustomer.customer_namepoint at the same underlying storage and share dirty tracking. Writes sent on the wire stay camelCase.
Nested fields. Customer-type-specific data (firstName, lastName, legalName, addresses, etc.) lives under
customer.customerDetails— the API does not expose them as top-level attributes on Customer itself. Read and write them as hashes.
where, order, limit, offset, expand chain like ActiveRecord. HTTP
only fires on terminal methods (each, to_a, first, count).
Infinite::Customer
.where(status: "ACTIVE", countryCode: "US")
.order("-createdAt")
.limit(50)
.each { |c| puts c.email }Both pagination modes are walked transparently:
# Offset-based (most endpoints)
Infinite::Customer.all.each { |c| ... }
# Cursor-based (transfers)
Infinite::Transfer.page_size(100).each { |t| ... }
# Page-by-page if you want control:
Infinite::Transfer.all.each_page { |records| process_batch(records) }customer = Infinite::Customer.find(id)
customer.transfers.where(status: "PROCESSING").each { |t| ... }
customer.accounts.to_a
customer.fixed_routes.to_aEndpoints that don't map to standard CRUD are exposed as ! methods:
customer.submit! # POST /v1/customers/{id}/submit
transfer.submit! # POST /v1/transfers/{id}/submit
transfer.cancel! # POST /v1/transfers/{id}/cancel
transfer.fund_from_balance!(customerId: "cus_1") # PATCH /v1/transfers/{id}/fund-from-balance
document.confirm! # POST /v1/documents/{id}/confirm
document.archive! # POST /v1/documents/{id}/archive# Customer polymorphism
Infinite::Customer.create_individual(...)
Infinite::Customer.create_business(...)
# Associated entities (business customers have child owners)
customer.create_associated_individual(firstName: "Ada", ...)
customer.create_associated_business(legalName: "Subsidiary Ltd", ...)
# Fixed routes
Infinite::FixedRoute.create_virtual_bank_account(customerId: ..., sweepTargetId: ...)
Infinite::FixedRoute.create_virtual_wallet(customerId: ..., sweepTargetId: ...)org = Infinite::Organization.current
org.update(name: "Acme Inc")
Infinite::Organization::Configuration.current.update(
feePayoutAddresses: { ethereum: "0x..." }
)session = Infinite::Verification.initiate(customerId: "cus_1")
status = Infinite::Verification.customer_status("cus_1")Raise Infinite::SandboxOnly if called against a non-sandbox environment.
Infinite::Sandbox.set_customer_status("cus_1", "ACTIVE")
Infinite::Sandbox.simulate_transfer_lifecycle("txn_1", stage: "processing")Three-step signed-URL flow wrapped into one call:
doc = Infinite::Document.create_upload_request(
customerId: "cus_1",
documentType: "PROOF_OF_ADDRESS",
fileName: "bank_statement.pdf",
contentType: "application/pdf"
)
doc.upload!("/path/to/bank_statement.pdf") # PUT bytes + auto /confirm
# Or: doc.upload!(uploaded_file.tempfile, content_type: "application/pdf")For webhooks coming into your Rails app from Infinite:
class WebhooksController < ApplicationController
skip_before_action :verify_authenticity_token, only: :receive
def receive
Infinite::Webhook.verify!(
payload: request.raw_post,
signature: request.headers["X-Provider-Signature"],
secret: Rails.application.credentials.dig(:infinite, :webhook_secret)
)
event = JSON.parse(request.raw_post)
# dispatch on event["type"]
head :ok
rescue Infinite::Webhook::InvalidSignature
head :unauthorized
end
endConstant-time compare, tolerates a sha256= prefix on the signature header.
The SDK fails fast on operations that don't make sense rather than hitting the API and getting a confusing error:
Infinite::Organization.find("anything")
# => Infinite::NotSupported: Organization is a singleton — use .current instead
Infinite::Transfer.count
# => Infinite::NotSupported: cursor pagination — .count would require walking
# every page. Use .each_page { |page| ... } or bound with .limit(n).Every API error maps to a typed class under Infinite::APIError:
| Class | HTTP |
|---|---|
Infinite::BadRequest |
400 |
Infinite::Unauthorized |
401 |
Infinite::Forbidden |
403 |
Infinite::NotFound |
404 |
Infinite::Conflict |
409 |
Infinite::ValidationError |
422 |
Infinite::RateLimited |
429 |
Infinite::ServerError |
500 |
Infinite::BadGateway |
502 |
Infinite::ServiceUnavailable |
503 |
Infinite::GatewayTimeout |
504 |
Every error exposes #status, #error_type, #message, #details,
#request_id, #body, #response.
begin
customer = Infinite::Customer.find(id)
rescue Infinite::NotFound
head :not_found
rescue Infinite::Unauthorized
redirect_to billing_path, alert: "Reconnect your Infinite account"
rescue Infinite::ValidationError => e
render json: { errors: e.errors_by_field }, status: :unprocessable_entity
rescue Infinite::RateLimited => e
retry_after = e.retry_after || 30
Retryable.schedule_in(retry_after.seconds)
endFor AR-style validation, save / create catch 422s and populate the
record's errors instead of raising:
customer = Infinite::Customer.create_individual(email: "bad")
if customer.persisted?
# ...
else
customer.errors[:email] # => ["Invalid email format"]
endUse save! / create! / update! to raise on failure.
Every request emits request.infinite via ActiveSupport::Notifications:
ActiveSupport::Notifications.subscribe("request.infinite") do |_, _, _, _, payload|
# payload => { method:, path:, status:, duration: }
StatsD.timing("infinite.#{payload[:method]}", payload[:duration] * 1000)
endIn development on Rails the gem logs each request automatically.
Nothing special about the built-ins — you can subclass Infinite::Base for
any endpoint the SDK doesn't yet cover:
class Infinite::CustomThing < Infinite::Base
collection_path "/v1/custom-things"
attribute :id, :string
attribute :name, :string
attribute :status, :string
action :approve
has_many :events, class_name: "Infinite::Event",
path: "/v1/custom-things/{id}/events"
endEach resource was either verified end-to-end against the live sandbox (2026-04-21) or is currently limited to OpenAPI-alignment + unit tests.
| Resource | Read | Write | Notes |
|---|---|---|---|
Organization (singleton) |
✓ | — | Singleton read verified; update untested with data |
Customer |
✓ | ✓ create/find/update/archive | Flat-fields create request; nested response; full CRUD cycle verified |
Webhook::Endpoint |
✓ | ✓ create/update/destroy | PUT requires full updatable_attributes body |
Quote |
✓ | ✓ create | holdQuote: false returns no id (expected) |
Transfer |
list only | ○ | Cursor pagination fix verified (single page); multi-page walk untested |
Account |
list only | ○ | Endpoints responsive; no test records |
Counterparty |
list only | ○ | Same |
Document |
○ | ○ | Upload helper is unit-tested against WebMock, not a real signed URL |
ExternalBankAccount |
○ | ○ | OpenAPI-aligned only |
ExternalWallet |
○ | ○ | OpenAPI-aligned only |
FixedRoute |
○ | ○ | OpenAPI-aligned only |
TermsOfService |
○ | ○ | OpenAPI-aligned only |
Verification (module) |
○ | ○ | OpenAPI-aligned only |
Sandbox (module) |
○ | ○ | OpenAPI-aligned only |
✓ verified · ○ unverified (but endpoints reachable)
Several endpoints accept a different attribute set on write than they return on read. The SDK's permissive _assign_attribute lets undeclared attrs flow through on creates, and updatable_attributes restricts PUT bodies where needed.
Customer.create_individual(...)— flat fields (firstName,lastName,dateOfBirth,phone,occupation, ...). Response nests these undercustomerDetails.customer.update(...)— only acceptsemail,countryCode,customerDetails,addresses,preferences.customerNameis NOT updatable despite being in the response.Webhook::Endpoint#update(...)— PUT with full body (handled automatically viaupdatable_attributes). Don't senddisabled,id, timestamps, orsecret.Quote.create(...)—sourceAmount: { rawValue, currency }(minor-units string), plus top-levelsourceCurrency,destinationCurrency,payinMethod,payoutMethod. Use SCREAMING_SNAKE values like"ACH","ETHEREUM".
The API returns HTTP 400 for validation errors (not 422). The response details array is empty; all field-level errors are comma-joined into message. So:
rescue Infinite::BadRequest => e
e.message # "customerName must be a string, email must be an email, ..."
e.errors_by_field # => {} (always empty — API doesn't structure the details)
endParse #message if you need field-level errors in the UI. ValidationError (422) is still in the hierarchy for when/if the API starts returning structured validation details.
bin/setup # install deps
bundle exec rspec # run tests (WebMock stubs, fully offline)
bundle exec rubocop
bundle exec rake # lint + test
# Regenerate docs/ snapshots (requires the docs passcode — these files
# are gitignored; see testing model below)
INFINITE_DOCS_PASSCODE=... script/regen_docs.sh
# Live-verify the SDK against your sandbox (creates & archives test records)
INFINITE_ACCESS_TOKEN=sk_sandbox_... bundle exec ruby script/verify_sandbox.rbThis gem intentionally does not commit VCR cassettes. Three reasons:
- Cassette bodies carry org identity. Recorded responses include the recording account's name, record IDs, timestamps, and signed URLs. VCR's default filters scrub request-side credentials but don't touch response bodies.
- Cassettes go stale. Recorded six months ago, the API adds new response fields but CI still passes — a false sense of coverage.
script/verify_sandbox.rbis a better live-regression harness. Each contributor runs it with their own sandbox key. No shared state, nothing to leak.
Unit tests (bundle exec rspec) use WebMock stubs with exact expected bodies. For end-to-end live checks, set INFINITE_ACCESS_TOKEN and run the verify script. If you do record cassettes locally for debugging, they're gitignored under spec/fixtures/vcr_cassettes/ — don't try to commit them.
- Rotate any sandbox key you've pasted into issues, PRs, or commit messages
- Keep
docs/ref_*.md,docs/openapi_*.json,docs/llms.txt, anddocs/generated_attrs.txtout of git — those files are derived from Infinite's gated documentation and should not be republished
Tests use WebMock for stubbing and VCR for recorded fixtures. The access
token in cassettes is filtered to <ACCESS_TOKEN>.
MIT — see LICENSE.txt.