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

# Chat history

> Request the stored messages of a chat with optional date filters

**Auth:** `TokenAccount` or `TokenInstance` • **Rate-limit:** `Global` (100/min) • **Idempotent:** yes

## Description

Returns the stored messages of a specific chat, ordered from newest to oldest. You can control the amount with `count` and filter by a date window with `from`/`to`.

<Note>
  **There is no pagination cursor.** To paginate, adjust the `from` and `to` filters. The `hasMore` field is a heuristic: it is `true` when the number of returned messages == `count` (likely there are more).
</Note>

## Examples

### Last 50

Minimal form: pass only `number` and use the default `count` of 50 messages, returning the most recent ones in the chat ordered from newest to oldest.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://ryzeapi.cloud/api/chat/history/$Instance_Name" \
    -H "token: $Token_Instance" \
    -H "Content-Type: application/json" \
    -d '{"number":"5511999999999"}'
  ```

  ```javascript JavaScript theme={null}
  await fetch(`https://ryzeapi.cloud/api/chat/history/${process.env.Instance_Name}`, {
    method: "POST",
    headers: {
      "token":        process.env.Token_Instance,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({ number: "5511999999999" })
  });
  ```

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

  requests.post(
      f"https://ryzeapi.cloud/api/chat/history/{os.environ['Instance_Name']}",
      headers={
          "token":        os.environ["Token_Instance"],
          "Content-Type": "application/json"
      },
      json={"number": "5511999999999"}
  )
  ```

  ```go Go theme={null}
  package main

  import (
      "net/http"
      "os"
      "strings"
  )

  func main() {
      body := strings.NewReader(`{"number":"5511999999999"}`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/chat/history/"+os.Getenv("Instance_Name"), body)
      req.Header.Set("token", os.Getenv("Token_Instance"))
      req.Header.Set("Content-Type", "application/json")
      http.DefaultClient.Do(req)
  }
  ```
</CodeGroup>

### With a date window

Retrieves up to 200 messages sent between April 20 and April 28, 2026 (`from`/`to` in ISO 8601). Useful to extract history for a specific interval or to paginate using `to` as a cursor.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://ryzeapi.cloud/api/chat/history/$Instance_Name" \
    -H "token: $Token_Instance" \
    -H "Content-Type: application/json" \
    -d '{
      "number": "5511999999999",
      "count":  200,
      "from":   "2026-04-20T00:00:00Z",
      "to":     "2026-04-28T23:59:59Z"
    }'
  ```

  ```javascript JavaScript theme={null}
  await fetch(`https://ryzeapi.cloud/api/chat/history/${process.env.Instance_Name}`, {
    method: "POST",
    headers: {
      "token":        process.env.Token_Instance,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      number: "5511999999999",
      count:  200,
      from:   "2026-04-20T00:00:00Z",
      to:     "2026-04-28T23:59:59Z"
    })
  });
  ```

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

  requests.post(
      f"https://ryzeapi.cloud/api/chat/history/{os.environ['Instance_Name']}",
      headers={
          "token":        os.environ["Token_Instance"],
          "Content-Type": "application/json"
      },
      json={
          "number": "5511999999999",
          "count":  200,
          "from":   "2026-04-20T00:00:00Z",
          "to":     "2026-04-28T23:59:59Z"
      }
  )
  ```

  ```go Go theme={null}
  package main

  import (
      "net/http"
      "os"
      "strings"
  )

  func main() {
      body := strings.NewReader(`{
          "number": "5511999999999",
          "count":  200,
          "from":   "2026-04-20T00:00:00Z",
          "to":     "2026-04-28T23:59:59Z"
      }`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/chat/history/"+os.Getenv("Instance_Name"), body)
      req.Header.Set("token", os.Getenv("Token_Instance"))
      req.Header.Set("Content-Type", "application/json")
      http.DefaultClient.Do(req)
  }
  ```
</CodeGroup>

### Group

