curl --request POST \
--url https://api.happenstance.ai/v1/chat/{chat_id}/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"message": "<string>",
"answers": [
{
"question_index": 1,
"selected": [
"<string>"
],
"other": "<string>"
}
]
}
'import requests
url = "https://api.happenstance.ai/v1/chat/{chat_id}/messages"
payload = {
"message": "<string>",
"answers": [
{
"question_index": 1,
"selected": ["<string>"],
"other": "<string>"
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
message: '<string>',
answers: [{question_index: 1, selected: ['<string>'], other: '<string>'}]
})
};
fetch('https://api.happenstance.ai/v1/chat/{chat_id}/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"chat_id": "<string>",
"url": "<string>",
"turn_id": "<string>",
"status": "queued",
"joined": false,
"answered": false,
"warning": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}Send Chat Message
Send a message to a chat started through the API. Returns at once with the turn to poll. A message sent while a turn is still working joins that turn (joined: true): Chat takes it into the work in progress, and the turn’s reply and charge cover both messages.
When a turn ends with stop_reason needs_input, Chat waits on the questions in its reply.questions: send answers (by question index and option label), a message that answers them in words, or both. The answer starts the next turn (answered: true).
Returns 402 when the balance is below 3 credits for this message and for each turn still running, 409 for a chat started in the app.
curl --request POST \
--url https://api.happenstance.ai/v1/chat/{chat_id}/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"message": "<string>",
"answers": [
{
"question_index": 1,
"selected": [
"<string>"
],
"other": "<string>"
}
]
}
'import requests
url = "https://api.happenstance.ai/v1/chat/{chat_id}/messages"
payload = {
"message": "<string>",
"answers": [
{
"question_index": 1,
"selected": ["<string>"],
"other": "<string>"
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
message: '<string>',
answers: [{question_index: 1, selected: ['<string>'], other: '<string>'}]
})
};
fetch('https://api.happenstance.ai/v1/chat/{chat_id}/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"chat_id": "<string>",
"url": "<string>",
"turn_id": "<string>",
"status": "queued",
"joined": false,
"answered": false,
"warning": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "https://developer.happenstance.ai/api-reference/introduction#error-response-format",
"detail": "<string>",
"instance": "<string>"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
Body
The message to send, in plain text. While Chat waits on its questions (a turn with stop_reason needs_input), a message answers them in words.
Answers to Chat's open questions, one per question you answer. Send answers, a message, or both (the message then adds to the answers).
Show child attributes
Show child attributes
Response
Successful Response
Response from POST /v1/chat/{chat_id}/messages.
The chat's id
The chat in the Happenstance app
The turn to poll: the one this message started, or the running turn it joined
The turn's status
queued, running, completed, failed, cancelled True when the message joined the turn that was still running: Chat takes it into that turn's work, and the turn's reply and charge cover both messages
True when the message or answers answered Chat's open questions
Warning message when credit balance is low
