Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ All notable changes to the `tryiton` Python SDK are documented here. The format

## [Unreleased]

## [2.2.0] - 2026-11-27

### Added

- `prepare_live_garment()` takes four optional keyword overrides: `detail_images` (up to 3 extra views that only
sharpen the description), `description` (your own item description, max 200 chars, used inside the generated
prompt), `instructions` (your own prompt, max 1000 chars, used verbatim) and `enhance_prompt` (`False` turns off the
stream's prompt rewriting; the API defaults to `True`).
- `prepare_live_outfit(garment_ids, *, instructions=None, enhance_prompt=None)` combines 2-3 prepared garments into
one outfit (`POST /live/outfits`). Its `id` works wherever a garment id does: `start_live_session(garment_id=...)`
and the browser's `switchGarment`.
- `LiveGarment` gains `prompt`, `enhancePrompt` and `items` (an outfit's garment ids top to bottom, else `None`).
`category` can be `"outfit"`.

### Deprecated

- `try_on_fashion(mode=..., moderation_level=...)`: the API ignores `mode` and validates `moderation_level` without applying it. Passing either now emits a `DeprecationWarning`; both are removed in 3.0.
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,42 @@ client.get_live_config() # {"enabled", "secondsPerCredi
Billing is per `secondsPerCredit` seconds of streamed video, from the first try-on frame. Garment switches during a
session are free.

`prepare_live_garment` also takes optional overrides:

```python
client.prepare_live_garment(
product_image_url,
category="footwear",
detail_images=[side_view_url, back_view_url], # up to 3 extra views; they only sharpen the description
description="black leather knee-high boots", # your description (max 200), used in the generated prompt
instructions="Replace only the shoes with the boots.", # or your own prompt (max 1000), used verbatim
enhance_prompt=False, # keep the prompt as-is (default True)
)
```

### Outfits

Combine 2-3 prepared garments into one outfit worn together. The outfit's `id` works wherever a garment id does
(`start_live_session`, the browser's `switchGarment`). To swap one item, prepare the new combination (cached) and
switch to it.

```python
top = client.prepare_live_garment(shirt_url, category="clothing", subcategory="tops")
trousers = client.prepare_live_garment(trousers_url, category="clothing", subcategory="bottoms")
shoes = client.prepare_live_garment(shoes_url, category="footwear")

outfit = client.prepare_live_outfit([top["id"], trousers["id"], shoes["id"]])
# outfit["category"] == "outfit", outfit["items"] = the garment ids top to bottom
start = client.start_live_session(garment_id=outfit["id"], end_user_id=shopper_id)

# Later the shopper picks another top: prepare that outfit and switch the running stream to it.
jacket = client.prepare_live_garment(jacket_url, category="clothing", subcategory="tops")
next_outfit = client.prepare_live_outfit([jacket["id"], trousers["id"], shoes["id"]])
# Send next_outfit["id"] to the browser, which calls live.switchGarment(id) (tryiton-live).
```

`prepare_live_outfit` also takes `instructions` and `enhance_prompt`, as above.

## Error handling

All failures raise `TryItOnError`, which carries the HTTP status code and the API error name.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "tryiton"
version = "2.1.0"
version = "2.2.0"
description = "Official Python SDK for the TryItOn virtual try-on API."
readme = "README.md"
requires-python = ">=3.8"
Expand Down
183 changes: 181 additions & 2 deletions tests/fixtures/sdk-cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,189 @@
"responses": [
{
"status": 201,
"body": { "ok": true, "garment": { "id": "g1", "category": "clothing", "subcategory": "tops", "description": "a navy polo", "createdAt": "2026-11-26T12:20:59.512Z" } }
"body": { "ok": true, "garment": { "id": "g1", "category": "clothing", "subcategory": "tops", "description": "a navy polo", "prompt": "Substitute the current top with a navy polo shown in the reference image, matching its color, material, and fit.", "enhancePrompt": true, "items": null, "createdAt": "2026-11-26T12:20:59.512Z" } }
}
],
"expectRequests": [
{ "method": "POST", "path": "/live/garments", "body": { "garment_image": "https://example.com/shirt.jpg", "category": "clothing", "subcategory": "tops" } }
],
"expectResult": { "id": "g1", "category": "clothing", "subcategory": "tops", "description": "a navy polo", "createdAt": "2026-11-26T12:20:59.512Z" }
"expectResult": { "id": "g1", "category": "clothing", "subcategory": "tops", "description": "a navy polo", "prompt": "Substitute the current top with a navy polo shown in the reference image, matching its color, material, and fit.", "enhancePrompt": true, "items": null, "createdAt": "2026-11-26T12:20:59.512Z" }
},
{
"name": "prepareLiveGarment with every override",
"method": "prepareLiveGarment",
"params": {
"garmentImage": "https://example.com/look.jpg",
"category": "footwear",
"detailImages": [
"https://example.com/boots-side.jpg",
"data:image/png;base64,AAAA"
],
"description": "black leather knee-high boots",
"instructions": "Replace only the shoes with the boots.",
"enhancePrompt": false
},
"responses": [
{
"status": 201,
"body": {
"ok": true,
"garment": {
"id": "g2",
"category": "footwear",
"subcategory": null,
"description": "black leather knee-high boots",
"prompt": "Replace only the shoes with the boots.",
"enhancePrompt": false,
"items": null,
"createdAt": "2026-11-26T12:20:59.512Z"
}
}
}
],
"expectRequests": [
{
"method": "POST",
"path": "/live/garments",
"body": {
"garment_image": "https://example.com/look.jpg",
"category": "footwear",
"detail_images": [
"https://example.com/boots-side.jpg",
"data:image/png;base64,AAAA"
],
"description": "black leather knee-high boots",
"instructions": "Replace only the shoes with the boots.",
"enhance_prompt": false
}
}
],
"expectResult": {
"id": "g2",
"category": "footwear",
"subcategory": null,
"description": "black leather knee-high boots",
"prompt": "Replace only the shoes with the boots.",
"enhancePrompt": false,
"items": null,
"createdAt": "2026-11-26T12:20:59.512Z"
}
},
{
"name": "prepareLiveOutfit returns the outfit",
"method": "prepareLiveOutfit",
"params": {
"garmentIds": [
"g1",
"g3"
]
},
"responses": [
{
"status": 201,
"body": {
"ok": true,
"outfit": {
"id": "o1",
"category": "outfit",
"subcategory": null,
"description": "a navy polo, black jeans",
"prompt": "Substitute the current top with a navy polo shown at the top and the current pants with black jeans shown at the bottom of the reference image, matching each item's color, material, and fit.",
"enhancePrompt": true,
"items": [
"g1",
"g3"
],
"createdAt": "2026-11-26T12:24:10.031Z"
}
}
}
],
"expectRequests": [
{
"method": "POST",
"path": "/live/outfits",
"body": {
"garment_ids": [
"g1",
"g3"
]
}
}
],
"expectResult": {
"id": "o1",
"category": "outfit",
"subcategory": null,
"description": "a navy polo, black jeans",
"prompt": "Substitute the current top with a navy polo shown at the top and the current pants with black jeans shown at the bottom of the reference image, matching each item's color, material, and fit.",
"enhancePrompt": true,
"items": [
"g1",
"g3"
],
"createdAt": "2026-11-26T12:24:10.031Z"
}
},
{
"name": "prepareLiveOutfit with overrides",
"method": "prepareLiveOutfit",
"params": {
"garmentIds": [
"g1",
"g3"
],
"instructions": "Dress them in the polo and jeans.",
"enhancePrompt": false
},
"responses": [
{
"status": 200,
"body": {
"ok": true,
"outfit": {
"id": "o1",
"category": "outfit",
"subcategory": null,
"description": "a navy polo, black jeans",
"prompt": "Dress them in the polo and jeans.",
"enhancePrompt": false,
"items": [
"g1",
"g3"
],
"createdAt": "2026-11-26T12:24:10.031Z"
}
}
}
],
"expectRequests": [
{
"method": "POST",
"path": "/live/outfits",
"body": {
"garment_ids": [
"g1",
"g3"
],
"instructions": "Dress them in the polo and jeans.",
"enhance_prompt": false
}
}
],
"expectResult": {
"id": "o1",
"category": "outfit",
"subcategory": null,
"description": "a navy polo, black jeans",
"prompt": "Dress them in the polo and jeans.",
"enhancePrompt": false,
"items": [
"g1",
"g3"
],
"createdAt": "2026-11-26T12:24:10.031Z"
}
},
{
"name": "startLiveSession returns the whole response unchanged",
Expand Down Expand Up @@ -194,6 +370,9 @@
"category": "clothing",
"subcategory": "tops",
"description": null,
"prompt": "p",
"enhancePrompt": true,
"items": null,
"createdAt": "2026-11-26T12:20:59.512Z",
"input": { "prompt": "p", "enhancePrompt": true, "referenceImage": "data:image/jpeg;base64,AA" }
}
Expand Down
6 changes: 6 additions & 0 deletions tests/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"waitForResult": "wait_for_result",
"getLiveConfig": "get_live_config",
"prepareLiveGarment": "prepare_live_garment",
"prepareLiveOutfit": "prepare_live_outfit",
"startLiveSession": "start_live_session",
"getLiveSession": "get_live_session",
"stopLiveSession": "stop_live_session",
Expand Down Expand Up @@ -55,6 +56,11 @@
"maxSeconds": "max_seconds",
"endUserId": "end_user_id",
"allowedOrigin": "allowed_origin",
"detailImages": "detail_images",
"description": "description",
"instructions": "instructions",
"enhancePrompt": "enhance_prompt",
"garmentIds": "garment_ids",
}

# Extra kwargs per method, so polling cases run instantly.
Expand Down
2 changes: 1 addition & 1 deletion tryiton/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"LiveSessionStart",
]
# Single source of the SDK version (sent in the User-Agent); keep it equal to pyproject.toml.
__version__ = "2.1.0"
__version__ = "2.2.0"
49 changes: 44 additions & 5 deletions tryiton/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,64 @@ def prepare_live_garment(
*,
category: Optional[str] = None,
subcategory: Optional[str] = None,
detail_images: Optional[List[str]] = None,
description: Optional[str] = None,
instructions: Optional[str] = None,
enhance_prompt: Optional[bool] = None,
) -> LiveGarment:
"""Prepare a garment for live try-on. Returns the garment dict.

Do it once per product ahead of time (e.g. at catalog sync): it's cached
per image and category, so starting a session or switching garments
later is instant. `garment_image` is a URL or base64 data URL. Passing
`category` (and `subcategory`, e.g. "tops") is recommended; omit it to
let it be detected.
per image, category and overrides, so starting a session or switching
garments later is instant. `garment_image` is a URL or base64 data URL.
Passing `category` (and `subcategory`, e.g. "tops") is recommended; omit
it to let it be detected.

Optional overrides: `detail_images` is up to 3 extra views (URLs or data
URLs) that only sharpen the description. `description` (max 200 chars)
is your own item description, used inside the generated prompt.
`instructions` (max 1000 chars) is your own prompt, used verbatim
instead of the generated one. `enhance_prompt=False` stops the stream
from rewriting the prompt (the API defaults to True).

The dict has ``id`` (pass it to start_live_session), ``category``,
``subcategory``, ``description`` and ``createdAt``.
``subcategory``, ``description``, ``prompt``, ``enhancePrompt``,
``items`` (None for a single garment) and ``createdAt``.
"""
body = {
"garment_image": garment_image,
"category": category,
"subcategory": subcategory,
"detail_images": detail_images,
"description": description,
"instructions": instructions,
"enhance_prompt": enhance_prompt,
}
return cast(LiveGarment, self._request("POST", "/live/garments", body)["garment"])

