- Persistent conversations with session management
- Contextual responses that build on previous interactions
- Source integration for grounded, authoritative answers
- Streaming responses for real-time conversation flow
Prerequisites
Before starting, ensure you have:- A Gloo AI Studio account
- Your Client ID and Client Secret from the API Credentials page
- Authentication setup - Complete the Authentication Tutorial first
The Chat and Message APIs require Bearer token authentication. If you haven’t set up authentication yet, follow the Authentication Tutorial to learn how to exchange your credentials for access tokens and manage token expiration.
Step 1: Creating a Chat Session
The Message API can either create a new chat session or continue an existing one. When you don’t provide achat_id
, it automatically creates a new session.
Step 2: Continuing the Conversation
Once you have a chat session, you can continue the conversation by including thechat_id
from the previous response in your next message request. You don’t need to retrieve chat history to continue the conversation - the API maintains context automatically.
Step 3: Retrieving Chat History (Optional)
If you want to view the complete conversation history, you can retrieve it using the Chat API. This is useful for displaying conversation logs or analyzing chat patterns.Complete Working Examples
Here are complete, runnable examples that demonstrate the full chat flow:Error Handling Best Practices
When working with the Message API, implement proper error handling for common scenarios:Authentication Errors
- 401 Unauthorized: Token expired or invalid
- 403 Forbidden: Insufficient permissions
Request Errors
- 400 Bad Request: Invalid request parameters
- 422 Unprocessable Entity: Validation errors
Rate Limiting
- 429 Too Many Requests: Implement backoff strategies
Network Issues
- Connection timeouts: Implement retry logic
- Network failures: Handle gracefully with user feedback
Advanced Features
Streaming Responses
Setstream: true
in your request for real-time response streaming:
Publisher Filtering
Restrict responses to specific content publishers:Response Customization
Control response length and source count:Next Steps
Now that you understand the Message API, consider exploring:- Authentication Tutorial - For detailed authentication setup
- Messages API - For additional API information
- Completions Tutorial - For stateless chat interactions
- Tool Use - For enhanced AI capabilities