Chat API

Generate a dynamic chat response with MCP support for an agent using the Holoworld Chat API.

Authentication

All API requests require authentication using an API key. The API key should be included in the request headers as x-api-key.

To obtain an API key:

  1. Register for an account at Holoworld

  2. Navigate to your profile > settings

  3. Copy the API key. From now on, this key be referenced as YOUR_API_KEY

Before getting started

Ensure you have an Agent with a valid agent created on Holoworld (consult Create Agent for more information). Go to your agent's profile page and copy the Agent ID (the agent ID is the last part of the URL after the slash on the Agent's profile page)

From now on, this will be referenced as YOUR_AGENT_ID.

API Endpoints

Send a message and receive a response /api/chat

Initiates a new video rendering job with the specified parameters.

  • URL: https://holoworld-llm.com

  • Method: POST

  • Headers:

    • Content-Type: application/json

    • x-api-key: YOUR_API_KEY

Request Body

Chat History Format

The chat history should be an array of ChatMessage objects with the following structure:

Streaming Response

The endpoint returns an HTTP stream containing a series of JSON chunks, each separated by double newlines (\n\n). Each chunk represents a different event in the response generation process.

Streaming Chunk Format

Each streaming chunk follows this structure:

Chunk Types

  • start: Indicates the beginning of a new message or response

  • content: Contains a fragment of the agent's text response

  • tool_call: Indicates the agent is invoking a tool, with tool name and arguments

  • tool_result: Contains the result of a tool invocation

  • completion: Signals completion of a message or tool operation

  • end: Marks the end of the entire response

  • error: Contains error information if something went wrong

  • unknown: Used for unrecognized event types

Handling Streaming Responses

Standard vs. Tool Messages

The API distinguishes between standard content messages and tool-invocation messages:

Standard Message

A regular message from the AI with text content that's displayed directly to the user:

Tool Message

A special message type that indicates the AI has called a tool to perform a task:

UI Considerations

In a chat interface, these message types should be displayed differently:

  • Standard Messages: Displayed as regular chat bubbles with the AI's text content.

  • Tool Messages: Displayed as a specialized UI component that shows:

    • The tool being used (e.g., "Calculator", "Weather API")

    • The query or input to the tool

    • The result returned by the tool

Tool messages can be styled differently to visually distinguish them from regular content, such as using a different background color, adding an icon representing the tool type, or displaying them in a card-like interface with clear sections for the tool name, query, and result.

For example, a calculator tool might be displayed with a calculator icon, showing the calculation performed and its result in a structured format, while a weather tool might show forecast information with appropriate weather icons.

Example of collapsable tool query and content

Error Handling

The API may return error events in the stream. These should be handled appropriately:

Last updated