def prepare_live_outfit(
self,
garment_ids: List[str],
*,
instructions: Optional[str] = None,
enhance_prompt: Optional[bool] = None,
) -> LiveGarment:
"""Combine 2-3 prepared garments into one outfit worn together.

Returns the outfit as a garment dict with ``category`` "outfit" and
``items`` = the garment ids top to bottom. Its ``id`` works wherever a
garment id does (start_live_session, the browser's switchGarment).
It's cached per set of garments and overrides, so swapping one item is
preparing the new set and switching to it. `instructions` and
`enhance_prompt` work as in prepare_live_garment.
"""
body = {
"garment_ids": list(garment_ids),
"instructions": instructions,
"enhance_prompt": enhance_prompt,
}
return cast(LiveGarment, self._request("POST", "/live/outfits", body)["outfit"])

def start_live_session(
self,
*,
Expand Down
7 changes: 5 additions & 2 deletions tryiton/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ class LiveConfig(TypedDict):


class LiveGarment(TypedDict):
"""A garment prepared for live try-on."""
"""A garment (or outfit) prepared for live try-on."""

id: str
category: str
category: str # the item's category, or "outfit" for a prepare_live_outfit result
subcategory: Optional[str]
description: Optional[str]
prompt: str # the prompt the stream uses
enhancePrompt: bool # whether the stream rewrites `prompt`
items: Optional[List[str]] # an outfit's garment ids, top to bottom; None for a single garment
createdAt: str # ISO 8601


Expand Down
Loading