> ## Documentation Index
> Fetch the complete documentation index at: https://docs.api.ecylt.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Wbot-3 & Wbot-4

> Wbot open API

<Check>
  Wbot-4:347B is now live. Compared to the original Wbot-4, this version offers free API access.
  API access: [https://api.223387.xyz/](https://api.223387.xyz/)
</Check>

<Info>
  How to try Wbot-4-Preview-low?

  Answer: Visit [https://api.223387.xyz/ to try it out!](https://api.223387.xyz/)
</Info>

## Conversational application API

The conversational application supports session persistence, allowing previous chat history to serve as context for responses. It is suitable for chat/customer service AI and similar use cases.

#### Base URL

```
https://servicewbot.ecylt.top/v1/chat-messages
```

#### Authentication

The Service API uses `API-Key` for authentication. ***`We strongly recommend that developers store the API-Key on the backend rather than sharing it or storing it on the client side, to prevent API-Key leakage and potential financial loss.`*** All API requests should include your `API-Key` in the **`Authorization`** HTTP Header, as shown below:

```javascript theme={null}
Authorization: Bearer {API_KEY}
```

The current version of API-Key is only available to beta testers and professional users.

***

POST

### Send a conversation message

Create a conversation message.

#### Request Body

* Name`query`TypestringDescription

  User input/question content.
* Name`inputs`TypeobjectDescription

  (Optional) Allows passing values for App-defined variables. The inputs parameter contains multiple key/value pairs, where each key corresponds to a specific variable and each value is the concrete value for that variable.
* Name`response_mode`TypestringDescription
  * `streaming` Streaming mode (recommended). Implements a typewriter-style streaming return based on SSE ([**Server-Sent Events**](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)).
* Name`user`TypestringDescription

  User identifier, used to define the identity of the end user for easy retrieval and statistics. Defined by the developer, must be unique within the application.
* Name`conversation_id`TypestringDescription

  (Optional) Conversation ID. To continue a conversation based on previous chat history, the conversation\_id from the previous message must be provided.
* Name`auto_generate_name`TypeboolDescription

  (Optional) Auto-generate title, defaults to `false`. You can asynchronously generate a title by calling the conversation rename API with `auto_generate` set to `true`.

#### Response

* When `response_mode` is `streaming`, returns a ChunkChatCompletionResponse object stream sequence.
* #### ChunkChatCompletionResponse
* Returns streaming chunks of App output, with `Content-Type` as `text/event-stream`. Each streaming chunk starts with data:, and chunks are separated by \n\n (two newline characters), as shown below:
* ```streaming theme={null}
  data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n
  ```

Streaming chunks have different structures depending on the event:

* `event: message` LLM text block return event: the complete text is output in chunks.
  * `task_id` (string) Task ID, used for request tracking and the stop response API below
  * `message_id` (string) Unique message ID
  * `conversation_id` (string) Conversation ID
  * `answer` (string) LLM returned text block content
  * `created_at` (int) Creation timestamp, e.g.: 1705395332
* `event: agent_message` Text block return event in Agent mode: in Agent mode, text is output in chunks (only used in Agent mode)
  * `task_id` (string) Task ID, used for request tracking and the stop response API below
  * `message_id` (string) Unique message ID
  * `conversation_id` (string) Conversation ID
  * `answer` (string) LLM returned text block content
  * `created_at` (int) Creation timestamp, e.g.: 1705395332
* `event: agent_thought` Content related to Agent thinking steps in Agent mode, involving tool calls (only used in Agent mode)
  * `id` (string) agent\_thought ID, each Agent iteration round has a unique id
  * `task_id` (string) Task ID, used for request tracking and the stop response API below
  * `message_id` (string) Unique message ID
  * `position` (int) Position of agent\_thought in the message, e.g., position is 1 for the first iteration
  * `thought` (string) Agent's thinking content
  * `observation` (string) Return result of tool calls
  * `tool` (string) List of tools used, separated by ;
  * `tool_input` (string) Tool input, JSON formatted string (object). E.g.: `{"dalle3": {"prompt": "a cute cat"}}`
  * `created_at` (int) Creation timestamp, e.g.: 1705395332
  * `message_files` (array\[string]) File IDs associated with the current `agent_thought`
    * `file_id` (string) File ID
  * `conversation_id` (string) Conversation ID
* `event: message_file` File event, indicates a new file needs to be displayed
  * `id` (string) Unique file ID
  * `type` (string) File type, currently only image
  * `belongs_to` (string) File belongs to user or assistant, this API only returns `assistant`
  * `url` (string) File access URL
  * `conversation_id` (string) Conversation ID
* `event: message_end` Message end event, receiving this event means the streaming return has ended.
  * `task_id` (string) Task ID, used for request tracking and the stop response API below
  * `message_id` (string) Unique message ID
  * `conversation_id` (string) Conversation ID
  * `metadata` (object) Metadata
    * `usage` (Usage) Model usage information
    * `retriever_resources` (array\[RetrieverResource]) Citation and attribution segment list
* `event: message_replace` Message content replacement event. When content moderation is enabled and the output triggers moderation rules, this event replaces the message content with the preset reply.
  * `task_id` (string) Task ID, used for request tracking and the stop response API below
  * `message_id` (string) Unique message ID
  * `conversation_id` (string) Conversation ID
  * `answer` (string) Replacement content (directly replaces all LLM reply text)
  * `created_at` (int) Creation timestamp, e.g.: 1705395332
* `event: error` Exceptions during the streaming output are output as stream events. The stream ends after receiving an error event.
  * `task_id` (string) Task ID, used for request tracking and the stop response API below
  * `message_id` (string) Unique message ID
  * `status` (int) HTTP status code
  * `code` (string) Error code
  * `message` (string) Error message
* `event: ping` Ping event every 10 seconds to keep the connection alive.

#### Errors

* 404, conversation does not exist
* 400, `invalid_param`, invalid parameter
* 400, `app_unavailable`, App configuration is unavailable
* 400, `provider_not_initialize`, no available model credential configuration
* 400, `provider_quota_exceeded`, model call quota exceeded
* 400, `model_currently_not_support`, current model is unavailable
* 400, `completion_request_error`, text generation failed
* 500, internal server error

***

### Example

#### Request example

```bash theme={null}
curl -X POST 'https://servicewbot.ecylt.top/v1/chat-messages' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "inputs": {},
    "query": "What are the specs of the iPhone 13 Pro Max?",
    "response_mode": "streaming",
    "conversation_id": "",
    "user": "abc-123"
}'
```

#### Streaming mode response example

```json theme={null}
data: {"event": "agent_thought", "id": "8dcf3648-fbad-407a-85dd-73a6f43aeb9f", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "position": 1, "thought": "", "observation": "", "tool": "", "tool_input": "", "created_at": 1705639511, "message_files": [], "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
data: {"event": "agent_thought", "id": "8dcf3648-fbad-407a-85dd-73a6f43aeb9f", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "position": 1, "thought": "", "observation": "", "tool": "dalle3", "tool_input": "{\"dalle3\": {\"prompt\": \"cute Japanese anime girl with white hair, blue eyes, bunny girl suit\"}}", "created_at": 1705639511, "message_files": [], "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
data: {"event": "agent_thought", "id": "8dcf3648-fbad-407a-85dd-73a6f43aeb9f", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "position": 1, "thought": "", "observation": "image has been created and sent to user already, you should tell user to check it now.", "tool": "dalle3", "tool_input": "{\"dalle3\": {\"prompt\": \"cute Japanese anime girl with white hair, blue eyes, bunny girl suit\"}}", "created_at": 1705639511, "message_files": ["d75b7a5c-ce5e-442e-ab1b-d6a5e5b557b0"], "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
data: {"event": "agent_thought", "id": "67a99dc1-4f82-42d3-b354-18d4594840c8", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "position": 2, "thought": "", "observation": "", "tool": "", "tool_input": "", "created_at": 1705639511, "message_files": [], "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
data: {"event": "agent_message", "id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "answer": "I have created an image of a cute Japanese", "created_at": 1705639511, "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
data: {"event": "agent_message", "id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "answer": " anime girl with white hair and blue", "created_at": 1705639511, "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
data: {"event": "agent_message", "id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "answer": " eyes wearing a bunny girl" ,"created_at": 1705639511, "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
data: {"event": "agent_message", "id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "answer": " suit .", "created_at": 1705639511, "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
data: {"event": "agent_thought", "id": "67a99dc1-4f82-42d3-b354-18d4594840c8", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "position": 2, "thought": "", "observation": "", "tool": "", "tool_input": "", "created_at": 1705639511, "message_files": [], "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
```
