# Reply to a chat

Posts your next message to an existing chat and starts the next agent turn. The request returns as soon as the message is saved. Poll the [chat status](https://betterstack.com/docs/ai-sre/api/chats/status/) until it leaves `processing`, then [get the chat](https://betterstack.com/docs/ai-sre/api/chats/get/) to read the answer.

[endpoint]
base_url = "https://chat.betterstack.com"
path = "/api/v2/chats/{chat_id}/messages"
method = "POST"

[[path_param]]
name = "chat_id"
description = "The ID of the chat to reply to."
required = true
type = "string"

[[body_param]]
name = "message"
description = "Your message to the agent."
required = true
type = "string"

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"

[[header]]
name = "Content-Type"
description = "application/json"
required = true
type = "string"
[/endpoint]

[responses]
[[response]]
status = 201
description = '''Returns the chat, still processing. Its transcript ends with your message and a placeholder for the agent's answer.'''
body = '''{
  "data": {
    "id": "12345",
    "type": "chat",
    "attributes": {
      "team_id": 123456,
      "team_name": "example-team",
      "name": "Checkout 5xx spike",
      "status": "processing",
      "message_count": 4,
      "last_message_at": "2026-09-07T10:35:00.000Z",
      "total_tokens": 15420,
      "created_at": "2026-09-07T10:30:00.000Z",
      "updated_at": "2026-09-07T10:35:00.000Z",
      "messages": [
        {
          "id": 9001,
          "message_type": "user",
          "text": "Why did checkout start returning 5xx at 10:15?",
          "artifacts": [],
          "created_at": "2026-09-07T10:30:00.000Z",
          "user": null
        },
        {
          "id": 9002,
          "message_type": "ai",
          "text": "The 5xx responses come from checkout-api pods restarting after the 10:12 deploy of v2.4.0. The new version fails its readiness probe because PAYMENTS_URL is unset. Set it in the deployment manifest and roll out again.",
          "artifacts": [],
          "created_at": "2026-09-07T10:32:18.000Z",
          "user": null
        },
        {
          "id": 9003,
          "message_type": "user",
          "text": "Was the payments service affected too?",
          "artifacts": [],
          "created_at": "2026-09-07T10:35:00.000Z",
          "user": null
        },
        {
          "id": 9004,
          "message_type": "ai",
          "text": null,
          "artifacts": [],
          "created_at": "2026-09-07T10:35:00.000Z",
          "user": null
        }
      ],
      "pending_confirmations": []
    }
  }
}'''

[[response]]
status = 401
description = '''Unauthorized'''
body = '''{
  "errors": "Invalid authentication"
}'''

[[response]]
status = 403
description = '''Forbidden - AI SRE Not Included In Your Plan'''
body = '''{
  "errors": "AI SRE is not available on this plan."
}'''

[[response]]
status = 404
description = '''Not Found'''
body = '''{
  "errors": "Resource with the provided ID was not found"
}'''

[[response]]
status = 409
description = '''Conflict - The Agent Is Still Working'''
body = '''{
  "errors": "The agent is still working on this chat (status: processing). Poll GET /api/v2/chats/:id/status and retry once it leaves processing."
}'''

[[response]]
status = 409
description = '''Conflict - A Confirmation Is Pending'''
body = '''{
  "errors": "The agent is waiting on a tool-use confirmation (status: awaiting_confirmation). Resolve it via PATCH /api/v2/chats/:chat_id/confirmations/:id before replying."
}'''

[[response]]
status = 422
description = '''Unprocessable Entity - Missing Required Attributes'''
body = '''{
  "errors": "Sorry, you are missing some required attributes",
  "required_attributes": ["message"]
}'''
[/responses]

#### Example cURL

```shell
[label Example]
curl --request POST \
  --url https://chat.betterstack.com/api/v2/chats/12345/messages \
  --header "Authorization: Bearer $TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{
    "message": "Was the payments service affected too?"
  }'
```
