Skip to main content
GET
/
v1
/
public
/
agents
/
{agent_id}
/
first-message
Get First Message
curl --request GET \
  --url https://prod.eigi.ai/v1/public/agents/{agent_id}/first-message \
  --header 'X-API-Key: <api-key>'
{
  "session_id": "<string>",
  "first_message": "<string>",
  "agent_id": "<string>"
}

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

X-API-Key
string
required
Your eigi.ai API key. Must be prefixed with vk_.

Path Parameters

agent_id
string
required
The unique identifier of the agent. Example: 68ea2517dbb84c09bae1ba0a

Response

session_id
string
A new session ID created for this chat. Use this for subsequent messages.
first_message
string
The agent’s greeting/welcome message configured in the agent settings.
agent_id
string
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:
1

Get First Message

Call this endpoint when a user opens your chat interface.
2

Display Greeting

Show the first_message to the user in your chat UI.
3

Store Session ID

Save the session_id for use in subsequent messages.
4

Continue Chat

When the user sends a message, use the stored session_id with the chat endpoint.

Complete Chat Flow Example

JavaScript
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 CodeDescription
401 UnauthorizedMissing, invalid, inactive, or expired API key
403 ForbiddenAPI key owner doesn’t have access to this agent
404 Not FoundAgent not found with the given ID
Example Error Response
{
  "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.

Authorizations

X-API-Key
string
header
required

API key for authentication. Get your API key from the eigi.ai Dashboard under Settings → API Keys.

Path Parameters

agent_id
string
required

The unique agent ID

Response

Successfully retrieved first message

session_id
string

New session ID for the chat

first_message
string

Agent's greeting message

agent_id
string

The agent ID