Skip to content

媒体 API

本页介绍图片获取、语音获取以及媒体能力查询等接口。媒体发送作为消息段随 send_msg / send_group_msg / send_private_msg 一同发送,详见 消息 API消息段。群文件与私聊文件上传见 群文件系统 API;头像设置见 账号资料 API

快速索引

API描述
get_image获取图片
get_record获取语音
can_send_image检查是否可以发送图片(见信息查询
can_send_record检查是否可以发送语音(见信息查询

获取图片

  • API: get_image
  • 描述: 获取图片文件信息或下载地址。

请求参数

字段类型必填默认值说明
filestring-本地路径或已收图的 token。
json
{
  "file": "<file_path>"
}

响应参数

字段类型说明备注
filestring本地路径或原始 token。-
filenamestring文件名或原始 token。仅远程 token 返回。
urlstring图片下载地址。仅远程 token 返回。
json
{
  "file": "<file_path>"
}

示例

bash
curl -X POST 'http://127.0.0.1:5700/get_image' \
  -H 'Content-Type: application/json' \
  -d '{"file":"<file_path>"}'
js
const res = await fetch('http://127.0.0.1:5700/get_image', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    file: '<file_path>'
  })
})

const body = await res.json()
console.log(body.data.file)
py
import requests

resp = requests.post(
    "http://127.0.0.1:5700/get_image",
    json={"file": "<file_path>"},
    timeout=10,
)
resp.raise_for_status()
body = resp.json()
print(body["data"]["file"])

错误码

retcode说明
1400参数错误。
1500token 解析失败。

注意事项

  • file 接受本地路径(裸路径或 file:// 前缀)、base64://http(s)://
  • 本地路径直接返回该路径;远程 token 解析后返回下载 URL。

获取语音

  • API: get_record
  • 描述: 获取语音文件,可指定目标格式。

请求参数

字段类型必填默认值说明
filestring-本地路径或已收语音 token。
out_formatstring-目标音频格式,如 mp3amrsilk 等。
json
{
  "file": "<file_path>",
  "out_format": "mp3"
}

响应参数

字段类型说明备注
filestring本地文件路径。-
json
{
  "file": "<file_path>"
}

示例

bash
curl -X POST 'http://127.0.0.1:5700/get_record' \
  -H 'Content-Type: application/json' \
  -d '{"file":"<file_path>","out_format":"mp3"}'
js
const res = await fetch('http://127.0.0.1:5700/get_record', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    file: '<file_path>',
    out_format: 'mp3'
  })
})

const body = await res.json()
console.log(body.data.file)
py
import requests

resp = requests.post(
    "http://127.0.0.1:5700/get_record",
    json={
        "file": "<file_path>",
        "out_format": "mp3",
    },
    timeout=10,
)
resp.raise_for_status()
body = resp.json()
print(body["data"]["file"])

错误码

retcode说明
1400参数错误。
1500本地文件需要转码但缺少 ffmpeg,或远程 token 无法解析。

注意事项

  • 仅当 file 为已存在的本地路径且其扩展名(不区分大小写)已等于 out_format 时直接返回。
  • 本地文件存在但格式不匹配时需要 ffmpeg / ffprobePATH 中可用进行转码。
  • 已收语音 token 目前无法解析,返回 1500

能力查询

can_send_imagecan_send_record 的完整文档见信息查询 API。两者恒返回 { "yes": true }