Skip to main content
The Chat API is retired. It was retired on 21 August 2026 and its endpoints no longer exist, so the steps below no longer run against a live API. They are kept as a reference for anyone migrating. Follow the Migration Guide to move to Completions V2 or the Responses API.
Build interactive chat with Gloo AI APIs: create chat sessions, send messages, continue conversations, and retrieve chat history. Want the concepts first? Read the Concepts guide. The Chat and Message APIs support:
  • 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 (see Streaming Responses for the idea)

Prerequisites

You need:
The Chat and Message APIs require an API key for authentication.

Step 1: Creating a Chat Session

The Message API creates a new chat session or continues an existing one. Without a chat_id, it creates a new session.

Step 2: Continuing the Conversation

To continue the conversation, include the chat_id from the previous response in your next message request. The API keeps the context, so you don’t need to retrieve chat history first.

Step 3: Retrieving Chat History (Optional)

To view the complete conversation history, use the Chat API. This is useful for displaying conversation logs or analyzing chat patterns.

Complete Working Examples

Complete, runnable examples of the full chat flow:

Error Handling Best Practices

Treat 401 and 403 as key or permission problems, fix 400 and 422 requests before resending, back off on a 429 when its error.retryable is true or it carries Retry-After, and retry connection timeouts with a bounded budget while showing your user what is happening. See Error Handling and Retries.

Advanced Features

Streaming Responses

Set stream: 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:

Working Code Sample

View Complete Code

Clone or browse the complete working examples for all 6 languages (JavaScript, TypeScript, Python, PHP, Go, Java) with setup instructions.

Next Steps

Explore next:
  1. Authentication Tutorial - For detailed authentication setup
  2. Messages API - For additional API information
  3. Completions Tutorial - For stateless chat interactions
  4. Tool Use - For enhanced AI capabilities