# Retrieve agent history (/en/api-reference/api-ref/conversational-ai/history)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

Retrieves conversation history for a running Conversational AI agent.

- OpenAPI: /openapi/conversational-ai/rest-api.en.yaml
- Operation ID: get-history
- Method: GET
- Path: /v2/projects/{appid}/agents/{agentId}/history
- Endpoint: https://api.agora.io/api/conversational-ai-agent/v2/projects/{appid}/agents/{agentId}/history

## Servers

- https://api.agora.io/api/conversational-ai-agent

Call this endpoint while the agent is running to retrieve the conversation history between the user and the Conversational AI agent.


## Authorization

This endpoint requires authentication.

- `tokenAuth`
- `basicAuth`

## Parameters

- `appid` (path, required, string) - The App ID of the project.
- `agentId` (path, required, string) - The agent instance ID you obtained after successfully calling `join` to [Start a conversational AI agent](/en/api-reference/api-ref/conversational-ai/join).

## Request body

No request body.

## Request examples

### curl

```bash
curl --request get \
        --url https://api.agora.io/api/conversational-ai-agent/v2/projects/:appid/agents/:agentId/history \
        --header 'Authorization: Basic <credentials>'
```

### Python

```python
import requests

    url = "https://api.agora.io/api/conversational-ai-agent/v2/projects/:appid/agents/:agentId/history"

    headers = {"Authorization": "Basic <credentials>"}

    response = requests.request("get", url, headers=headers)

    print(response.text)
```

### Node.js

```javascript
const url = 'https://api.agora.io/api/conversational-ai-agent/v2/projects/:appid/agents/:agentId/history';
    const options = {method: 'get', headers: {Authorization: 'Basic <credentials>'}};

    fetch(url, options)
      .then(res => res.json())
      .then(json => console.log(json))
      .catch(err => console.error(err));
```


### Response

- If the returned status code is `200`, the request was successful. The response body contains the result of the request.

- If the returned status code is not `200`, the request failed. The response body includes the error code and description. Refer to [status codes](/en/api-reference/api-ref/conversational-ai/status-codes) to understand the possible reasons for failure.


## Responses

### 200

The request was successful. The response body contains the result of the request.

- `agent_id` (string) - Unique identifier of the agent.
- `start_ts` (integer) - Agent creation timestamp.
- `status` (string) - Agent status. Only supports querying the running agent.
- `contents` (array) - Agent history.
  - `contents.items` (object)
    - `contents.items.role` (string) - The message sender.
- `user`: User
- `assistant`: AI agent
      - Allowed: `user` | `assistant`
    - `contents.items.content` (string) - Message content.
    - `contents.items.speech_start_ms` (integer) - Unix timestamp in milliseconds indicating when the user started speaking or the agent started TTS playback. Only returned when `llm.vendor` is `custom`.
    - `contents.items.speech_end_ms` (integer) - Unix timestamp in milliseconds indicating when the user stopped speaking, or when TTS playback completed or was interrupted. Only returned when `llm.vendor` is `custom`.
    - `contents.items.speech_algorithmic_delay` (integer) - The total delay in milliseconds introduced by audio processing algorithms, including noise reduction, background voice suppression, and voiceprint locking, after audio is captured from the user's microphone. Use this value to align timestamps with cloud recording audio.

Only returned when:
- `llm.vendor` is `custom`
- `contents[].role` is `user`
- Actual voice input is present
### default

The request failed. The response body includes the error details.

- `detail` (string) - Detailed error information.
- `reason` (string) - The reason for the failure.

## Response examples

### 200

```json
{
  "agent_id": "xxxx",
  "start_ts": 123,
  "status": "RUNNING",
  "contents": [
    {
      "role": "user",
      "content": "hello."
    },
    {
      "role": "assistant",
      "content": "hi, how can I help you?"
    }
  ]
}
```
