Skip to main content

Chat

📄️Send a message to the agent

Sends one message to the same agent the Mocart app talks to, as the account that owns the key. Answers 202 at once with the turn; poll `GET /chat/turns/{turnId}` until `status` is `done` or `failed`. The first message of a conversation has no `sessionId`; send the `sessionId` the reply carries on the next one. A turn never runs twice: if it fails, send the message again with a NEW `Idempotency-Key`, in the SAME conversation (its `sessionId`) when the problem names one. `Idempotency-Key` is required.

📄️Get a turn

While `status` is `queued` or `running` the response carries `Retry-After`: poll again after that many seconds. On `done`, `reply` holds the agent’s answer (`prose` is its plain words, `null` when there are none; an offer is `reply.proposal.kind === 'proposes'` with a `planId` to confirm or cancel; when the agent designed a piece, the offer is to make it (`reply.proposal.draftOffer`) and the piece exists only once the offer is confirmed). On `failed`, `problem` says why, and `problem.sessionId` (also `sessionId`) names the conversation to resend INTO when the turn had started one. `RUNNER_LOST` is NOT final: the runner stopped reporting, but the turn may still complete and then reads `done`, so poll again before resending, and resend in the SAME `sessionId` rather than a fresh conversation. `NOT_STARTED` IS final: the turn waited too long to start and will never run. `RESULT_NOT_STORED` means the turn ran but its answer could not be saved: its effects may exist, so continue in the same `sessionId`. A turn is kept for as long as its `Idempotency-Key` is remembered (30 days).

📄️Confirm an offer

Says yes to an offer the agent made and starts its run. THIS SPENDS CREDITS: the run is launched from the stored plan at the price the offer showed (`plan.price.totalCredits`), never from anything sent here. Answers 202 with the run; confirming a plan that already started answers 200 with the SAME run and starts nothing. An offer of pictures for a draft piece (`reply.proposal.pieceOffer`) has no run: it answers `pieceId` instead of `runId`, read the piece with `GET /pieces/{pieceId}` (its slides say `waiting` while a picture is being made), and only the pictures actually made are charged, at most `plan.price.totalCredits`. An offer to MAKE a designed piece (`reply.proposal.draftOffer`) makes the piece only now, then its pictures: it answers the new `pieceId`, and `total` is the pictures it will make (`0` when its design holds no picture: the piece is made and nothing is charged). A piece that cannot be made as the offer stands (the account lost the feature, a product or brand was deleted) answers `AGENT_CHAT_PLAN_CANNOT_RUN`, with nothing charged. An offer whose pictures name no product, on an account that cannot have a picture made from a description alone (its start says `needs-product`), is never made: confirming it answers `AGENT_CHAT_PLAN_NEEDS_PRODUCT` and nothing is made or charged. A price that moved since the offer was shown is refused with nothing charged. The key needs `chat` and `runs:write`.