Overview
This endpoint retrieves the agent’s first/greeting message that should be displayed when starting a new chat. Use this to initialize your chat UI before the user sends their first message, providing a welcoming experience.
Authentication
Your eigi.ai API key. Must be prefixed with vk_.
Path Parameters
The unique identifier of the agent. Example: 68ea2517dbb84c09bae1ba0a
Response
A new session ID created for this chat. Use this for subsequent messages.
The agent’s greeting/welcome message configured in the agent settings.
The agent ID (same as the request parameter).
Examples
Get Agent’s First Message
curl -X GET "https://prod.eigi.ai/v1/public/agents/68ea2517dbb84c09bae1ba0a/first-message" \
-H "X-API-Key: vk_your_api_key_here"
Response Example
{
"session_id": "58a6b549-ef07-4a31-86bc-0eb0e026840a",
"first_message": "Hello! Welcome to Acme Corp support. I'm your AI assistant, ready to help with any questions about our products, services, or your account. How can I assist you today?",
"agent_id": "68ea2517dbb84c09bae1ba0a"
}
Typical Workflow
Here’s how to properly initialize a chat conversation:
Get First Message
Call this endpoint when a user opens your chat interface.
Display Greeting
Show the first_message to the user in your chat UI.
Store Session ID
Save the session_id for use in subsequent messages.
Continue Chat
When the user sends a message, use the stored session_id with the chat
endpoint.
Complete Chat Flow Example
class ChatClient {
constructor(apiKey, agentId) {
this.apiKey = apiKey;
this.agentId = agentId;
this.sessionId = null;
this.messages = [];
}
async initialize() {
// Step 1: Get the agent's greeting
const response = await fetch(
`https://prod.eigi.ai/v1/public/agents/${this.agentId}/first-message`,
{
headers: { "X-API-Key": this.apiKey },
}
);
const data = await response.json();
// Step 2: Store session and display greeting
this.sessionId = data.session_id;
this.messages.push({
role: "assistant",
content: data.first_message,
});
return data.first_message;
}
async sendMessage(userMessage) {
// Step 3: Send user message with session ID
this.messages.push({ role: "user", content: userMessage });
const response = await fetch("https://prod.eigi.ai/v1/public/chat", {
method: "POST",
headers: {
"X-API-Key": this.apiKey,
"Content-Type": "application/json",
},
body: JSON.stringify({
agent_id: this.agentId,
session_id: this.sessionId,
message: userMessage,
streaming: false,
}),
});
const data = await response.json();
this.messages.push({
role: "assistant",
content: data.response,
});
return data.response;
}
}
// Usage
const chat = new ChatClient("vk_your_api_key", "68ea2517dbb84c09bae1ba0a");
const greeting = await chat.initialize();
console.log("Bot:", greeting);
const reply = await chat.sendMessage("I need help with my order");
console.log("Bot:", reply);
Error Responses
| Status Code | Description |
|---|
| 401 Unauthorized | Missing, invalid, inactive, or expired API key |
| 403 Forbidden | API key owner doesn’t have access to this agent |
| 404 Not Found | Agent not found with the given ID |
{
"detail": "Agent not found"
}
Best Practices
Always Initialize First: Call this endpoint before displaying your chat UI
to ensure a proper greeting and valid session.
Cache When Appropriate: If you’re opening multiple chats to the same
agent, you can cache the first message content (but not the session ID).
Handle Errors Gracefully: Have a fallback greeting message in case this
endpoint fails.
API key for authentication. Get your API key from the eigi.ai Dashboard under Settings → API Keys.
Successfully retrieved first message
New session ID for the chat