Channels

Chat API

Create a Muchat API key, send messages from your server, and handle responses, conversation IDs, follow-up messages, and handoff state.

Overview

Use Chat API to add Muchat to your own application or service. The API channel creates a key for the selected agent; your application uses it to send messages and receive answers. Send requests from your server so the key is not included in public browser code.

What you can do

Send messages, continue a conversation with its returned ID, and display AI reply or human handoff status in your application.

Create an API key

Open the API channel

Choose your agent in the dashboard. Open API in Deploy and click Setup.

Create the key

Click Create API Key. The key appears under Manage Keys; select it to copy the value.

Configure it on your server

Store the value in your server’s MUCHAT_API_KEY environment variable. It is different from the agent ID and the widget’s websiteToken.

API key creation for the selected Muchat agent

Send a message

Send POST /v2/chat with an Authorization: Bearer header. This example waits for the final JSON response:

cURL
curl --request POST 'https://api.mu.chat/v2/chat' \
  --header "Authorization: Bearer $MUCHAT_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{"query":"Hello","stream":false}'

Reply text is in data.message.parts. Each text part has type set to text, with its content in text. Read conversation information and the response outcome from data.metadata:

FieldUse
conversation_idConversation ID for sending the next message in the same chat
external_message_idIncoming message ID for tracking or retries
finish_reasonGeneration outcome, such as completed or suppressed
bot_activeWhether AI is active for the conversation
handoff_statusHuman handoff state

Continue a conversation

Send the previous response’s conversation_id with the next query in your request body. Wait for the earlier request to finish before sending another; a conversation with a reply in progress does not accept a concurrent message.

  • You may assign a unique external_message_id to each logical message. For a retry, keep that ID and body unchanged to avoid creating a duplicate message.
  • Reusing the same ID with different text or another body causes a conflict. Use a new ID for a new message.
  • Treat a request without conversation_id as the start of a conversation. Save the returned ID to continue it.
  • If message is empty or the outcome is suppressed, do not invent reply text. Check the AI pause and handoff state.

Chat API is different from an API knowledge source. Use a custom action to retrieve information from your own system while preparing a reply.

Troubleshooting

StatusCheck
401Check the key and Bearer header format.
403Check channel activation and your plan’s API access.
409Check for a reused message ID with a changed body, concurrent requests, or a closed conversation.
422Send valid JSON and avoid an empty text message.

To test, send a first message, then continue with a second message using the returned ID. Check that the same conversation is recorded in Inbox. Deleting the API connection invalidates its key for subsequent requests.

Next steps

MuChat documentation

On this page