Send a message to the agent
/v2/agent/chatRuns one agent turn over the conversation you send. The agent may read
what the store stocks, search the catalogue privately, put chosen
products on screen, compose an outfit into one or more looks, ask the
shopper a structured question, work out a size, offer follow-up chips,
and, when a cart snapshot is present, read or change the cart. All of
that happens server-side inside a single request; tool results go back
into the model before it writes, capped at ten model calls per turn.
The model
The turn runs on the chat model chosen in the organization's Stylor
settings (AI models), or the default, Claude Haiku 5.5, when none is
chosen. Stylor Ultrafast answers many turns without the agent loop:
it routes the turn, searches, puts cards up and writes one line, and
hands the turn to the agent only when it needs one. Both paths use
the same events and the same history, so a client does not need to
know which one answered.
Streaming
The response streams by default. It is text/event-stream and each
thing the agent does arrives as its own event — see the
streaming guide and the event
catalogue below. Pass stream: false to receive one JSON body once the
turn has finished.
Conversation state
You own the conversation state. The turn ends with a replay-ready
history array (on the done event, or in the JSON body). Send it
back verbatim as messages on the next request, with the shopper's
new message appended, and the conversation continues. There is no
server-side chat id and nothing is stored between requests.
Dataset scope
datasetIds narrows the catalogue the agent works from. Without it,
store (the storefront the shopper is on) narrows it to that store's
active datasets, and without either every active dataset is used. An
invalid or archived dataset scope does not fail the request: the
agent's tools report the problem to the model (you will see it on
tool_output), and the model answers without catalogue data.
The shopper's language
Send language (on a Shopify storefront, Shopify.locale) and the
agent writes everything the shopper reads in it: replies, status
notes, chips, and the questions and options on cards. Product names,
brands and sizes stay as the store writes them, and the agent's tool
arguments stay in English.
Adding to the cart without a model call
Send add beside the shopper's message (with a cart snapshot and
stream on) and the turn is a cart add with no model call, as the
widget's "Add to cart" and "Add all to cart" buttons do. Pieces whose
size is known are added at once as cart_action events; otherwise
one cart_sizes card asks for the sizes. See the
cart guide.
Prices in the shopper's country
Send country (on a Shopify storefront, Shopify.country) and every
product in search_results, looks and the tool outputs, the prices
on cart actions, the sizes in stock and the sale information are the
shopper's market's. Without it the store's default market's prices
come back, flagged product.marketExact: false. An unrecognised
country is treated as absent, never as an error. See
Introduction.
Metering
One request consumes one unit of api.v2.agent.chat
regardless of how many tool calls the turn takes. The rate-limit
headers are set on the stream response as well as on JSON responses.
This resource is separate from v1 chat, so v2 usage never draws down
your POST /v1/chat allowance and vice versa.
Where errors arrive
Authentication, quota and validation failures
are decided before any stream exists, so they always come back as an
ordinary JSON error with the right HTTP status. Check Content-Type
before you attach an SSE reader. Once the stream has started the
status is already 200; a failure mid-run is delivered as an error
event and the stream closes without a done event.
The widgets' switch
A request that carries the widget's sessionToken is a widget's turn.
When the organization has switched its widgets off in its Stylor
settings, such a request is refused with 403 and
"code": "widget_disabled" beside error. A request without a
sessionToken is an API call and is never refused by the switch.
The token is read after the API key is authenticated, and only a
token issued for the key's own organization counts: one from another
organization is ignored, like an invalid or expired token, and the
turn runs as an ordinary API call.
Request body
application/jsonrequiredThe whole conversation so far: the previous turn's history, if
any, followed by the shopper's new message. On the first turn this
is a single UserMessage.
Restrict the agent to these datasets. Omit or send [] to use every
active dataset in the organization, narrowed to one store when
store is sent. When present, these always win over store.
Must be an array of strings when present (null is refused with
422). An id that is not the organization's does not fail the
request; the agent's tools report the problem to the model instead.
A snapshot of the shopper's cart. Sending one — even an empty cart
with items: [] — enables the cart tools for this turn; omitting it
or sending null leaves the agent with no cart capability at all.
The server does not validate the snapshot: any non-null value enables
the tools, and a malformed one makes the cart tools report errors to
the model (visible on tool_output) rather than failing the request.
See the cart guide.
Option 1: CartSnapshot
Total units across all lines.
Cart total in major currency units.
ISO 4217 currency code for total and each line's price.
The cart lines. May be empty.
Option 2: null
How much the model reasons before it acts, for this turn. Left out
(null, false or absent), the level saved in the organization's
settings is used, else the chat model's own default: low for
Claude Haiku 5.5 (the default model) and Stylor Ultrafast, whose
router chooses none or low per turn; none for Claude Sonnet
5.5; none (or the lowest level it accepts) for the GPT models.
none is the fast option: nothing then sits between the request
and the first word, about 700 ms sooner, at the cost of an
occasional dead turn. true means low (or the model's lowest
level); a string picks a level, in any case. Accepted levels
depend on the model and are checked before the run: an
unsupported one is a 422 naming the accepted ones. Stylor
Ultrafast accepts only none and low, and GPT-6.1 Sol has no
none. With thinking on, the reasoning is summarised and streamed
as thinking, thinking_delta and thinking_break events so the
wait is visible.
Option 1: string
Option 2: boolean
Option 3: null
What the shopper is looking at. Send product when the chat is open
on a product page and the agent treats "this" and "it" as that
product, answering questions about its price, options and
availability without a lookup. It is context only: it enables no
tools. The server reads the fields below by name, clamps them, and
ignores everything else; a product without a title is ignored.
The Stylor widget fills this from the storefront's
/products/{handle}.js.
Omitted, true or any other truthy value streams Server-Sent Events.
false — or any falsy value such as null or 0 — returns one JSON
body when the turn is complete.
The analytics session this visit belongs to — the
session.sessionId returned by the v1 widget preflight — so events
the server records line up with events your storefront reports for
the same visit. Never used for authorization. It also binds cart
intent tokens: without it, cart actions carry intent: null and
their outcomes cannot be reported.
Visit metadata for analytics. Ignored unless it is useful to you.
Option 1: Session
Where the shopper is talking to the agent. Defaults to widget when omitted.
Which agent version your client is built against. Use v2.
How your client persists the visit id — for example memory, session or local. Defaults to memory.
The shopper's IANA time zone.
The shopper's BCP 47 locale.
A coarse device class, typically mobile or desktop.
Option 2: null
Which store the shopper is on, for an organization that runs
several stores under one key. origin is the storefront page's
origin (window.location.origin) and shop is Shopify's
permanent shop domain (Shopify.shop, e.g.
kit-and-ace.myshopify.com), which still identifies the store when
it serves from a different domain. When datasetIds is empty,
the agent searches only that store's active datasets and speaks as
that store. If neither matches a dataset, every active dataset is
used; when those belong to several stores, the agent says it
represents several stores, names the store each product comes
from, and points policy questions to that store's own site.
Ignored when datasetIds is sent. It can only narrow within your
own organization, never widen it. The Stylor chat embed sends it.
Option 1: object
Option 2: null
The shopper's country, ISO 3166-1 alpha-2 in any case (US, ca).
On a Shopify storefront, read it from Shopify.country. Every
product the agent finds, shows or puts in a look is priced in that
shopper's market: price, currency, each variant's price,
compareAtPrice and inStock, the sizes it offers, the prices on
cart actions, and onSale / discount. The lookup_products
tool's minPrice and maxPrice are in that currency, and its
onSale argument finds products reduced for this shopper.
Products their market does not sell are not shown. Omitted, or
for a country the store does not sell into, products carry the
store's default market's prices, flagged
product.marketExact: false. A value that is not a two-letter
code is treated as unknown, not refused.
The language the store page is shown in, as a language tag
(fr, de-CH, pt-BR); on a Shopify storefront, Shopify.locale.
The agent writes everything the shopper reads in it (replies,
status notes, chips, card questions and options) while searching
in English. English, an unknown tag or none leaves it in English.
The shopper's profile token, from a profile event or the v1
shopper profile endpoints. With it the agent knows the sizes,
taste and facts kept for this shopper and ranks results by their
taste. It opens only its own profile, in this organization. Absent,
the turn starts a profile when there is something worth keeping
and sends its token on a profile event. Ignored when the
organization has switched shopper profiles off.
The visit's signed analytics session token, from the v1 widget
preflight. It marks the turn as the widget's: refused with 403
when the organization has switched its widgets off, and filed
under the visit's holdout arm in analytics. Only a token issued
for the API key's organization counts; any other is ignored.
Leave it out for your own integration.
Makes the turn a cart add with no model call, as the widget's "Add
to cart" buttons do. Needs a cart snapshot and the streamed
response. Put the shopper's words as the last message as usual
("Add the Coastal Linen Shirt to my cart"); the history records
the add as an add_to_cart call. Pieces whose size is known
(size, or one the shopper gave earlier) are added at once as
cart_action events; otherwise one cart_sizes card asks. Answer
that card by sending add again with every piece's size.
The pieces to add.
Keep the sizes picked on the shopper's profile as their sizes at this store.
Response
stream omitted or true: a Server-Sent Events stream. With
stream: false: one JSON body describing the whole turn.
Response headers
X-RateLimit-ResourceThe quota resource this endpoint is metered against: api.v2.agent.chat
for the chat endpoint, api.v2.agent.looks.render for the looks
endpoint (api.v2.agent.looks on a plan not yet moved to it),
api.v2.agent.match for shop the look, api.v2.agent.looks.complete
for complete the look and api.v2.agent.pose for the pose endpoint.
These are separate from the v1 resources, so Agent API usage never
draws down a v1 allowance.
X-RateLimit-Quota-LimitRequests allowed in the current billing period, or unlimited.
X-RateLimit-Quota-RemainingRequests left in the current billing period, or unlimited.
X-RateLimit-Quota-ResetUnix epoch seconds at which the billing period resets.
X-RateLimit-RPM-LimitRequests allowed per minute for this resource.
X-RateLimit-RPM-RemainingRequests left in the current one-minute window.
X-RateLimit-RPM-ResetUnix epoch seconds at which the one-minute window resets.
text/event-streamevent: <name>\ndata: <json>\n\n frames, one per event, in the
order listed under Stream events. The stream closes after
done (success) or error (failure). Cache-Control: no-cache
and Connection: keep-alive are set.
application/jsonThe assistant's final text. May be empty when a row or a card was the whole answer.
Replay-ready conversation. Send it back as messages next turn.
Every product row the agent displayed, in order.
Heading for the row.
outfit — worn together; list — alternatives to choose between.
outfitlistRepeats label.
Number of entries in results.
Every look the agent composed. Render each with the looks endpoint.
Name of the look; pass it to the looks endpoint.
The garments worn together, as full Product records. Pass their
itemIds to the looks endpoint. Each also carries lookColour
(the colour the look shows it in, or null; pass it in the looks
endpoint's colours), lookImageKey (a storage key for its photo
in that colour) and lookImageBox (where the piece is in that
photo, [x0, y0, x1, y1] fractions, or null), and its
product.url links to that colour.
The agent's direction for the renderer, including a garment the shopper owns, how pieces sit, the setting. Pass it through to the looks endpoint unchanged.
A garment of the shopper's own the look includes, or null. Pass { slot } to the looks endpoint as ownPiece.
The store's house basics the look wears (plain pieces the merchant set up, such as shoes added to a look that has none), listed beside the picture as not sold here. Pass their text values to the looks endpoint as basics.
Question cards the agent asked (at most one per turn in practice).
The first question's options. Two or more, or none when that question has only fields or free text.
Whether the shopper may type their own answer instead of picking an option.
Present only when the card asks more than one question, or when
any question has fields. Every question, in order, including the
first, which question, options and allowFreeText above
repeat. Answer all of them and reply once, a line per answer: a
choice as <topic>: <label> (the question itself, less its final
punctuation, when it has no topic), then each field as
<field label>: <value>.
Every follow-up chip offered this turn, from suggest_replies and from those attached to product rows and looks, in order.
The profile event's payload when the turn made a shopper profile, else null. Keep its token.
The profile_save event's payload when the agent asked to save the profile, else null.
Sizes cards (cart_sizes) the agent put up instead of adding to the cart.
The card's heading, in the shopper's language.
Whether the shopper has a profile the sizes can be kept on (add.save).
Every piece being added, in the order asked.
Which arm of Stylor's own styling experiment the turn ran on.
Stream events
20Each frame is event: <name> followed by data: <json> and a blank line. Events are listed in the order they normally arrive.
settingsThe organization's settings that change what the client should
offer, sent first when one applies. Today the only one is
profiles: false: the organization has switched shopper profiles
off, so keep nothing about the shopper (no profile token, no "save
your profile" offer). Not sent when profiles are on.
{
"profiles": false
}thinkingThe model started (status: started) or finished (status: done)
a stretch of reasoning. Sent on every turn that reasons, which
depends on the turn's thinking level (see thinking on the
request; most models reason by default). On Stylor Ultrafast the
pair is always sent and spans the routing and the first search,
whatever the level. Show a "thinking" state between the two; a
summary may or may not follow, so this pair is the reliable
signal. The stretch ends when text or a tool call begins.
{
"status": "started"
}thinking_deltaA chunk of the model's reasoning summary, in order, between a
thinking start and done. Written for a reader, not the raw chain
of thought, and not part of the reply. Only on a turn that reasons.
{
"delta": "They want a dinner look; I'll check dresses and heels first."
}thinking_breakThe reasoning summary began a new paragraph. The payload is empty. Only on a turn that reasons.
{}text_deltaA chunk of the assistant's reply, in order. Append the chunks to
render the reply as it is written. The reply can come before the
tools' cards or after them, so treat a tool_called event as the
end of the current paragraph.
{
"delta": "All three are linen, so they will breathe on a warm afternoon."
}noteA few words the model wrote on the way to a tool call, such as
"Finding relaxed black tees". Show it as a passing status line,
not as part of the reply: it is not in output, and a later
note or the reply replaces it.
{
"text": "Finding linen shirts"
}tool_calledThe model invoked a tool. arguments is the raw JSON string the
model produced (parse it if you need the values), or null. Useful
for showing progress, for instance "Searching…" while
lookup_products runs.
Tool names: get_articles, get_colors, get_details,
lookup_products, find_product, view_product, read_products,
show_products, create_looks, ask_question and
suggest_replies; remember and save_profile unless shopper
profiles are off; size_from_brands, ask_brand_sizes and
shoe_size (or size_from_measurements and shoe_size when the
store has switched sizing from other brands off);
list_store_pages and read_store_page when the catalogue is
synced from one Shopify store; view_items on Stylor Ultrafast
for a store of 150 products or fewer; and, only when a cart was
sent, get_cart, add_to_cart, set_cart_quantity,
change_cart_size and remove_from_cart.
Stylor Ultrafast also sends three status steps that are not tools:
read_request (while it reads the message), and plan_looks or
plan_reply (while the agent plans a turn it took over). They
carry arguments: null and no tool_output follows them.
Anything a tool draws on screen (viewing, search_results,
looks, question, brand_sizes, suggestions, cart_action,
cart_sizes, profile, profile_save) is emitted between that
tool's tool_called and tool_output. When the model calls
several tools in one step, every tool_called for that step
arrives first, then the tools' display events in the order the
tools produce them, then every tool_output, so match display
events by their type, not by position.
{
"name": "lookup_products",
"arguments": "{\"query\":\"linen wedding shirt\",\"slot\":null,\"family\":[\"shirt\"],\"age_group\":null,\"gender\":\"mens\",\"colors\":null,\"pattern\":null,\"fit\":null,\"materials\":[\"linen\"],\"features\":null,\"minPrice\":null,\"maxPrice\":300,\"onSale\":null,\"exclude_terms\":null,\"limit\":8}"
}viewingThe pieces the agent is looking at while it decides, from
view_items (Stylor Ultrafast, small stores). Not an answer: show
them as a row of thumbnails beside the status line. id is the
13-character reference the agent names the piece by in its later
tool calls (create_looks), thumb a storage key for the piece's
photo in the colour it is weighing (turn it into a URL with
https://stylor.ai/api/v1/image/<key>). Pieces the shopper cannot
buy are left out. Several can arrive in one turn.
{
"items": [
{
"id": "8f2c1a9e-4b7d",
"name": "Coastal Linen Shirt",
"thumb": "org_5f3a/ds_9c21/8f2c1a9e-4b7d/0.jpg"
}
]
}search_resultsA row of products to display, from show_products. kind is
outfit when the items are meant to be worn together (at most one
per slot) or list when they are alternatives to choose between;
render them differently. query repeats label. results holds
full Product records in the order the agent chose, which is part of
the recommendation. A product shown in a colour other than its
default carries that colour as cardColour, with its photos and
link for that colour. The agent may emit several rows in one turn.
{
"label": "Wedding shirts",
"kind": "list",
"query": "Wedding shirts",
"count": 3,
"results": [
{
"itemId": "8f2c1a9e-4b7d-4c1e-9a3f-2d6b7e5c1a90",
"datasetId": "9c21f0aa-3e4b-4d2a-b6d1-0f7e8a9b1c2d",
"status": "active",
"metadata": {
"gender": "mens",
"color_family": "navy",
"slot": "top",
"family": "shirt"
},
"product": {
"name": "Coastal Linen Shirt",
"url": "https://shop.example.com/products/coastal-linen-shirt",
"price": 89,
"currency": "USD",
"variants": [
{
"variantId": "gid://shopify/ProductVariant/41611609636909",
"sku": "CLS-NVY-M",
"label": "M / Navy",
"options": [
{
"name": "Size",
"value": "M"
},
{
"name": "Color",
"value": "Navy"
}
],
"inStock": true,
"quantity": 4,
"price": 89,
"compareAtPrice": null
}
],
"assets": {
"images": [
{
"uploaded": {
"key": "org_5f3a/ds_9c21/8f2c1a9e-4b7d/0.jpg"
}
}
]
}
}
}
]
}suggestionsTwo to four follow-up chips, written in the shopper's voice. Emitted
by suggest_replies, alongside search_results and looks when
the agent attached chips to them, and by Stylor Ultrafast after its
line. When tapped, send the chip text as the next user message. A
turn can emit this more than once; keep the latest.
{
"suggestions": [
"Show me trousers to match",
"Something more formal",
"Cheaper options"
]
}questionA card from ask_question. The agent has stopped to wait for an
answer, so the turn ends shortly after this event. Render the
options; when the shopper picks one, send the option's label
(or their typed text if allowFreeText) as the next user message.
questionId is unique per card, for your own bookkeeping.
A card can carry several questions (typically a size for each
piece of an outfit) or questions with fields (sliders for body
measurements). It then has a steps array holding every question,
the first included, and question, options and allowFreeText
repeat the first so a client that ignores steps still shows
something answerable. Collect an answer to every step and send
them as ONE user message, one line per answer in order:
<topic>: <label> for a choice and <field label>: <value> for
each field, e.g. Shirt size: M / White. Do not send them as
separate messages; the agent acts on the full set. See
QuestionCard.
{
"questionId": "5f0e8c3a-2b1d-4e7f-9a6c-3d2e1f0a9b8c",
"question": "Who am I styling for?",
"options": [
{
"label": "Menswear",
"value": "mens"
},
{
"label": "Womenswear",
"value": "womens"
}
],
"allowFreeText": false
}brand_sizesThe sizes card, from ask_brand_sizes: it asks the sizes the
shopper wears at other brands, a row per garment, so the agent can
work out their size here. The turn ends after it. garments are
the rows, kinds and fits the choices offered for each answer,
brands the brands to pick from (with their logos unless logos
is false), saved the sizes already on the shopper's profile,
and department (womens, mens or null, which means ask)
whose sizes they are. Send the answer as one user message: a first
line Sizes I wear (womenswear): (or (menswear), or no
department), then one line per size as
- <brand> <garment>: <size>, fits <tight|right|loose>, for
example - Levi's jeans: 32, fits right.
{
"cardId": "0b9c1f7e-4d2a-4c1b-8e55-7a1d2c3b4e5f",
"title": "Which brands do you wear?",
"department": "womens",
"kind": null,
"garments": [
{
"value": "jeans",
"label": "Jeans",
"part": "bottom",
"kind": "jeans"
}
],
"kinds": [
{
"value": "tops",
"label": "Tops"
},
{
"value": "jeans",
"label": "Jeans"
},
{
"value": "trousers",
"label": "Trousers"
},
{
"value": "dresses",
"label": "Dresses"
},
{
"value": "outerwear",
"label": "Jackets"
},
{
"value": "suits",
"label": "Suit jackets"
}
],
"fits": [
{
"value": "tight",
"label": "Tight"
},
{
"value": "right",
"label": "Right"
},
{
"value": "loose",
"label": "Loose"
}
],
"brands": [],
"logos": true,
"saved": []
}looksOne or more complete outfits the agent wants rendered. Each look
carries its label, its full Product records in items, and
customInstructions (the agent's direction for anything the
product photos cannot show, or null); see Look for ownPiece
and basics. tryOn says whether the store lets shoppers see
looks on their own photo (userPhotoUrl on the looks endpoint).
Nothing has been rendered yet: call POST /v2/agent/looks once
per look, passing the items' itemIds, the label,
customInstructions, ownPiece and the basics' text, and show
each image as it returns. Send each item's lookColour in the
looks endpoint's colours so the picture shows the colour listed.
The items may include pieces that were never shown as cards.
{
"looks": [
{
"label": "Garden wedding",
"items": [
{
"itemId": "8f2c1a9e-4b7d-4c1e-9a3f-2d6b7e5c1a90",
"product": {
"name": "Coastal Linen Shirt",
"price": 89,
"currency": "USD"
}
},
{
"itemId": "1b7e33c0-9a2d-4f8e-b5c6-7d8e9f0a1b2c",
"product": {
"name": "Everyday Chino",
"price": 79,
"currency": "USD"
}
},
{
"itemId": "c4d5e6f7-0a1b-4c2d-8e9f-0a1b2c3d4e5f",
"product": {
"name": "Suede Loafer",
"price": 129,
"currency": "USD"
}
}
],
"customInstructions": "Shirt untucked with the top button open; outdoor daylight setting.",
"ownPiece": null,
"basics": []
}
],
"tryOn": true
}cart_actionThe agent read or wants to change the shopper's cart. Only possible
when the request carried a cart snapshot. action is one of
read, add, quantity, swap or remove, and the rest of the
payload depends on it; see the CartAction schema. A read is
already satisfied (it was answered from your snapshot) and can be
shown as a receipt. Every other action is a request: the server
has verified the item, variant and stock, but your client must
perform the change on the storefront and show the outcome. Every
action but read carries an intent token (or null when no
sessionId was sent) for reporting the result; see the
cart guide.
{
"action": "add",
"itemId": "8f2c1a9e-4b7d-4c1e-9a3f-2d6b7e5c1a90",
"name": "Coastal Linen Shirt",
"url": "https://shop.example.com/products/coastal-linen-shirt?variant=41611609636909",
"sku": "CLS-NVY-M",
"size": "M / Navy",
"shown": "M · Navy",
"quantity": 1,
"price": 89,
"currency": "USD",
"image": "org_5f3a/ds_9c21/8f2c1a9e-4b7d/0.jpg",
"intent": "eyJ2IjoxLCJqdGkiOiI3ZjFlIn0.q8vT2rN9…"
}cart_sizesThe card that gathers the sizes still missing before a cart add,
from add_to_cart or a cart add request (add). Every piece being
added is a row in items, with its sizes in the colour shown
(sold-out sizes have inStock: false), the likeliest size in
picked and a runner-up in alternative. Rows already sized have
ready: true; rows that cannot be added have unavailable: true.
canSave says whether the sizes can be kept on the shopper's
profile. Answer with a cart add request: send add with each
piece's id, colour and the size picked (and save: true to
keep them). See CartSizesCard.
{
"cardId": "2e3f4a5b-6c7d-4e8f-8a9b-0c1d2e3f4a5b",
"title": "Pick your size",
"canSave": false,
"items": [
{
"id": "8f2c1a9e-4b7d",
"name": "Coastal Linen Shirt",
"image": "org_5f3a/ds_9c21/8f2c1a9e-4b7d/0.jpg",
"colour": "Navy",
"quantity": 1,
"sizes": [
{
"label": "S",
"inStock": true
},
{
"label": "M",
"inStock": true
},
{
"label": "L",
"inStock": false
}
],
"picked": "M",
"alternative": "S",
"note": null,
"concern": null,
"colours": [],
"ready": false,
"unavailable": false
}
]
}profileThe turn made a shopper profile (the agent kept something the
shopper said, or a size). Store token in the shopper's browser
and send it as profile on later requests, so the agent remembers
them. Only sent when no profile token was sent and profiles are
on.
{
"token": "eyJwIjoiN2YxZSJ9.c2lnbmF0dXJl",
"kind": "visitor",
"created": true
}profile_saveFrom save_profile: show a card that saves the shopper's profile
to their email (intent: save) or opens one saved before
(intent: sign_in). reason is one short line for the card. The
email and code steps go through the v1 shopper profile endpoints.
{
"reason": "Keep your sizes and styles for next time",
"intent": "save"
}tool_outputA tool call finished. output is the value the model saw: usually an
object with a note written for the model, sometimes an error key
when the tool could not do its job (for example an invalid dataset
scope). Product searches return compact summaries here, never full
products; the full records travel on search_results. On Stylor
Ultrafast a search's output is only { "count": n }. output is a
plain string rather than an object when the tool could not run at
all, for example when the model produced arguments that failed
validation, in which case it reads An error occurred while running
the tool. Please try again. Error: …. The agent sees that text and
usually retries; it does not end the stream. Pictures a tool showed
the model (a size chart page) are never sent: a line of text stands
in for each.
{
"name": "lookup_products",
"output": {
"count": 8,
"items": [
{
"id": "8f2c1a9e-4b7d",
"description": "Coastal Linen Shirt — navy, linen, relaxed fit, $89"
}
],
"note": "The shopper saw NOTHING — this was for your eyes only."
}
}doneThe turn finished. output is the assistant's final text (may be an
empty string when a card or a row was the whole answer) and
history is the complete, replay-ready conversation: every user
message, assistant message, tool call and tool result. Store
`history` and send it back as `messages` on the next turn. The
stream closes after this event.
{
"output": "All three are linen, so they will breathe on a warm afternoon.",
"history": [
{
"role": "user",
"content": "I need something for a summer wedding, menswear, under $300."
},
{
"type": "function_call",
"callId": "call_8kP2wN7r",
"name": "show_products",
"arguments": "{\"label\":\"Wedding shirts\",\"kind\":\"list\",\"itemIds\":[\"8f2c1a9e-4b7d\",\"1b7e33c0-9a2d\",\"c4d5e6f7-0a1b\"],\"suggestions\":[\"Show me trousers to match\",\"Something more formal\"]}",
"status": "completed"
},
{
"type": "function_call_result",
"callId": "call_8kP2wN7r",
"name": "show_products",
"status": "completed",
"output": {
"type": "text",
"text": "{\"shown\":3,\"note\":\"3 cards are now on the shopper's screen under \\\"Wedding shirts\\\".\"}"
}
},
{
"type": "message",
"role": "assistant",
"status": "completed",
"content": [
{
"type": "output_text",
"text": "All three are linen, so they will breathe on a warm afternoon."
}
]
}
]
}errorThe run failed after the stream had started, for example the model
exceeded the ten-call cap or the model provider returned an error.
The HTTP status is already 200; this event is the only signal. The
message is always Agent run failed.; the cause is logged on our
side. No done follows and no history is returned, so replay the
previous turn's history plus the shopper's message to retry. The
stream closes after this event.
{
"error": "Agent run failed."
}Errors
28Every error is JSON with a single error string unless noted. Match on the status code; the message is for humans.
Request body must be valid JSON.The body could not be parsed as JSON.
Request body must be a JSON object.The body is empty, or is valid JSON that is not an object (for example an array).
The widget is switched off in this organization's Stylor settings.sessionToken is a valid widget session issued for the API key's organization, and that organization has switched its widgets off. The body also carries "code": "widget_disabled". Checked after the API key; the request uses no quota.
messages must be an array.messages is missing or not a JSON array. Returned as JSON even when streaming was requested.
messages cannot be empty.messages is an empty array, or, on a cart add (add), missing or not an array. Returned as JSON even when streaming was requested.
datasetIds must be an array of strings.datasetIds was sent and is not an array of strings (for example null). Returned as JSON even when streaming was requested.
thinking must be one of <efforts> for <model>, or true/false.thinking is a string the organization's chat model does not accept, or a value of another type. The accepted levels are listed, comma-separated.
add needs the cart snapshot.add was sent without a cart.
add.items must be an array.add is not an object or its items is not an array.
add.items needs at least one item id.No entry of add.items has a usable id.
add.items takes at most 8 items.add.items has more than eight entries with an id.
add is only taken on the streamed chat.add was sent with stream: false. A cart add's writes travel as stream events.
curl -X POST "https://stylor.ai/api/v2/agent/chat" \
-H "Authorization: Bearer $STYLOR_API_KEY" \
-H "Content-Type: application/json" \
-N \
-d '{
"messages": [
{
"role": "user",
"content": "I need something for a summer wedding, menswear, under $300."
}
],
"datasetIds": [
"9c21f0aa-3e4b-4d2a-b6d1-0f7e8a9b1c2d"
],
"sessionId": "3b0d4a1e-6f52-4b8a-9d3c-7e2f1a0b9c8d",
"session": {
"surface": "widget",
"agentVersion": "v2",
"storageMode": "local",
"tz": "America/Toronto",
"locale": "en-CA",
"device": "desktop"
}
}'event: settings
data: {"profiles":false}
event: thinking
data: {"status":"started"}
event: thinking_delta
data: {"delta":"They want a dinner look; I'll check dresses and heels first."}
event: thinking_break
data: {}
event: text_delta
data: {"delta":"All three are linen, so they will breathe on a warm afternoon."}
event: note
data: {"text":"Finding linen shirts"}
event: tool_called
data: {"name":"lookup_products","arguments":"{\"query\":\"linen wedding shirt\",\"slot\":null,\"family\":[\"shirt\"],\"age_group\":null,\"gender\":\"mens\",\"colors\":null,\"pattern\":null,\"fit\":null,\"materials\":[\"linen\"],\"features\":null,\"minPrice\":null,\"maxPrice\":300,\"onSale\":null,\"exclude_terms\":null,\"limit\":8}"}
event: viewing
data: {"items":[{"id":"8f2c1a9e-4b7d","name":"Coastal Linen Shirt","thumb":"org_5f3a/ds_9c21/8f2c1a9e-4b7d/0.jpg"}]}
event: search_results
data: {"label":"Wedding shirts","kind":"list","query":"Wedding shirts","count":3,"results":[{"itemId":"8f2c1a9e-4b7d-4c1e-9a3f-2d6b7e5c1a90","datasetId":"9c21f0aa-3e4b-4d2a-b6d1-0f7e8a9b1c2d","status":"active","metadata":{"gender":"mens","color_family":"navy","slot":"top","family":"shirt"},"product":{"name":"Coastal Linen Shirt","url":"https://shop.example.com/products/coastal-linen-shirt","price":89,"currency":"USD","variants":[{"variantId":"gid://shopify/ProductVariant/41611609636909","sku":"CLS-NVY-M","label":"M / Navy","options":[{"name":"Size","value":"M"},{"name":"Color","value":"Navy"}],"inStock":true,"quantity":4,"price":89,"compareAtPrice":null}],"assets":{"images":[{"uploaded":{"key":"org_5f3a/ds_9c21/8f2c1a9e-4b7d/0.jpg"}}]}}}]}
event: suggestions
data: {"suggestions":["Show me trousers to match","Something more formal","Cheaper options"]}
event: question
data: {"questionId":"5f0e8c3a-2b1d-4e7f-9a6c-3d2e1f0a9b8c","question":"Who am I styling for?","options":[{"label":"Menswear","value":"mens"},{"label":"Womenswear","value":"womens"}],"allowFreeText":false}
event: brand_sizes
data: {"cardId":"0b9c1f7e-4d2a-4c1b-8e55-7a1d2c3b4e5f","title":"Which brands do you wear?","department":"womens","kind":null,"garments":[{"value":"jeans","label":"Jeans","part":"bottom","kind":"jeans"}],"kinds":[{"value":"tops","label":"Tops"},{"value":"jeans","label":"Jeans"},{"value":"trousers","label":"Trousers"},{"value":"dresses","label":"Dresses"},{"value":"outerwear","label":"Jackets"},{"value":"suits","label":"Suit jackets"}],"fits":[{"value":"tight","label":"Tight"},{"value":"right","label":"Right"},{"value":"loose","label":"Loose"}],"brands":[],"logos":true,"saved":[]}
event: looks
data: {"looks":[{"label":"Garden wedding","items":[{"itemId":"8f2c1a9e-4b7d-4c1e-9a3f-2d6b7e5c1a90","product":{"name":"Coastal Linen Shirt","price":89,"currency":"USD"}},{"itemId":"1b7e33c0-9a2d-4f8e-b5c6-7d8e9f0a1b2c","product":{"name":"Everyday Chino","price":79,"currency":"USD"}},{"itemId":"c4d5e6f7-0a1b-4c2d-8e9f-0a1b2c3d4e5f","product":{"name":"Suede Loafer","price":129,"currency":"USD"}}],"customInstructions":"Shirt untucked with the top button open; outdoor daylight setting.","ownPiece":null,"basics":[]}],"tryOn":true}
event: cart_action
data: {"action":"add","itemId":"8f2c1a9e-4b7d-4c1e-9a3f-2d6b7e5c1a90","name":"Coastal Linen Shirt","url":"https://shop.example.com/products/coastal-linen-shirt?variant=41611609636909","sku":"CLS-NVY-M","size":"M / Navy","shown":"M · Navy","quantity":1,"price":89,"currency":"USD","image":"org_5f3a/ds_9c21/8f2c1a9e-4b7d/0.jpg","intent":"eyJ2IjoxLCJqdGkiOiI3ZjFlIn0.q8vT2rN9…"}
event: cart_sizes
data: {"cardId":"2e3f4a5b-6c7d-4e8f-8a9b-0c1d2e3f4a5b","title":"Pick your size","canSave":false,"items":[{"id":"8f2c1a9e-4b7d","name":"Coastal Linen Shirt","image":"org_5f3a/ds_9c21/8f2c1a9e-4b7d/0.jpg","colour":"Navy","quantity":1,"sizes":[{"label":"S","inStock":true},{"label":"M","inStock":true},{"label":"L","inStock":false}],"picked":"M","alternative":"S","note":null,"concern":null,"colours":[],"ready":false,"unavailable":false}]}
event: profile
data: {"token":"eyJwIjoiN2YxZSJ9.c2lnbmF0dXJl","kind":"visitor","created":true}
event: profile_save
data: {"reason":"Keep your sizes and styles for next time","intent":"save"}
event: tool_output
data: {"name":"lookup_products","output":{"count":8,"items":[{"id":"8f2c1a9e-4b7d","description":"Coastal Linen Shirt — navy, linen, relaxed fit, $89"}],"note":"The shopper saw NOTHING — this was for your eyes only."}}
event: done
data: {"output":"All three are linen, so they will breathe on a warm afternoon.","history":[{"role":"user","content":"I need something for a summer wedding, menswear, under $300."},{"type":"function_call","callId":"call_8kP2wN7r","name":"show_products","arguments":"{\"label\":\"Wedding shirts\",\"kind\":\"list\",\"itemIds\":[\"8f2c1a9e-4b7d\",\"1b7e33c0-9a2d\",\"c4d5e6f7-0a1b\"],\"suggestions\":[\"Show me trousers to match\",\"Something more formal\"]}","status":"completed"},{"type":"function_call_result","callId":"call_8kP2wN7r","name":"show_products","status":"completed","output":{"type":"text","text":"{\"shown\":3,\"note\":\"3 cards are now on the shopper's screen under \\\"Wedding shirts\\\".\"}"}},{"type":"message","role":"assistant","status":"completed","content":[{"type":"output_text","text":"All three are linen, so they will breathe on a warm afternoon."}]}]}
event: error
data: {"error":"Agent run failed."}