Skip to main content
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.

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.
  • 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.
  • 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.
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 {}.
A suspended partner account cannot start a conversation (409 ACCOUNT_NOT_ACTIVE).

Send a message

Any other field is refused with 400 VALIDATION_FAILED.
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

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

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.
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

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.

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.

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.

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:
Show the user the detail and ask them to rephrase. Do not retry automatically: the same text is refused again. See MARKET_CONTENT_REFUSED for every reason.

For partners

Send Kash-Account: <accountId> on every market conversation call, reads included:
  • 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:
See TypeScript SDK.

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

Next

TypeScript SDK

kash.marketConversations and waitForReply.

Rate limits

The creation limit and the daily limits.