Authentication & API Keys
Authenticate virtual try-on API requests with a Bearer API key: create a key in the dashboard, call the API from your server, and rotate keys safely.
Every request to the TryItOn virtual try-on API carries an API key in the Authorization header. A key belongs to
your TryItOn account: every request made with it spends that account's credits and counts against its rate limits.
The API is built to be called from your server. Keep the key there.
Create an API key
Sign in and open Developer API → API Keys at tryiton.now/app/developer.
In the API Keys table, click + Create new API Key. Don't use Site Keys: those are for the storefront
widget and don't work with /api/v1 server endpoints.
Give the key a name (up to 50 characters), such as production-backend, and click Create Key.
Copy the key. It's shown only once. Store it in your secret manager or environment, then click I've saved my key.
Send the key
Send the key as a Bearer token on every request. The base URL for all endpoints is https://tryiton.now/api/v1.
Authorization: Bearer YOUR_API_KEYThe official SDKs set this header for you from the key you pass to the client.
Check your key with a first call
GET /credits is the cheapest way to check that a key works. It costs no
credits and returns your balance.
import { TryItOn } from "tryiton";
const client = new TryItOn({ apiKey: process.env.TRYITON_API_KEY });
const credits = await client.getCredits();
console.log(credits); // { on_demand, subscription, purchased, reserved }import os
from tryiton import TryItOn
client = TryItOn(api_key=os.environ["TRYITON_API_KEY"])
credits = client.get_credits()
print(credits) # Credits(on_demand=..., subscription=..., purchased=..., reserved=...)package main
import (
"context"
"fmt"
"log"
"os"
tryiton "github.com/tryiton-now/tryiton-go/v2"
)
func main() {
client, err := tryiton.New(os.Getenv("TRYITON_API_KEY"))
if err != nil {
log.Fatal(err)
}
credits, err := client.GetCredits(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", *credits)
}<?php
require 'vendor/autoload.php';
use TryItOn\Client;
$client = new Client(getenv('TRYITON_API_KEY'));
print_r($client->getCredits());require "tryiton"
client = Tryiton::Client.new(api_key: ENV.fetch("TRYITON_API_KEY"))
p client.get_creditscurl https://tryiton.now/api/v1/credits \
-H "Authorization: Bearer YOUR_API_KEY"A working key returns 200 with { "ok": true, "credits": { ... } }. A bad key returns 403.
Authentication errors
The API answers authentication problems with 403 Forbidden. It never returns 401 for a bad or missing key,
so handle 403 wherever your HTTP client handles auth failures.
| Status | error.name | error.message | Cause |
|---|---|---|---|
| 403 | Forbidden | Missing or invalid Authorization header. | No Authorization header, or it doesn't start with Bearer . |
| 403 | Forbidden | API key is invalid. | The key doesn't exist: mistyped, deleted, or a site key. |
| 403 | Forbidden | Your account has been disabled. Please contact support. | The account that owns the key is disabled. |
| 500 | InternalServerError | Failed to verify API key. | The key check itself failed on our side. Retry with backoff. |
Retrying a 403 with the same key won't help. Check the key and header, then fix the request. See
Error Codes & Handling for every error the API returns.
Keep the key on your server
Call the API from your backend, never from a browser or a mobile app bundle:
- Anyone who has the key can spend your credits. A key in front-end JavaScript or an app binary is public.
- Browsers are blocked anyway. The server endpoints only allow cross-origin requests from TryItOn's own sites,
so a
fetchfrom your web page fails the CORS check. - Mobile apps should call your own backend, which calls TryItOn with the key.
The one exception is live try-on. Your server starts the session with the API key, then passes the session's own short-lived credentials to the browser. The browser endpoints accept those credentials and are open to cross-origin requests. The API key never reaches the browser.
Key hygiene
- Load the key from the environment (
TRYITON_API_KEYin the samples) or a secret manager. Don't commit it to source control. - Use one key per service or environment and name it after where it runs. When a key leaks you can delete that one key without breaking the others.
- Don't log the
Authorizationheader. Redact it in request logging and error reporting. - Rotate by creating a new key. A key's value can't be regenerated. Create a new key, deploy it, confirm traffic works, then delete the old key with the delete icon in the API Keys table. A deleted key stops working right away.
- If a key leaks, delete it now, then create a replacement. Check Developer API → Requests in the dashboard for requests you don't recognise.
Related
SDKs
Official virtual try-on SDKs for Node.js, Python, Go, PHP and Ruby: packages, client options, error classes, wait helpers and the tryiton-live browser package.
Errors
Every virtual try-on API error code: HTTP status, error name, cause and fix, plus how each SDK raises errors and which requests are safe to retry.