OnFitt/ Docs← App
SDK v1 · REST API v1

OnFitt SDK & API Reference

Add a virtual try-on button to any product page in one line of HTML. Customers upload a photo and see themselves wearing your product.

Platform-specific setup guides

#Quick start

Paste one <script> tag on your product page. The SDK auto-detects your product image and injects a “Try it on” button beneath it.

<script
  src="https://www.getonfitt.com/api/sdk"
  data-api-key="YOUR_API_KEY">
</script>
Required: Replace YOUR_API_KEY with your API key from the dashboard.
Performance tip: Add this tag to your page <head> to pre-warm the connection and reduce button load time.
<link rel="preconnect" href="https://getonfitt.com">

#Product image detection

The SDK resolves the clothing item to send to the AI in this order of priority:

  1. Explicit URL list: data-clothing-urls
  2. Gallery selector: data-product-images (CSS selector for <img> tags)
  3. og:image meta tag: automatic, no configuration needed

Multi-image gallery (AI picks the best angle for best results):

<script
  src="https://www.getonfitt.com/api/sdk"
  data-api-key="sk_live_..."
  data-product-images=".product-gallery img">
</script>

Explicit URL list (JSON array):

data-clothing-urls='["https://yourstore.com/jacket-front.jpg","https://yourstore.com/jacket-side.jpg"]'
If no product image is found the button is silently hidden and a warning is logged to the console.

#CTA button

Customize the injected button with data-* attributes or via the Dashboard's Customize panel. Script-tag attributes always take precedence over dashboard settings.

Themes

Four built-in themes, or go fully custom with your own hex.

Try it on
purple
Try it on
dark
Try it on
light
custom
custom

Button attributes

AttributeTypeDefaultDescription
data-api-keystringYour OnFitt API key. Required.
data-themepurple | dark | light | custompurpleBuilt-in colour preset. Use custom to set your own colour via data-color.
data-colorhex / cssButton background when theme=custom.
data-text-colorhex / cssButton label colour when theme=custom.
data-radiusnumber (px)10Border radius of the button in pixels. 0–20.
data-button-labelstringTry it onLabel shown on the injected button.
data-attach-toCSS selectorIf set, the button is injected after the matched element instead of after the script tag.
<script
  src="https://www.getonfitt.com/api/sdk"
  data-api-key="sk_live_..."
  data-theme="custom"
  data-color="#e11d48"
  data-text-color="#ffffff"
  data-radius="8"
  data-button-label="See it on me">
</script>

The try-on modal inherits your brand colours. Every attribute below can also be set permanently through the Dashboard without touching code.

AttributeTypeDefaultDescription
data-modal-themelight | darklightBase colour scheme of the modal. Drives surface colours and text. Override individual colours with the attributes below.
data-accent-colorhex#7c3aedPrimary action colour. Drives the upload CTA, spinner, share button, and upload zone border.
data-cta-colorhexColour of the Shop this look button in the result step. Leave empty to use the accent colour.
data-modal-bghex#ffffffModal card background colour.
data-modal-title-colorhex#111111Colour of the modal title text ("Virtual Try-On" / "Your look").
data-close-icon-colorhex#9ca3afColour of the ✕ close button icon.
data-divider-colorhex / transparenttransparentColour of the horizontal line separating the modal header from the body. Set to transparent to hide.
data-powered-by-colorhex#9ca3afThe "Powered by" prefix text colour. The "OnFitt" brand name always stays in accent colour.

Dark modal example:

<script
  src="https://www.getonfitt.com/api/sdk"
  data-api-key="sk_live_..."
  data-theme="dark"
  data-accent-color="#f59e0b"
  data-modal-bg="#18181b"
  data-modal-title-color="#ffffff"
  data-close-icon-color="#71717a"
  data-divider-color="#27272a"
  data-powered-by-color="#52525b">
</script>

#Share

After a successful try-on, a Share your look button appears. On mobile it triggers the native share sheet; on desktop it shows a copy-link popover. Configure what gets shared:

AttributeTypeDefaultDescription

#Dashboard-driven config

Every attribute above can be set once in the Dashboard's Customize panel and applied globally. No code changes needed. The SDK fetches your saved config on init and caches it for 1 hour.

CTA Button

  • Theme (purple / dark / light / custom)
  • Custom colour + text colour
  • Border radius
  • Button label

Modal

  • Light / dark theme
  • Accent colour (spinner, CTAs, upload border)
  • Shop this look button colour (independent of accent)
  • Modal background
  • Title colour
  • Close icon colour
  • Divider line colour
  • "Powered by" text colour

Share

  • Share URL
  • Share message

Priority

  • Script-tag attributes always override dashboard settings
  • Dashboard settings fill any attributes not specified in the tag
  • Cached locally for 1 h (key: onfitt_cfg_{last8})

#API key security

Your API key is embedded in client-side HTML and is visible to anyone who views your page source. To prevent unauthorised use, configure a domain allowlist in the Dashboard's Security panel.

Important: Until you add at least one allowed domain, your API key will reject all requests. Set up your allowlist before going live.

Domain allowlist

  • Exact match: mystore.com
  • Wildcard subdomains: *.mystore.com
  • localhost is always allowed (no need to add it)
  • Up to 20 domains per key

How it works

  • The Origin header of every request is checked
  • Requests from unlisted origins get a 403 response
  • Blocked attempts are logged in the Security tab
  • You get an email alert the first time a new blocked origin is seen

#JavaScript API

Once the SDK script is loaded, window.OnFitt exposes two methods.

OnFitt.open(cfg)

Opens the try-on modal programmatically. Useful for custom button placements or testing.

OptionTypeDescription
apiKeystringRequired. Your OnFitt API key.
_clothingUrlsstring[]Array of product image URLs to try on.
theme / accentColor / modalBg / …stringAny of the theming options listed above.
// Open the modal with a specific product image
window.OnFitt.open({
  apiKey: "sk_live_...",
  _clothingUrls: ["https://yourstore.com/jacket.jpg"],
  accentColor: "#e11d48",
  modalBg: "#18181b",
  modalTitleColor: "#ffffff",
});

OnFitt.init(cfg)

Runs the full init flow (usage check, then remote config fetch, then button injection). Use this when loading the SDK dynamically.

const s = document.createElement("script");
s.src = "https://www.getonfitt.com/api/sdk";
s.onload = () => window.OnFitt.init({
  apiKey: "sk_live_...",
  clothingUrls: ["https://yourstore.com/jacket.jpg"],
});
document.head.appendChild(s);

#REST API reference

Full OpenAPI spec. Authenticate with your API key as Authorization: Bearer sk_live_....

Get your API key