Skip to content
Median
Esc
↑↓navigate↵open⌘Jpreview

Send a message

The first message creates the visitor and the conversation. The AI starts answering unless a person already holds the thread.

New user values overwrite old ones and omitted fields are not erased. Query strings are stripped from page URLs on arrival.

Pass buttons: true when your panel draws the agent’s answers to tap and its link buttons. They arrive as choices and links on the thread’s messages.

Pass emailAsk: true when your panel can show an email field. When a tool needs the visitor’s address, the thread carries emailAsk until you answer with POST /email-ask.

POST/messages
Authorization
AuthorizationBearer token · headerrequired
A MEDIAN_KEY from Settings under API. It starts with `median_key_` and stays on your server. The tool endpoint routes also accept an OAuth access token (`median_oat_`) from `median login` or an MCP client, acting as the person who approved it. The messaging routes accept only a Median key.
Request body
requiredapplication/json
sessionstringrequired
The visitor's session token.
min length 8 · max length 128
bodystringrequired
The message. Can be empty when the message carries attachments.
max length 4000
userobject
Who this is, shown to your team.
Show properties
namestring
Cut to 80 characters.
emailstring
Cut to 320 characters.
avatarUrlstring
An HTTPS URL up to 512 characters. Anything else is dropped.
metadataobject
Your own facts about them: plan, seats, account age. The first 16 entries are kept, and keys and values are cut to 200 characters.
contextobject
The visitor's browser, shown beside the thread.
Show properties
timeZonestring
localestring
browserstring
osstring
devicestring
Allowed:desktoptabletmobile
screenstring
pageobject
Where they wrote from. Kept on the conversation's first message.
Show properties
urlstringrequired
titlestring
referrerstring
attachmentsobject[]
Up to 6 files, with ids from POST /uploads.
max items 6
Show properties
Array of object
idstringrequired
namestringrequired
buttonsboolean
Your panel draws `choices` and `links` as buttons, so the agent may ask with answers to tap and offer pages, and the thread keeps them out of `body`. Send it with every message. Left out, the agent asks in words.
emailAskboolean
Your panel can show an email field when the agent asks for one. The ask arrives as `emailAsk` on the thread. Left out, the agent asks in words.
Responses
200The conversation it landed in, and the message.
conversationIdstringrequired
messageIdstringrequired
400`invalid_json`: the body is not a JSON object. `invalid_request`: a field is missing, has the wrong type, or is unknown, and the message names the allowed fields. `invalid_session`: the session is not 8 to 128 characters. `empty_message`: no body and no attachments. `message_too_long`: the body is over 4,000 characters. `too_many_attachments`: more than 6. `attachment_missing`: an id is not a file from `POST /uploads`. `attachment_wrong_type`: the file is HTML, XHTML, SVG or XSLT.
errorobjectrequired
Show properties
codestringrequired
Branch on this rather than on the message.
messagestringrequired
401`missing_api_key`: no bearer token. `invalid_api_key`: the key matches no organization or was revoked. `publishable_key`: a `median_pk_` key was sent. An OAuth access token is refused here with `invalid_api_key`.
errorobjectrequired
Show properties
codestringrequired
Branch on this rather than on the message.
messagestringrequired
429The organization's API allowance for this class of request is used up. Wait the `Retry-After` header's seconds. Limits depend on the plan. See [rate limits](/api/errors-and-limits#rate-limits).
errorobjectrequired
Show properties
codestringrequired
Branch on this rather than on the message.
messagestringrequired
Request
curl -X POST "https://api.median.sh/v1/messages" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "session": "user_42",
  "body": "How do I export my data?",
  "user": {
    "name": "Ada",
    "email": "ada@example.com"
  },
  "buttons": true
}'
Response
{
  "conversationId": "js7...",
  "messageId": "jd2..."
}