> ## Documentation Index
> Fetch the complete documentation index at: https://docs.deeptrace.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Send Chat Message

> Send a message and receive an AI-powered response

Send a message and receive an AI-powered response. Supports multi-turn conversations by passing a `chat_id` from a previous response.

## Headers

<ParamField header="Authorization" type="string" required>
  Bearer token with your Deeptrace API key. Format: `Bearer <your_api_key>`.
</ParamField>

## Query Parameters

<ParamField query="stream" type="boolean" default="false">
  Enable Server-Sent Events streaming.
</ParamField>

## Body

<ParamField body="messages" type="object[]" required>
  Array of message objects (minimum 1).

  <Expandable title="Message object">
    <ParamField body="role" type="string" required>
      `"user"` or `"assistant"`.
    </ParamField>

    <ParamField body="content" type="string" required>
      The message text.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="chat_id" type="string">
  ID of an existing chat to continue a conversation.
</ParamField>

<ParamField body="model" type="string" default="claude-opus-4-6">
  Model to use for the response.
</ParamField>

<ParamField body="system_prompt" type="string">
  Custom system prompt override.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.deeptrace.com/api/v1/chat" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer <your_api_key>" \
    -d '{
      "messages": [
        {"role": "user", "content": "What errors are happening in production right now?"}
      ]
    }'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.deeptrace.com/api/v1/chat",
      headers={"Authorization": "Bearer <your_api_key>"},
      json={
          "messages": [
              {"role": "user", "content": "What errors are happening in production right now?"}
          ]
      }
  )

  data = response.json()
  print(data["chat_id"], data["response"])
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    "https://api.deeptrace.com/api/v1/chat",
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer <your_api_key>",
      },
      body: JSON.stringify({
        messages: [
          { role: "user", content: "What errors are happening in production right now?" },
        ],
      }),
    }
  );

  const data = await response.json();
  console.log(data.chat_id, data.response);
  ```
</RequestExample>

## Returns

Returns the chat ID and the assistant's response along with usage information.

<ResponseExample>
  ```json 200 — Success theme={null}
  {
    "chat_id": "baa1b1be-4905-4448-9a37-159f08dfc570",
    "response": "Let me check your error tracking tools...",
    "usage": {
      "input_tokens": 3,
      "output_tokens": 624,
      "cache_creation_input_tokens": 92161,
      "cache_read_input_tokens": 0,
      "cost": 0.59,
      "model": "claude-opus-4-6",
      "api_calls_count": 1
    }
  }
  ```
</ResponseExample>

<ResponseField name="chat_id" type="string" required>
  UUID of the chat. Use this to continue the conversation or retrieve the chat later.
</ResponseField>

<ResponseField name="response" type="string" required>
  The assistant's response text.
</ResponseField>

<ResponseField name="usage" type="object" required>
  Token usage and cost information for the request.

  <Expandable title="Usage object">
    <ResponseField name="input_tokens" type="integer">Input tokens consumed.</ResponseField>
    <ResponseField name="output_tokens" type="integer">Output tokens generated.</ResponseField>
    <ResponseField name="cache_creation_input_tokens" type="integer">Tokens used to create the prompt cache.</ResponseField>
    <ResponseField name="cache_read_input_tokens" type="integer">Tokens read from prompt cache.</ResponseField>
    <ResponseField name="cost" type="number">Cost in USD.</ResponseField>
    <ResponseField name="model" type="string">Model used for the response.</ResponseField>
    <ResponseField name="api_calls_count" type="integer">Number of API calls made.</ResponseField>
  </Expandable>
</ResponseField>

## Continuing a Conversation

Pass the `chat_id` from a previous response to continue the conversation:

```bash theme={null}
curl -X POST "https://api.deeptrace.com/api/v1/chat" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your_api_key>" \
  -d '{
    "chat_id": "baa1b1be-4905-4448-9a37-159f08dfc570",
    "messages": [
      {"role": "user", "content": "Can you dig deeper into the top error?"}
    ]
  }'
```

## Streaming

Add `?stream=true` to receive Server-Sent Events:

```bash theme={null}
curl -X POST "https://api.deeptrace.com/api/v1/chat?stream=true" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your_api_key>" \
  -d '{
    "messages": [
      {"role": "user", "content": "What errors are happening in production?"}
    ]
  }'
```

**Stream event types:**

| Event Type        | Description                                         |
| ----------------- | --------------------------------------------------- |
| `start`           | Stream initiated, includes `messageId` and `chatId` |
| `reasoning-start` | Beginning of reasoning block                        |
| `reasoning-delta` | Incremental reasoning text                          |
| `reasoning-end`   | End of reasoning block                              |
| `text-start`      | Beginning of response text                          |
| `text-delta`      | Incremental response text                           |
| `text-end`        | End of response text                                |
