TryItOn
Guides

Try-On Go Quickstart

Run a virtual try-on in Go using the official tryiton-go SDK: submit a job, wait for completion, and read the output image URLs.

This quickstart uses the official tryiton-go SDK to:

  1. Submit a try-on to the /tryon/clothes endpoint.
  2. Wait for the job to finish (the SDK polls /status/<id> for you).
  3. Read the output image URLs.

Install

go get github.com/tryiton-now/tryiton-go

Requires Go 1.20 or later. See all libraries on the SDKs page.

Minimal example

This example uses URLs for the model and garment images. You can also pass a base64 data URL (data:image/png;base64,...) for either image.

package main

import (
	"context"
	"errors"
	"fmt"
	"log"
	"os"
	"time"

	tryiton "github.com/tryiton-now/tryiton-go"
)

func main() {
	client, err := tryiton.New(os.Getenv("TRYITON_API_KEY"))
	if err != nil {
		log.Fatal(err)
	}

	ctx := context.Background()

	// 1. Submit the try-on
	jobID, err := client.TryOnClothes(ctx, tryiton.ClothesParams{
		ModelImage:   "https://example.com/model.jpg",
		GarmentImage: "https://example.com/garment.jpg",
		Category:     "clothing",
		Subcategory:  "tops",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Job started:", jobID)

	// 2. Wait for completion (polls status until done)
	urls, err := client.WaitForResult(ctx, jobID, 2*time.Second)
	if err != nil {
		// API and job failures are *tryiton.Error
		var apiErr *tryiton.Error
		if errors.As(err, &apiErr) {
			log.Fatalf("Failed (%d %s): %s", apiErr.Status, apiErr.Name, apiErr.Message)
		}
		log.Fatal(err)
	}

	// 3. Read the result image URLs (valid for 72 hours)
	fmt.Println("Result:", urls[0])
}

The same pattern works for the other models — call client.TryOnHairstyle(...) or client.TryOnTattoo(...) instead. See Hairstyle and Tattoo.

Prefer to poll yourself? Call client.GetStatus(ctx, jobID) in a loop instead of WaitForResult.

On this page