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
/latestConsumerChatId
https://chat-api.atriai.chat/latestConsumerChatId
Authentication
Query Parameters
The following query parameters can be included in the URL:
URL Query Parameters
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:
The ID of the most recent chat for the consumer, or null if no chats exist
ISO timestamp when the latest chat was last updated (only present if chat_id is not null)
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
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.