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

# Market creation (preview)

> Draft a market with the Kash market assistant from your own app: start a conversation, send the user's messages and read the replies.

> [!WARNING]
>
> **Preview.** The market creation API is switched off until it launches. Until then a key that holds `markets:write` gets `503 ROUTE_DISABLED` from every route on this page, and a key without it gets `403 INSUFFICIENT_SCOPE`. The routes and the SDK methods may still change before launch.

The market creation API lets your server hold the conversation a user would have with the market assistant in the Kash app. You start a conversation for the user, send their messages, and read the assistant's replies, which draft the market. Market text (title, description, resolution criteria and outcome labels) is drafted in English whatever language the user writes in.

| Method | Path | Scope | Rate-limit class | Idempotency-Key |
| - | - | - | - | - |
| `POST` | `/v1/market-conversations` | `markets:write` | write, plus the [creation limit](#limits) | honoured |
| `GET` | `/v1/market-conversations` | `markets:write` | read | |
| `GET` | `/v1/market-conversations/{conversationId}` | `markets:write` | read | |
| `POST` | `/v1/market-conversations/{conversationId}/messages` | `markets:write` | write, plus the [creation limit](#limits) | honoured |
| `GET` | `/v1/market-conversations/{conversationId}/messages` | `markets:write` | read | |

## Before you start

* **A key with `markets:write`.** Every route on this page needs it, the reads included: `markets:read` does not open a conversation's transcript. `markets:write` is never granted by default. Ask ZeroID to add it to your key. See [Authentication](https://docs.kash.bot/developer-docs/rest-api/authentication.md#scopes).
* **The user.** A user key acts for its own user. A partner key names the user's account in the `Kash-Account` header on every call, and a user key that sends `Kash-Account` is refused with `400 ACCOUNT_HEADER_NOT_ALLOWED`. See [For partners](#for-partners).
* **Conversation ids.** Send them in lower case, as the API returns them. The API matches the lower-case form only, so an upper-case copy of a real id answers `404 MARKET_CONVERSATION_NOT_FOUND`. The SDK lower-cases them for you.

## How a conversation runs

**1. Start a conversation**

`POST /v1/market-conversations` returns `201` with the conversation's `id`. Nothing reaches the assistant until the first message.

**2. Send the user's message**

`POST /v1/market-conversations/{conversationId}/messages` queues the message and returns `202` with the message's `id`. The assistant's reply arrives in the transcript.

**3. Wait for the reply**

Read the state until the assistant is `idle`. See [Read the state](#read-the-state).

**4. Read what is new**

Read the transcript from the `after` position you kept last time, and keep the new `after` for the next read.

## Start a conversation

The body is empty or `{}`.

```bash theme={null}
curl -X POST "$KASH_API/market-conversations" \
  -H "X-API-Key: $KASH_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{}'
```

```json theme={null}
{
  "conversation": { "id": "5b0f6a52-8c1e-4d3a-9f27-6e4b1c0d9a83", "createdAt": "2026-11-21T09:30:00.000Z" },
  "data":         { "id": "5b0f6a52-8c1e-4d3a-9f27-6e4b1c0d9a83", "createdAt": "2026-11-21T09:30:00.000Z" },
  "_meta": { "requestId": "…", "timestamp": "2026-11-21T09:30:00.000Z", "idempotent": false }
}
```

A suspended partner account cannot start a conversation (`409 ACCOUNT_NOT_ACTIVE`).

## Send a message

```bash theme={null}
curl -X POST "$KASH_API/market-conversations/$CONVERSATION_ID/messages" \
  -H "X-API-Key: $KASH_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"content": "Will Calgary get more than 10 cm of snow on 1 December 2026?", "timezone": "America/Edmonton"}'
```

| Field | Type | Notes |
| - | - | - |
| `content` | string, required | What the user wrote. At most 2,000 characters (UTF-16 code units), not blank, with no NUL character and no unpaired surrogate. |
| `declaredAction` | `"create_market"`, optional | Send it when the user explicitly asked to turn the conversation into a market, as the Kash app's **Turn this into a market** does. Omit it for a typed message. |
| `timezone` | string, optional | The user's IANA time zone, such as `America/Edmonton`, used only to read relative dates such as "next Friday". Defaults to UTC. An alias is accepted and stored under its canonical name (`US/Mountain` becomes `America/Denver`). A UTC offset such as `+05:30` is refused with `400 VALIDATION_FAILED`. |

Any other field is refused with `400 VALIDATION_FAILED`.

```json theme={null}
{
  "message": {
    "id": "c3a9e1d4-2f6b-4b8e-a0d7-91e5f3c2b6a4",
    "conversationId": "5b0f6a52-8c1e-4d3a-9f27-6e4b1c0d9a83",
    "createdAt": "2026-11-21T09:30:05.000Z"
  },
  "data": { "id": "c3a9e1d4-2f6b-4b8e-a0d7-91e5f3c2b6a4", "conversationId": "5b0f6a52-8c1e-4d3a-9f27-6e4b1c0d9a83", "createdAt": "2026-11-21T09:30:05.000Z" },
  "_meta": { "requestId": "…", "timestamp": "2026-11-21T09:30:05.000Z", "idempotent": false }
}
```

Keep the message `id`: it tells you when your message has been answered. A message sent while an earlier one is still being answered is queued behind it.

## Read the state

```bash theme={null}
curl "$KASH_API/market-conversations/$CONVERSATION_ID" -H "X-API-Key: $KASH_API_KEY"
```

| Field | Type | Notes |
| - | - | - |
| `id`, `createdAt` | uuid, date-time | |
| `status` | enum | `queued`: a message is waiting to be picked up. `working`: a reply is being written. `idle`: nothing is in flight. |
| `queuePosition` | integer \| null | While `queued` behind other conversations: how many are ahead. Approximate. |
| `estimatedWaitSeconds` | integer \| null | While `queued`: an approximate wait, never a promise. |
| `readyToPublish` | boolean | The assistant has finished a draft in its latest reply. The API cannot submit it yet: see [What the API does not do yet](#what-the-api-does-not-do-yet). |
| `marketRequestId` | uuid \| null | The id of the market request linked to this conversation, once one exists. No API route reads or submits it yet. |
| `latestMessage` | object \| null | The latest message: `id`, `status` and `createdAt`. `status` is `pending` (accepted, not yet handed to the assistant), `published` (handed over) or `failed` (it could not be delivered and will get no reply). |

Your message has been answered when `status` is `idle` and `latestMessage` is your message and not `failed`. Then read the transcript after the position you hold: the reply is the assistant turn written after your message. A message the assistant has answered can still read `pending`, so go by `status` rather than waiting for `published`. If the reply is not in the transcript yet, read again a moment later. Two other cases:

* **`latestMessage.status` is `failed`.** No reply will come. Send the message again with a new `Idempotency-Key`.
* **`latestMessage.id` is not your message's `id`.** A later message has been sent to the same conversation, for example by another process of yours. Read the transcript rather than waiting for your own message.

Each read counts against your key's read budget. Poll every few seconds.

## Read the transcript

```bash theme={null}
curl "$KASH_API/market-conversations/$CONVERSATION_ID/messages?after=$AFTER&limit=50" \
  -H "X-API-Key: $KASH_API_KEY"
```

The user's messages and the assistant's replies, oldest first. Omit `after` to read from the start. `limit` is 1 to 100, default 50.

```json theme={null}
{
  "data": [
    {
      "turnNumber": 1,
      "role": "user",
      "content": "Will Calgary get more than 10 cm of snow on 1 December 2026?",
      "revision": 1,
      "createdAt": "2026-11-21T09:30:05.000Z",
      "updatedAt": "2026-11-21T09:30:05.000Z"
    },
    {
      "turnNumber": 2,
      "role": "assistant",
      "content": "…",
      "revision": 1,
      "createdAt": "2026-11-21T09:30:21.000Z",
      "updatedAt": "2026-11-21T09:30:21.000Z"
    }
  ],
  "pagination": { "after": "…", "hasMore": false, "limit": 50 },
  "_meta": { "requestId": "…", "timestamp": "2026-11-21T09:30:30.000Z" }
}
```

| Field | Type | Notes |
| - | - | - |
| `turnNumber` | integer | The turn's place in the conversation. |
| `role` | enum | `user` or `assistant`. |
| `content` | string | |
| `revision` | integer | Starts at 1 and rises each time the turn is rewritten. |
| `createdAt`, `updatedAt` | date-time | |

`pagination.after` works differently from the cursor on other lists:

* It is always the position after the last turn you have seen. Pass it as `after` to read only what follows.
* On a page with no turns it repeats the `after` you sent, even when `hasMore` is `false`. Keep it: it is where your next read starts.
* It is `null` only when you sent no `after` and the page has no turns: before the conversation has any turn, or while the assistant is writing one. `null` means read from the start, so omit `after` next time.
* A reply the assistant rewrites after you read it comes back after your position with a higher `revision`. Keep one entry per `turnNumber`, the one with the highest `revision`.
* An `after` that is malformed or from another list is refused with `400 VALIDATION_FAILED`.

## List conversations

```bash theme={null}
curl "$KASH_API/market-conversations?limit=20" -H "X-API-Key: $KASH_API_KEY"
```

The conversations you can see, newest first, each with `id` and `createdAt`. Cursor-paginated like other lists (`limit` 1 to 100, default 20): see [Pagination](https://docs.kash.bot/developer-docs/rest-api/pagination.md).

## Who can see a conversation

A conversation belongs to the kind of key that started it:

* a user key sees the conversations user keys started for its user;
* a partner key sees those its organisation started for the `Kash-Account` user.

Conversations started in the Kash app are not available through the API. Anything else answers `404 MARKET_CONVERSATION_NOT_FOUND`, with the same body in every case. A new key of the same user or organisation sees the same conversations: rotating a key does not lose them.

## Retries and idempotency

Send an `Idempotency-Key` on both `POST` routes, one per start and one per message:

* **A retry with the same key and body** returns the stored answer instead of running again: the `201` conversation, the `202` message, or the `422 MARKET_CONTENT_REFUSED` refusal. The response carries the header `Idempotent-Replay: true`. On these two routes `_meta.idempotent` is always `false`, so read the header to tell a replay.
* **Without a key,** a retry may start a second conversation or send the message twice.
* **The same key with a different body** is refused with `409 IDEMPOTENCY_KEY_CONFLICT`.
* **A retry that waits more than 2 seconds** for the first request to finish answers `409 IDEMPOTENCY_REQUEST_IN_PROGRESS` with `Retry-After: 1`. Retry with the same key.
* **Any other error stores nothing.** A retry with the same key after it is judged afresh.
* **A `503 DEPENDENCY_UNAVAILABLE` whose `detail` says the request may still take effect:** retry with the same key. If the write happened, the retry returns it; if not, it runs once.

The general rules are on [Idempotency](https://docs.kash.bot/developer-docs/rest-api/idempotency.md).

## Limits

* **Creation requests per minute.** Starts and messages together are limited to **20 a minute per user**, across every key acting for that user. For a partner key the user is the account in `Kash-Account`. This is on top of your key's own request rate. Past it the request is refused with `429 RATE_LIMIT_EXCEEDED` and a `Retry-After` header. A replay counts against it too.
* **Daily limits.** Starting conversations and sending messages are each limited per user and per key each day, counted from 00:00 UTC. At a limit the request is refused with `429 MARKET_CREATION_DAILY_LIMIT_REACHED` and nothing is written. `Retry-After` is the number of seconds until 00:00 UTC. A user's messages count whether they were sent through the API or in the Kash app. A user's daily limits are shared between their own key and the partner acting for them. The limits depend on your key's tier; they are set by Kash and are not published. A replay is never refused and never counted again.
* **Daily AI drafting budget.** When today's budget for your key, or for market creation through the API, is used up, a message is not refused: it is accepted with `202`, and the assistant's reply in the transcript says so. It reads "This API key has used today's AI drafting budget. It resets at 00:00 UTC." or "Market creation through the API has used today's AI drafting budget. It resets at 00:00 UTC."

See [Rate limits](https://docs.kash.bot/developer-docs/rest-api/rate-limits.md#market-creation-limits).

## Content rules

A message that breaks Kash's market content rules is refused with `422 MARKET_CONTENT_REFUSED`. Nothing is sent and nothing counts against your daily limits. The body's `reason` names the rule and `detail` explains it in words you can show the user:

```json theme={null}
{
  "type": "https://docs.kash.bot/developer-docs/api-errors/MARKET_CONTENT_REFUSED",
  "title": "Message refused by content rules",
  "status": 422,
  "code": "MARKET_CONTENT_REFUSED",
  "detail": "i can't draft a market settled on information you say isn't public. use a source anyone can check.",
  "reason": "insider_information",
  "instance": "/v1/market-conversations/5b0f6a52-8c1e-4d3a-9f27-6e4b1c0d9a83/messages",
  "requestId": "…"
}
```

Show the user the `detail` and ask them to rephrase. Do not retry automatically: the same text is refused again. See [`MARKET_CONTENT_REFUSED`](https://docs.kash.bot/developer-docs/api-errors/MARKET_CONTENT_REFUSED) for every `reason`.

## For partners

Send `Kash-Account: <accountId>` on every market conversation call, reads included:

```bash theme={null}
curl -X POST "$KASH_API/market-conversations" \
  -H "X-API-Key: $KASH_PARTNER_KEY" \
  -H "Kash-Account: $ACCOUNT_ID" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{}'
```

* A partner key without the header is refused with `400 ACCOUNT_HEADER_REQUIRED`.
* A conversation is visible only with the same `Kash-Account` that started it.
* A suspended account can still read its conversations, but cannot start one or send a message (`409 ACCOUNT_NOT_ACTIVE`).
* The per-minute creation limit counts each account on its own. The daily limits count each account, and your key across all its accounts. A user's daily limits are shared between their own key and the partner acting for them.

## With the SDK

`@kashdao/sdk` wraps these routes as `kash.marketConversations`, from version 0.5.0. The SDK keys both writes, so its own retries never start a second conversation or send a message twice. `waitForReply` polls the state for you and returns the new turns:

```ts theme={null}
import { KashClient } from '@kashdao/sdk';

const kash = new KashClient({ apiKey: process.env.KASH_API_KEY! });

const { conversation } = await kash.marketConversations.start();
const { message } = await kash.marketConversations.sendMessage(conversation.id, {
  content: 'Will Calgary get more than 10 cm of snow on 1 December 2026?',
  timezone: 'America/Edmonton',
});

const reply = await kash.marketConversations.waitForReply(conversation.id, { message });
if (reply.outcome === 'replied') {
  for (const turn of reply.turns) console.log(turn.role, turn.content);
}
// Keep reply.after and pass it as `after` on your next read.
```

See [TypeScript SDK](https://docs.kash.bot/developer-docs/rest-api/sdks/typescript.md#market-creation-preview).

## What the API does not do yet

The API stops at the draft. It holds the conversation and reports when the assistant has a draft ready, but it does not yet:

* submit the draft as a market request, or read or change a market request;
* generate or read the cover image, or quote the market creation fee;
* send webhooks about a conversation, so read the state to follow it.

These come in later releases.

## Errors

| Status | `code` | When |
| - | - | - |
| 400 | [`VALIDATION_FAILED`](https://docs.kash.bot/developer-docs/api-errors/VALIDATION_FAILED) | A body, query or `after` the route does not accept. |
| 400 | [`ACCOUNT_HEADER_NOT_ALLOWED`](https://docs.kash.bot/developer-docs/api-errors/ACCOUNT_HEADER_NOT_ALLOWED) | A user key sent `Kash-Account`. |
| 400 | [`ACCOUNT_HEADER_REQUIRED`](https://docs.kash.bot/developer-docs/api-errors/ACCOUNT_HEADER_REQUIRED) | A partner key sent no `Kash-Account`. |
| 403 | [`INSUFFICIENT_SCOPE`](https://docs.kash.bot/developer-docs/api-errors/INSUFFICIENT_SCOPE) | The key lacks `markets:write`. |
| 404 | [`ACCOUNT_NOT_FOUND`](https://docs.kash.bot/developer-docs/api-errors/ACCOUNT_NOT_FOUND) | `Kash-Account` names no account of your organisation. |
| 404 | [`MARKET_CONVERSATION_NOT_FOUND`](https://docs.kash.bot/developer-docs/api-errors/MARKET_CONVERSATION_NOT_FOUND) | The key cannot see the conversation. |
| 409 | [`MARKET_CONVERSATION_NOT_WRITABLE`](https://docs.kash.bot/developer-docs/api-errors/MARKET_CONVERSATION_NOT_WRITABLE) | The key can no longer start a conversation for this user, or the conversation was visible but refused this message. Rare. |
| 409 | [`ACCOUNT_NOT_ACTIVE`](https://docs.kash.bot/developer-docs/api-errors/ACCOUNT_NOT_ACTIVE) | The partner account is still being set up, or is suspended and cannot start a conversation or send a message. |
| 409 | [`IDEMPOTENCY_KEY_CONFLICT`](https://docs.kash.bot/developer-docs/api-errors/IDEMPOTENCY_KEY_CONFLICT), [`IDEMPOTENCY_REQUEST_IN_PROGRESS`](https://docs.kash.bot/developer-docs/api-errors/IDEMPOTENCY_REQUEST_IN_PROGRESS) | See [Retries and idempotency](#retries-and-idempotency). |
| 422 | [`MARKET_CONTENT_REFUSED`](https://docs.kash.bot/developer-docs/api-errors/MARKET_CONTENT_REFUSED) | The message breaks the market content rules. |
| 429 | [`MARKET_CREATION_DAILY_LIMIT_REACHED`](https://docs.kash.bot/developer-docs/api-errors/MARKET_CREATION_DAILY_LIMIT_REACHED) | A daily limit is reached. `Retry-After` runs to 00:00 UTC. |
| 429 | [`RATE_LIMIT_EXCEEDED`](https://docs.kash.bot/developer-docs/api-errors/RATE_LIMIT_EXCEEDED) | Past 20 creation requests a minute for the user, or your key's request rate. |
| 503 | [`ROUTE_DISABLED`](https://docs.kash.bot/developer-docs/api-errors/ROUTE_DISABLED) | The market creation API is switched off. Only a key with `markets:write` gets this answer. |
| 503 | [`DEPENDENCY_UNAVAILABLE`](https://docs.kash.bot/developer-docs/api-errors/DEPENDENCY_UNAVAILABLE) | Retry shortly. See [Retries and idempotency](#retries-and-idempotency). |

## Next

> [card] [TypeScript SDK](https://docs.kash.bot/developer-docs/rest-api/sdks/typescript.md#market-creation-preview)
>
> `kash.marketConversations` and `waitForReply`.

> [card] [Rate limits](https://docs.kash.bot/developer-docs/rest-api/rate-limits.md#market-creation-limits)
>
> The creation limit and the daily limits.


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