Official Ruby client for the TryItOn virtual try-on API. Add photoreal AI virtual try-on for clothing, accessories, hairstyles, and tattoos to your Ruby or Rails application with a few lines of code.
- Virtual clothing try-on and accessory try-on (eyewear, footwear, headwear, jewelry)
- Hairstyle and tattoo try-on
- Standard library only (no dependencies), with a built-in job polling helper
Full API reference: docs.tryiton.now · Get an API key: tryiton.now/app/developer
gem install tryitonOr add it to your Gemfile:
gem "tryiton"Requires Ruby 2.6 or later.
Submit a garment and a model photo, then wait for the generated result image.
require "tryiton"
client = Tryiton::Client.new(api_key: ENV["TRYITON_API_KEY"])
# Submit a clothing try-on
job_id = client.try_on_fashion(
model_image: "https://example.com/model.jpg",
garment_image: "https://example.com/tshirt.jpg",
category: "clothing",
subcategory: "tops"
)
# Poll until the job completes and return the output image URL(s)
urls = client.wait_for_result(job_id)
puts urls.first # CDN URL, available for 72 hoursImage inputs accept a public URL or a base64 data URL (data:image/png;base64,...).
try_on_fashion covers clothing and accessory try-on. The most important parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
model_image |
String | Yes | URL or base64 data URL of the person. |
garment_image |
String | Yes | URL or base64 data URL of the garment or accessory. |
category |
String | No | Item type: auto, clothing, eyewear, footwear, headwear, jewelry, accessories, or others. auto detects it for you. |
subcategory |
String | No | Required for clothing (tops, bottoms, dresses), jewelry, and accessories. |
Additional options (mode and moderation_level for clothing; num_samples 1–4 and output_format png/jpeg for every try-on, including hairstyle and tattoo) are documented in the API reference.
# Hairstyle try-on (see Tryiton::HAIRCUTS for all supported values)
client.try_on_hairstyle(face_image: face_url, haircut: "BuzzCut", hair_color: "ash blonde")
# Tattoo try-on — place it with free text...
client.try_on_tattoo(body_image: body_url, design_image: design_url, placement: "on the right forearm, small")
# ...or pin the exact spot with a region box (normalized 0-1, from the image's top-left)
client.try_on_tattoo(body_image: body_url, design_image: design_url, region: { x: 0.32, y: 0.18, w: 0.28, h: 0.34 })
# Poll a job manually, or check your credit balance
status = client.get_status(job_id) # { "status" => ..., "output" => [...], "error" => ... }
credits = client.get_credits # { "on_demand" => ..., "subscription" => ..., "purchased" => ..., "reserved" => ... }Your server prepares garments and starts sessions with the API key. The shopper's browser streams with the
tryiton-live npm package, using only the session-scoped response.
# Once per product, e.g. at catalog sync (cached per image + category):
garment = client.prepare_live_garment(garment_image: product_image_url, category: "clothing", subcategory: "tops")
# When a shopper opens live try-on. Render `start` to the browser as-is (e.g. `render json: start`):
start = client.start_live_session(
garment_id: garment["id"],
end_user_id: shopper.id.to_s, # one stream per end user
allowed_origin: "https://shop.example.com" # locks the media token to your site
)
client.get_live_session(start["session"]["id"]) # { "status" => ..., "seconds" => ..., "creditsCharged" => ... }
client.stop_live_session(start["session"]["id"]) # end it from your server
client.get_live_config # { "enabled" => ..., "secondsPerCredit" => ..., "maxSeconds" => ... }Billing is per secondsPerCredit seconds of streamed video, from the first try-on frame. Garment switches during a
session are free.
All failures raise Tryiton::Error, which carries the HTTP status code and the API error name.
begin
client.try_on_fashion(...)
rescue Tryiton::Error => e
puts "#{e.status} #{e.error_name} #{e.message}" # e.g. 429 OutOfCredits
end- Output image URLs expire 72 hours after completion. Download any results you want to keep.
- Failed jobs are never charged.
- Every request sends
User-Agent: tryiton-ruby/<version>. - Type signatures (RBS) ship in
sig/for Steep and other RBS tooling. - To route requests through your own HTTP layer (retries, logging, a proxy), pass
transport:toClient.new: any object whosecall(request)takes aTryiton::Requestand returns something withstatusandbody. SeeTryiton::NetHTTPTransportfor the default.
bundle install
bundle exec rake test # Minitest, including the shared contract cases
bundle exec rbs -I sig validate # RBS signatures (Ruby 3.1+)test/fixtures/sdk-cases.json is generated from the TryItOn backend's API contract. Don't edit it here.
Full documentation, parameter reference, and guides: docs.tryiton.now
MIT