Same logic, but with `number` pointing to a group JID (`@g.us`) and `count` of 100. Each item in `messages[]` carries `senderJid` filled with the message author within the group.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://ryzeapi.cloud/api/chat/history/$Instance_Name" \
    -H "token: $Token_Instance" \
    -H "Content-Type: application/json" \
    -d '{
      "number": "120363123456789@g.us",
      "count":  100
    }'
  ```

  ```javascript JavaScript theme={null}
  await fetch(`https://ryzeapi.cloud/api/chat/history/${process.env.Instance_Name}`, {
    method: "POST",
    headers: {
      "token":        process.env.Token_Instance,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      number: "120363123456789@g.us",
      count:  100
    })
  });
  ```

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

  requests.post(
      f"https://ryzeapi.cloud/api/chat/history/{os.environ['Instance_Name']}",
      headers={
          "token":        os.environ["Token_Instance"],
          "Content-Type": "application/json"
      },
      json={
          "number": "120363123456789@g.us",
          "count":  100
      }
  )
  ```

  ```go Go theme={null}
  package main

  import (
      "net/http"
      "os"
      "strings"
  )

  func main() {
      body := strings.NewReader(`{
          "number": "120363123456789@g.us",
          "count":  100
      }`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/chat/history/"+os.Getenv("Instance_Name"), body)
      req.Header.Set("token", os.Getenv("Token_Instance"))
      req.Header.Set("Content-Type", "application/json")
      http.DefaultClient.Do(req)
  }
  ```
</CodeGroup>

## Success response

`messages` carries the messages in reverse chronological order (newest first). `count` indicates how many items came in this page and `hasMore` is `true` when you reached exactly the requested `count`, signaling that there may be more messages, paginate by using the `from`/`to` from the last returned message. `chat_jid` is the resolved JID of the requested chat.

```json 200 OK theme={null}
{
  "success": true,
  "message": "Retrieved 2 messages from chat history",
  "chat_jid": "5511999999999@s.whatsapp.net",
  "messages": [
    {
      "id": "3EB08FCF27E532F1B0F5",
      "fromMe": true,
      "timestamp": "2026-04-28T14:30:00Z",
      "content": "Hi",
      "type": "text",
      "chatJid": "5511999999999@s.whatsapp.net",
      "senderJid": ""
    },
    {
      "id": "3EB08FCF27E532F1B0F4",
      "fromMe": false,
      "timestamp": "2026-04-28T14:29:55Z",
      "content": "Good morning!",
      "type": "text",
      "chatJid": "5511999999999@s.whatsapp.net",
      "senderJid": "5511999999999@s.whatsapp.net"
    }
  ],
  "count": 2,
  "hasMore": false
}
```

## Path parameters

<ParamField path="instance" type="string" required>
  Instance name.
</ParamField>

## Headers

| Name           | Required                 | Example            | Description                    |
| -------------- | ------------------------ | ------------------ | ------------------------------ |
| `Content-Type` | yes                      | `application/json` | ,                              |
| `token`        | yes (or `Authorization`) | `a1b2c3d4-...`     | TokenAccount or TokenInstance. |

## Request body

<ParamField body="number" type="string" required>
  Phone number, private JID (`...@s.whatsapp.net` or `...@lid`), group JID (`...@g.us`), or newsletter.
</ParamField>

<ParamField body="count" type="int" default="50">
  Maximum number of messages to return. No internal upper limit.
</ParamField>

<ParamField body="from" type="string">
  ISO 8601 / RFC3339. Messages **starting from** this date (inclusive).
</ParamField>

<ParamField body="to" type="string">
  ISO 8601 / RFC3339. Messages **up to** this date (inclusive).
</ParamField>

## Notes and gotchas

<Note>
  * Works **even when the instance is disconnected**, reads directly from the ingestion database.
  * To paginate safely, set `to = timestamp of the oldest message already received` in the previous call.
  * `hasMore=true` does not guarantee 100% that more messages exist, it is just a heuristic based on the requested count.
</Note>

## Error responses

| HTTP | `error.message`                                                                  | When it happens |
| ---- | -------------------------------------------------------------------------------- | --------------- |
| 400  | `Instance name is required`                                                      | ,               |
| 400  | `Invalid request body: <...>`                                                    | Malformed JSON. |
| 400  | `Number is required`                                                             | ,               |
| 400  | `invalid 'from' date format. Use ISO 8601 format (e.g., '2026-02-16T18:32:39Z')` | ,               |
| 400  | `invalid 'to' date format. Use ISO 8601 format (e.g., '2026-02-16T18:32:39Z')`   | ,               |
| 401  | `Invalid token`                                                                  | ,               |
| 404  | `Instance not found`                                                             | ,               |

```json Error 400 theme={null}
{
  "success": false,
  "error": { "message": "Number is required" }
}
```

## Related

<CardGroup cols={2}>
  <Card title="Find message" href="/en/api/chat/find-message">
    Retrieve a specific message from history.
  </Card>

  <Card title="Media as base64" href="/en/api/chat/media-base64">
    Download a media item referenced in history.
  </Card>
</CardGroup>
