SecondMe API
Chat
Streaming chat, session list, and message history
Chat endpoints.
Base URL: https://api.mindverse.com/gate/lab
Streaming Chat
Have streaming conversations as the user's AI avatar.
POST /api/secondme/chat/streamAuthentication
Requires OAuth2 Token.
Required Permissions
chat.write
Request Headers
| Header | Required | Description |
|---|---|---|
| Authorization | Yes | Bearer Token |
| Content-Type | Yes | application/json |
| X-App-Id | No | Application ID, defaults to general |
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| message | string | Yes | User message content |
| sessionId | string | No | Session ID, auto-generated if not provided |
| appId | string | No | Application ID, takes priority over Header |
| systemPrompt | string | No | System prompt, only effective on first request of new session |
| receiverUserId | number | No | Receiver user ID (reserved field) |
| enableWebSearch | boolean | No | Enable web search, defaults to false |
Request Example
curl -X POST "https://api.mindverse.com/gate/lab/api/secondme/chat/stream" \
-H "Authorization: Bearer lba_at_your_access_token" \
-H "Content-Type: application/json" \
-d '{
"message": "Hello, introduce yourself",
"systemPrompt": "Please reply in a friendly tone"
}'With WebSearch enabled:
curl -X POST "https://api.mindverse.com/gate/lab/api/secondme/chat/stream" \
-H "Authorization: Bearer lba_at_your_access_token" \
-H "Content-Type: application/json" \
-d '{
"message": "What are today tech news",
"enableWebSearch": true
}'Response
Response type is text/event-stream (Server-Sent Events).
First message for new session:
event: session
data: {"sessionId": "labs_sess_a1b2c3d4e5f6"}Chat content stream:
data: {"choices": [{"delta": {"content": "Hello"}}]}
data: {"choices": [{"delta": {"content": "! I am"}}]}
data: {"choices": [{"delta": {"content": " your AI avatar"}}]}
data: [DONE]Event stream when WebSearch is enabled:
event: session
data: {"sessionId": "labs_sess_a1b2c3d4e5f6"}
event: tool_call
data: {"toolName": "web_search", "status": "searching"}
event: tool_result
data: {"toolName": "web_search", "query": "tech news", "resultCount": 5}
data: {"choices": [{"delta": {"content": "Based on search results..."}}]}
data: [DONE]Stream Data Format
| Event Type | Description |
|---|---|
| session | Returns session ID when new session is created |
| tool_call | Tool call started, triggered when WebSearch is enabled |
| tool_result | Tool call result, contains search query and result count |
| data | Incremental chat content |
| [DONE] | End of stream marker |
Handling Streaming Response Example (Python)
import requests
response = requests.post(
"https://api.mindverse.com/gate/lab/api/secondme/chat/stream",
headers={
"Authorization": "Bearer lba_ak_xxx",
"Content-Type": "application/json"
},
json={"message": "Hello"},
stream=True
)
for line in response.iter_lines():
if line:
line = line.decode('utf-8')
if line.startswith('data: '):
data = line[6:]
if data == '[DONE]':
break
print(data)Error Codes
| Error Code | Description |
|---|---|
| apikey.permission.denied | Missing chat.write permission |
| secondme.user.invalid_id | Invalid user ID |
| secondme.stream.error | Streaming response error |
Get Session List
Get user's chat session list.
GET /api/secondme/chat/session/listAuthentication
Requires OAuth2 Token.
Required Permissions
chat.read
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| appId | string | No | Filter by application ID |
Request Example
curl -X GET "https://api.mindverse.com/gate/lab/api/secondme/chat/session/list?appId=general" \
-H "Authorization: Bearer lba_at_your_access_token"Response
Success (200)
{
"code": 0,
"data": {
"sessions": [
{
"sessionId": "labs_sess_a1b2c3d4",
"appId": "general",
"lastMessage": "Hello, introduce yourself...",
"lastUpdateTime": "2024-01-20T15:30:00Z",
"messageCount": 10
},
{
"sessionId": "labs_sess_e5f6g7h8",
"appId": "general",
"lastMessage": "What's the weather today?",
"lastUpdateTime": "2024-01-19T10:00:00Z",
"messageCount": 5
}
]
}
}| Field | Type | Description |
|---|---|---|
| sessions | array | Session list, sorted by last update time (descending) |
| sessions[].sessionId | string | Session ID |
| sessions[].appId | string | Application ID |
| sessions[].lastMessage | string | Last message preview (truncated to 50 chars) |
| sessions[].lastUpdateTime | string | Last update time (ISO 8601) |
| sessions[].messageCount | number | Message count |
Error Codes
| Error Code | Description |
|---|---|
| apikey.permission.denied | Missing chat.read permission |
Get Session Messages
Get message history for a specific session.
GET /api/secondme/chat/session/messagesAuthentication
Requires OAuth2 Token.
Required Permissions
chat.read
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| sessionId | string | Yes | Session ID |
Request Example
curl -X GET "https://api.mindverse.com/gate/lab/api/secondme/chat/session/messages?sessionId=labs_sess_a1b2c3d4" \
-H "Authorization: Bearer lba_at_your_access_token"Response
Success (200)
{
"code": 0,
"data": {
"sessionId": "labs_sess_a1b2c3d4",
"messages": [
{
"messageId": "msg_001",
"role": "system",
"content": "Please reply in a friendly tone",
"senderUserId": 12345,
"receiverUserId": null,
"createTime": "2024-01-20T15:00:00Z"
},
{
"messageId": "msg_002",
"role": "user",
"content": "Hello, introduce yourself",
"senderUserId": 12345,
"receiverUserId": null,
"createTime": "2024-01-20T15:00:05Z"
},
{
"messageId": "msg_003",
"role": "assistant",
"content": "Hello! I am your AI avatar...",
"senderUserId": 12345,
"receiverUserId": null,
"createTime": "2024-01-20T15:00:10Z"
}
]
}
}| Field | Type | Description |
|---|---|---|
| sessionId | string | Session ID |
| messages | array | Message list, sorted by creation time (ascending) |
| messages[].messageId | string | Message ID |
| messages[].role | string | Role: system/user/assistant |
| messages[].content | string | Message content |
| messages[].senderUserId | number | Sender user ID |
| messages[].receiverUserId | number | Receiver user ID (reserved) |
| messages[].createTime | string | Creation time (ISO 8601) |
Error Codes
| Error Code | Description |
|---|---|
| apikey.permission.denied | Missing chat.read permission |
| secondme.session.unauthorized | Not authorized to access this session |
Note: If sessionId does not exist, the API will return success (code=0) with an empty messages array.