> ## Documentation Index
> Fetch the complete documentation index at: https://agentmall.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Threads and Carts

> A thread is one shopping trip — from cart creation to order or cancellation.

![Thread lifecycle: browsing, carted, checked-out](https://mintcdn.com/agentmall/lkUvHMJJkrHKFrki/images/threads.svg?fit=max\&auto=format\&n=lkUvHMJJkrHKFrki\&q=85\&s=125c6eb6ff4eb98866c34d729f563d35)

A thread is one shopping trip. It starts when your agent creates a thread and ends when the order is placed or the thread is cancelled.

## Thread = cart

`create_cart` returns a cart with an `id` prefixed `thr_`. That id is the thread id. Every subsequent call (`update_cart`, `create_checkout`, `complete_checkout`) takes it as `thread_id`.

```json theme={null}
{ "merchant": "walmart" }
```

The shopper is identified by the `X-Shopper-Id` header, not a body field.

The response includes the `id`. Pass it as `thread_id` on every tool. On REST it is `:id` in `/v1/carts/:id`.

## Lifecycle

| Outcome | Meaning |
| - | - |
| `browsing` | The thread is open |
| `ordered` | The shopper confirmed and the merchant accepted the order |
| `cancelled` | Thread cancelled with `cancel_cart` |

A thread stays open until it is ordered, cancelled, or its order is submitted and fails or has an unknown outcome. It does not time out. Once it ends it cannot be reopened, and any call on it returns `thread_ended` (HTTP 410) with the outcome in the message. Start a new thread with `create_cart`.

`complete_checkout` does not end the thread. It returns a `confirm_url`, and the thread ends after the shopper confirms on that page. See [Orders](https://agentmall.mintlify.site/concepts/orders.md).

## What a thread holds

| Field | Set by | Cleared |
| - | - | - |
| Cart lines | `update_cart`, `get_cart` | When a cart read or write fails |
| Checkout review | `create_checkout`, `get_checkout`, `update_checkout` | `update_cart`, and when the thread ends |
| Saved card | The shopper, on the `set_credentials` page | When the thread ends |
| Saved login | The shopper, on the `set_credentials` page | When the thread ends |

The saved card and login are Evervault-encrypted values. See [Security](https://agentmall.mintlify.site/concepts/security.md).

## One merchant, one browser context

Each thread is bound to one merchant, set by `merchant` on `create_cart`. See [Merchants](https://agentmall.mintlify.site/concepts/merchants.md) for the nine live merchants.

A thread runs on a stored browser context: one per organization, shopper and merchant. The first `create_cart` for a shopper at a merchant creates it, and every later thread for the same `X-Shopper-Id` and merchant reuses it. The context keeps the merchant cart and sign-in state, and it outlives the thread. A shopper's next thread at the same merchant starts on the same context, usually still signed in. Each call borrows a browser from a shared pool and opens it on that context.

When every browser is busy, a call returns `browser_unavailable` with `retry_after_seconds`. Nothing changed. Wait and call again.

## Merchant sign-in

Every thread shops as the shopper's own merchant account. Nothing checks sign-in up front: a step that needs the account, such as `create_checkout`, returns `sign_in_required` when the shopper's context is signed out. Then:

1. `set_credentials` with `{ "thread_id": "thr_…", "type": "login" }`. It returns a `url`.
2. Give the `url` to the shopper. They enter their merchant email and password. The password is encrypted in their browser.
3. `sign_in` with `{ "thread_id": "thr_…" }`. It returns `{ "signed_in": true }`. Retry the step that failed.

The sign-in is kept on the context, so the shopper signs in once per merchant. The saved login is on the thread and is cleared when the thread ends.

| Code | What to do |
| - | - |
| `credentials_required` | The shopper has not saved a login on this thread. Go back to step 1. |
| `challenge_required` | The merchant wants a one-time code. AgentMall does not take codes yet. |
| `sign_in_failed` | The merchant rejected the login. Ask the shopper to check it, then go back to step 1. |

## Console

The Threads page at [console.getagentmall.com/threads](https://console.getagentmall.com/threads) lists every thread for your organization. Each row shows the merchant, outcome, and tool call count. Click a thread to see its tool calls.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.