> For the complete documentation index, see [llms.txt](https://api.pdf.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api.pdf.ai/v1/chat-history.md).

# Chat history

To get the chat history of a PDF you need `docId` of that PDF.&#x20;

Using `/v1/history` API you can get the complete chat history in the desired number of pages and in the desired order.

{% hint style="info" %}
Ensure that when you call the [Chat with PDF](/v1/chat-with-pdf.md) API, you set `save_chat` to true to let the chat history to be saved.
{% endhint %}

## Chat history of a PDF

<mark style="color:green;">`POST`</mark> `https://pdf.ai/api/v1/history`

To get the chat history of the PDF using its `docId`

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-API-Key<mark style="color:red;">\*</mark> | string | \<API-Key>  |

#### Request Body

| Name                                    | Type   | Description                                                                                   |
| --------------------------------------- | ------ | --------------------------------------------------------------------------------------------- |
| docId<mark style="color:red;">\*</mark> | string | Document ID obtained after uploading PDF                                                      |
| resultsPerPage                          | number | Number of results you want per page. Default: 10. Max: 100                                    |
| pageNumber                              | number | <p>Page number you want results from <br>Default: 1</p>                                       |
| sortOrder                               | string | <p>Order of the messages<br>"asc" for ascending, "desc" for descending<br>Default: "desc"</p> |

{% tabs %}
{% tab title="200 History of the PDF" %}
{% code overflow="wrap" %}

```json
{
    "messages": [
        {
            "role": "assistant",
            "content": "It is in Japan",
            "createdAt": "2024-10-16T06:58:03.044Z",
            "references": [
              {
                 "pageNumber": 1,
                 "fromLine": 41,
                 "toLine": 48
              }
             ]
        },
        {
            "role": "user",
            "content": "Where is Tokyo?",
            "createdAt": "2024-10-16T06:58:03.043Z",
            "references": []
        }
    ],
    "totalMessages": 8,
    "totalPages": 1,
    "currentPage": 1
}
```

{% endcode %}
{% endtab %}

{% tab title="401 Invalid API key" %}

```json
{
    "error": "Invalid API key"
}
```

{% endtab %}

{% tab title="400: Bad Request No API key or docId is present" %}

```json
{
    "error": "No API key present"
}
```

{% endtab %}
{% endtabs %}
