Latest Consumer Chat ID

Get the most recent chat ID for a specific consumer. This endpoint is useful when you need to continue the latest conversation with a consumer or check if they have any active chats.

Endpoint

GET/latestConsumerChatId
Retrieve the chat ID of the most recent conversation for a specific consumer within the authenticated project, based on the last updated timestamp.
https://chat-api.atriai.chat/latestConsumerChatId

Authentication

Type:
Bearer Token
Header:
Authorization
Your project-specific API key for the Chat service

Query Parameters

The following query parameters can be included in the URL:

URL Query Parameters

consumer_idstringREQUIRED

The unique identifier for the consumer whose latest chat ID you want to retrieve

Validation Rules

The following validation rules apply to the request:

consumer_id is required

A valid consumer_id must be provided as a query parameter

Valid API key required

A valid project-specific API key must be provided in the Authorization header

Consumer must belong to project

Only chats for consumers that belong to the authenticated project will be considered

Response Schema

The API returns a JSON object with the following structure:

chat_idstring | null

The ID of the most recent chat for the consumer, or null if no chats exist

last_updated_atstring

ISO timestamp when the latest chat was last updated (only present if chat_id is not null)

messagestring

Descriptive message about the result (only present if no chats are found)

Use Cases

Common scenarios where this endpoint is useful:

  • Continue the most recent conversation with a returning user
  • Check if a user has any existing conversation history
  • Implement 'resume chat' functionality in your application
  • Quick access to the latest interaction with a specific consumer
  • Efficient routing of users to their most recent chat session
  • Analytics on the latest activity timestamp for consumers

Implementation Tips

Best practices when using this endpoint:

  • Always check if chat_id is null before attempting to use it
  • Use this endpoint before starting a new conversation to offer resuming the latest chat
  • Cache the result temporarily to avoid repeated API calls
  • Consider the last_updated_at timestamp to determine chat freshness
  • Handle the case where no chats exist gracefully in your UI

Usage Examples

Common usage patterns for the Latest Consumer Chat ID endpoint:

Get Latest Chat ID

Retrieve the latest chat ID for a consumer

https://chat-api.atriai.chat/latestConsumerChatId?consumer_id=user_12345

Response Examples

Different response scenarios:

Consumer with Existing Chats

Response when the consumer has chat history:

{
  "chat_id": "chat_20240711_143052_abc123",
  "last_updated_at": "2024-07-11T14:35:21.456Z"
}

Consumer with No Chats

Response when the consumer has no chat history:

{
  "chat_id": null,
  "message": "No chats found for this consumer"
}

Try it out

Select a language to see how to make a request to the AI Chat API

C
cURL Request
curl -L 'https://chat-api.atriai.chat/latestConsumerChatId?consumer_id=your_consumer_id_here' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY'
!

API Key Required

Replace YOUR_API_KEY with your actual api key to authenticate requests.