Contacts, conversations, and messages
How to store a contact and send a message.
Contacts
POST /v1/contacts with contacts:write creates or updates a contact by phone number. A new contact returns 201. An existing one returns 200. Both return id, phoneNumber, optedIn, and attributes.
{
"phoneNumber": "+15555550123",
"externalId": "crm-881",
"displayName": "Pat Lee",
"timezone": "America/New_York",
"consent": { "source": "web_form", "capturedAt": "2026-10-28T23:00:00.000Z" }
}phoneNumberis stored in E.164: a plus sign, the country code, and the number, such as+15555550123.externalIdis your own id for the person. Using it with a different phone number returns 409.timezonemust be an IANA zone such asAmerica/New_York. Quiet hours use it.consentrecords where and when the person agreed to messages. A proactive message needs a consent record or an earlier message from the person.attributestakes only the fields defined for your agent: text, a number, yes or no, a date like2026-11-07, or one of a list. MessageOS sets the fields up, so ask MessageOS to add one. Any other field, or a value of the wrong kind, returns 422 naming the field, and an agent with no fields defined answers 422 to any attribute. They are merged into the stored ones, and a field set tonullis removed. Add?replace=trueto replace the stored attributes instead.- A field you do not send keeps its stored value.
clientIdandoptedInare rejected. A new contact is opted in, and only a message from the person changes that.
GET /v1/contacts and GET /v1/contacts/{id} need contacts:read. The list accepts phoneNumber, externalId, updatedSince, limit (1 to 100, default 25), and cursor. Pass nextCursor as cursor for the next page. It is null when the page was not full.
Conversations
A conversation starts with the first message to or from a person. After the idle gap, a long stretch with no message either way, the next message starts a new one. GET /v1/conversations needs conversations:read. Filter with contactId, status (open or closed), and updatedSince, which compares the time of the last message. limit and cursor page the list.
GET /v1/conversations/{id} returns one conversation and its message count. GET /v1/conversations/{id}/messages returns its messages in order, each with the labels of the buttons sent under it (chips) and its latest delivery status. An inbound message shows what the person typed or the label they tapped, and its id is the inboundMessageId of its reply.received event. Provider identifiers are not included.
Sending a message
POST /v1/messages needs messages:write and an Idempotency-Key header. The smallest body is a recipient and text.
curl -X POST 'https://api.messageos.ai/v1/messages' \
-H 'Authorization: Bearer mosc_...' \
-H 'Idempotency-Key: visit-reminder-42-2026-10-28' \
-H 'Content-Type: application/json' \
-d '{
"to": {
"contactId": 42
},
"text": "Your appointment is Tuesday at 3:00 PM."
}'Each sample is a whole program that uses only what comes with its language, and prints the status and the answer. The API reference has the same for every kind of message.
totakescontactId,phoneNumber, orexternalId. A phone number that is not yet a contact needsconsentin the same request:"consent": { "source": "checkout_form", "capturedAt": "2026-10-28T23:00:00.000Z" }. The contact is created with it and the message is sent. Without it the send is blocked withno_consent_record. Storing consent needscontacts:write.- A message is exactly one of
text,card,carousel,file, ortemplate.textis up to 2000 characters. Message types has a body for each, and forsuggestions, the buttons under a message. classisservice(the default),transactional, orpromotional, as this client is allowed.allowedClassesinGET /v1/whoamilists the classes your agent sends. MessageOS turns a class on for your agent, and no key or dashboard setting of yours can, so ask MessageOS if you need one that is not listed, such aspromotional. A class it does not send is refused before the send rules run: 422validation_error, anddetails[0].pathisclass.complianceis reserved for MessageOS and is rejected.referenceis your own id for the message, up to 200 characters. It comes back in the answer, inGET /v1/messages/{id}, and in themessage.delivered,message.read, andmessage.failedevents.onQuietsays what to do in quiet hours. See When a message is not sent.expiresAtorttlSecondsgives the message an expiry, andtrafficTypedeclares what kind of traffic it is. Message types has a body for each. Both answer 422 until MessageOS turns them on for you.- A template this client has can stand in for
text:"template": { "id": "reminder", "params": { "name": "Pat" } }. MessageOS sets templates up for an agent. An agent with none answers 422 to a template send, and so does a template that is missing a value. Plaintextneeds no template.
A sent message returns 201:
{ "id": "msg_123", "status": "sent", "type": "text", "channel": "rcs", "contactId": 42, "reference": null, "auditId": 123 }id names the message. GET /v1/messages/msg_123 reads its latest status, and the message.delivered, message.read, and message.failed webhooks carry the same id. auditId is the number in it.
When a message is not sent
Every send passes the same rules. A send that breaks one returns 409 blocked. reason is the stable cause, such as opted_out or no_consent_record, and message says what to do. Errors lists every reason.
Some rules always apply. A person who opted out is never sent anything, and STOP, START, and HELP are answered by MessageOS. A message you start needs a consent record for the person or an earlier message from them. The message class must be one this client sends. MessageOS does not cap how many messages you send, and Rate limits says where to read that for your key.
A send the messaging network does not accept is not reported as sent. It returns 409 blocked with a reason that says what the network refused: agent_not_available, message_rejected, provider_busy, or provider_error. That answer is not kept for the Idempotency-Key, so the same key sends again. Every other blocked answer is kept for the key: to try again once what blocked it has passed, send a new key. provider_error means the network did not confirm the message. It may still have gone out, so sending again can reach the person twice.
A phone that cannot get RCS
Messages go by RCS only. A phone that cannot receive RCS is not sent a text message instead, and it gets nothing. You learn of it one of two ways, so handle both:
- The send is refused on the request: 409
blocked, with one of the reasons above for a send the messaging network did not accept. - The send is accepted with 201, and the
message.failedevent arrives afterwards.GET /v1/messages/{id}then showsfailed.
To learn it before you send, check the number first.
Check a number first
GET /v1/capabilities asks the messaging network whether one phone can receive RCS from your agent, and what it supports. It needs messages:write, the scope of a send. The number does not have to be a contact, and the check stores nothing and sends nothing.
curl 'https://api.messageos.ai/v1/capabilities?phoneNumber=%2B15555550123' \
-H 'Authorization: Bearer mosc_...'{ "phoneNumber": "+15555550123", "rcs": true, "features": ["card", "carousel", "openUrl", "dial", "viewLocation", "shareLocation", "createCalendarEvent"] }rcsis false for a phone that cannot receive RCS from your agent. That is an answer, not an error: the status is 200 andfeaturesis empty. Until your agent is launched, a phone that is not one of its testers gets false too.featuresuses the names you send:cardandcarouselare the message types, andopenUrl,dial,viewLocation,shareLocation, andcreateCalendarEventare the suggested actions.revokemeans the phone allows a message to be taken back after it is delivered and before it is read.- Write the plus sign of the number as
%2Bin the address. - 503
provider_unavailablemeans the messaging network did not answer, or was busy or over its limit. It says nothing about the phone, so check again in a moment. 422 means the number is missing or is not a phone number, or the network did not accept it: it may not be a mobile number, or its carrier may not be supported. - An agent that has nothing to send from yet answers 409
blockedwith the reasonagent_not_available, as a send does.
The capability check answers 404 not_found until MessageOS turns it on for you. GET /v1/whoami shows rcsExtras true once it is.
Quiet hours
GET /v1/whoami returns quietHoursEnforced.
false: quiet hours are yours to keep. It is false for every agent set up as API only. A send is not held for the time of day, and a contact needs no time zone. To have MessageOS hold one message, setonQuieton that request:"reject"answers 409quiet_hoursduring quiet hours, and"defer"answers 202 withdeferredUntil, the end of quiet hours, and sends nothing. Both need a time zone on the contact or the client.true: a send you start during quiet hours is rejected withquiet_hours, or deferred with"onQuiet": "defer". A send to a contact with no time zone at all is blocked withmissing_timezone."onQuiet": "send"returns 422.
A deferred message is not sent later on its own: send it again after deferredUntil.
Quiet hours are counted in the contact's time zone, or the client's when the contact has none. The client's time zone is shown on the Agent page of the dashboard, with its quiet hours when MessageOS keeps them. Reminders and follow-ups that MessageOS schedules always wait for the end of quiet hours. The assistant's replies to someone who just texted in are never held, and neither is your own reply that names their message. See Replying to a message.
Replying to a message
When a person has just written in, name their message in inReplyTo and the send is a reply. Quiet hours do not hold a reply, the same as the assistant's own replies, and a reply needs no time zone or consent record. Every other rule still applies, including opt-out and the message class.
{ "to": { "contactId": 42 }, "text": "Thanks for your message. Your visit is confirmed for Tuesday at 3:00 PM.", "inReplyTo": 981 }inReplyTois the id of a message this contact sent:inboundMessageIdin thereply.receivedwebhook, or theidof an inbound message inGET /v1/conversations/{id}/messages.- The message must have arrived within the reply window, one hour.
GET /v1/whoamireturns it asreplyWindowSeconds. A send that names an older message is treated like any other send, so quiet hours can hold it. - Up to three sends can answer one message this way. A fourth, or any promotional send, is treated like any other send. Each new message from the person allows three more.
- An id that is not a message this contact wrote returns 422, and
details[0].pathisinReplyTo. - Craft mode and
POST /v1/messages/draftstakeinReplyTotoo. A draft written to answer a message is a reply only if it is approved while that message is still within the window. - Where replies are not turned on,
replyWindowSecondsis null and a body withinReplyToreturns 422.
Showing that an answer is on its way
When your own system answers customers, POST /v1/typing shows the person the typing indicator while it works. It needs messages:write. to is the same as in a send: contactId, phoneNumber, or externalId, for a person who is already a contact.
{ "to": { "contactId": 42 } }The answer is 202:
{ "status": "accepted", "contactId": 42 }- It is a signal, not a message. It is not counted in usage, it does not appear in the conversation, and it needs no
Idempotency-Key. - Quiet hours do not hold it, and it works while the assistant is paused or the agent is API only.
- A person who opted out is sent nothing: the answer is 409
blockedwith the reasonopted_out, ororg_opted_outwhen they opted out of all of your organization's messages. - It follows the same consent rule as a message you start: a contact with no consent record who has never written in answers 409
blockedwith the reasonno_consent_record. - The messaging network does not say how long a phone shows the indicator. If your answer takes a while, send it again.
- 409
blockedwith the reasonmessage_rejectedmeans the messaging network cannot reach the phone. 503provider_unavailablemeans it did not answer, or was busy or over its limit. Send it again in a moment.
There is no call to mark a customer's message as read, because MessageOS already does it: each message from a person who has not opted out is marked read when it arrives, whether the assistant is on, paused, or API only. A message MessageOS holds because the person sent too many messages is not marked read, and neither is a message to an agent MessageOS has set up without read receipts.
The typing indicator answers 404 not_found until MessageOS turns it on for you. GET /v1/whoami shows rcsExtras true once it is.
Taking a message back
DELETE /v1/messages/{id} asks the messaging network to take back a message you sent through this API. id is the id from the send answer. It needs messages:write and no Idempotency-Key.
curl -X DELETE https://api.messageos.ai/v1/messages/msg_123 \
-H 'Authorization: Bearer mosc_...'The answer is 202:
{ "id": "msg_123", "status": "revoke_requested" }- 202 means the messaging network took the request. It does not mean the message was taken back, and this API has no status or event that says it was.
- The messaging network's reference says a message can be taken back before it is delivered, and that some phones allow it after delivery until it is read. This API passes on the request for any message not yet reported read. A message that was read is refused here with 409
conflict, and so is one that was not sent, did not arrive, or was not sent through this API. - When the messaging network says the message was already delivered, the answer is 409
conflictsaying so. When it refuses the request for this message for another reason, the answer is also 409conflict, and asking again will not help. 503provider_unavailablemeans it did not answer, or was busy or over its limit, so ask again in a moment. - Asking again for the same message is safe.
- To have a message taken back on its own after a time, send it with
ttlSecondsinstead.
Taking a message back answers 404 not_found until MessageOS turns it on for you. GET /v1/whoami shows rcsExtras true once it is.
When your own system answers
When your own system answers is the guide for this setup: the loop, the reply rules, and a checklist. This section says what a pause changes.
If your system answers customers itself, an owner or admin can pause the assistant on the Agent page of the dashboard, so customers do not get two replies. While it is paused:
POST /v1/messagesstill sends under the same rules, and a send that names a message ininReplyTois still a reply.- The
reply.receivedwebhook still fires, so your system still hears about messages from customers. - STOP, START, and HELP still get their replies from MessageOS, and
contact.opted_outandcontact.opted_instill fire. - If your business is set to opt a customer back in on any message other than STOP, that does not happen while the assistant is paused, and
contact.opted_indoes not fire for it. The customer is opted back in only by START, UNSTOP, JOIN, SUBSCRIBE, or YES, or by subscribing again in their messaging app. Until then every send to them, a reply that names their message ininReplyToincluded, returns 409blockedwith the reasonopted_out. - Scheduled messages and event playbook messages are not sent, and they are not sent later. A playbook that needs approval still writes its draft, but approving a draft from an event playbook returns 409
blockedwith the reasonagent_paused, and the draft cannot be approved again. Other drafts send when approved.
MessageOS can also set your agent to API only, when your system always answers. Everything above applies to an API-only agent in the same way, and a blocked event playbook draft still returns the reason agent_paused. The Agent page shows the agent as API only with no switch, so an owner or admin cannot turn the assistant on there. To change it, ask MessageOS.
Pausing the assistant lists everything a pause changes, and says more about API only.
Drafts
With "mode": "craft", where it is enabled for the client, MessageOS writes the text from your instructions and stores a draft instead of sending. Every other send leaves mode out.
{ "mode": "craft", "to": { "contactId": 42 }, "instructions": "Remind Pat about the visit on Tuesday at 3:00 PM.", "approval": "required" }The response is 201 with the draft id (a number), "status": "pending_approval", the text, and expiresAt. A draft expires 24 hours after it is created.
GET /v1/messages/drafts/{id}reads it.PATCH /v1/messages/drafts/{id}replaces the text while it is pending.POST /v1/messages/drafts/{id}/approvesends it once, under the same rules as any send. Approving again returns 409. If the send is blocked, for example because the person opted out, the draft is marked blocked and cannot be approved again.POST /v1/messages/drafts/{id}/discarddrops it.POST /v1/messages/draftsstores text you wrote as a draft.
"approval": "none" sends the crafted text right away. It needs the scope messages:send_ai_without_approval.
The draft endpoints are hidden until craft mode is enabled.
