Create sessions, send messages (image generation, video generation, etc.), upload image/video files, and query session message progress via the agent-im OpenAPI.
Features
- Create session / send message - Create a new session or send a message to an existing session (e.g. "generate an anime video")
- Query session progress - Fetch the message list of the session by sessionId, used to poll image generation/video generation results
- Switch project - Switch the project bound to the current accessKey to a new project; subsequent create_session will use the new projectUuid
- Upload file - Upload an image or video file to OSS, returning an accessible OSS address
Prerequisites
export LIBTV_ACCESS_KEY="your-access-key"
Optional:OPENAPI_IM_BASE or IM_BASE_URL, default https://im.liblib.tv。
No additional dependencies need to be installed; only the Python standard library is used.
Usage
1. Create session / send message
# 创建新会话并发送「生一个动漫视频」
python3 {baseDir}/scripts/create_session.py "生一个动漫视频"
# 向已有会话发送消息
python3 {baseDir}/scripts/create_session.py "再生成一张风景图" --session-id SESSION_ID
# 只创建/绑定会话,不发消息
python3 {baseDir}/scripts/create_session.py
2. Query session progress
# 查询会话消息列表
python3 {baseDir}/scripts/query_session.py SESSION_ID
# 增量拉取(只返回 seq 大于 N 的消息)
python3 {baseDir}/scripts/query_session.py SESSION_ID --after-seq 5
# 附带项目地址(传入 create_session 返回的 projectUuid,结果中带 projectUrl)
python3 {baseDir}/scripts/query_session.py SESSION_ID --project-id PROJECT_UUID
3. Switch project
# 切换当前 accessKey 绑定的项目(后续创建会话将使用新项目)
python3 {baseDir}/scripts/change_project.py
4. Upload file
When the user provides a reference file address, perform the upload; only images and videos are supported, and the file size must be under 200M.
# 上传图片
python3 {baseDir}/scripts/upload_file.py /path/to/image.png
# 上传视频
python3 {baseDir}/scripts/upload_file.py /path/to/video.mp4
Output format
create_session Returns:
{
"projectUuid": "aa3ba04c5044477cb7a00a9e5bf3b4d0",
"sessionId": "90f05e0c-...",
"projectUrl": "https://www.liblib.tv/canvas?projectId=aa3ba04c5044477cb7a00a9e5bf3b4d0"
}
query_session Returns:
{
"messages": [
{"id": "msg-xxx", "role": "user", "content": "生一个动漫视频"},
{"id": "msg-yyy", "role": "assistant", "content": "..."}
],
"projectUrl": "https://www.liblib.tv/canvas?projectId=..."
}
(projectUrl Only present when --project-id is passed in)
change_project Returns:
{
"projectUuid": "新项目UUID",
"projectUrl": "https://www.liblib.tv/canvas?projectId=新项目UUID"
}
upload_file Returns:
{
"url": "https://libtv-res.liblib.art/claw/{projectUuid}/{uuid}.png"
}
When finally presenting to the user (OpenClaw)
- Video address: from the video/image URL in the content or result of the assistant message in the
query_sessionreturned bymessages, i.e. "the returned result". - Project address: use the
create_sessionreturned byprojectUrl, or concatenate it yourself ashttps://www.liblib.tv/canvas?projectId=+projectUuid. When querying progress, if--project-id PROJECT_UUID,query_sessionis passed in,projectUrlwill be returned directly, making it convenient to display together.
When the task is completed, provide both:Video/image result link + Project canvas link (projectUrl). During the process, do not provide the Project canvas link (projectUrl)。
Notes
- The authentication method is the request header
Authorization: Bearer <LIBTV_ACCESS_KEY> - When creating a session, if
messageis not passed in, only the session is created/bound, and SendMessage will not be called - When querying a session,
--after-seqcan be used for incremental fetching, making it convenient to poll for new messages (including assistant replies and image generation/video generation results) - The project canvas address is fixed as:
https://www.liblib.tv/canvas?projectId=+ projectUuid - After switching projects, the Redis cache will be updated, and the next create_session will use the new projectUuid
- File upload only supports image (image/) and video (video/) types; other types will be rejected
- The OSS address format returned by upload is
https://libtv-res.liblib.art/claw/{projectUuid}/{uuid}{ext} - Note that the generated videos and images should be returned and presented to the user in a timely manner
- Note that the user's requirement information should be passed to the agent in a timely manner