上传图片
curl --request POST \
--url https://kaienapi.com/v1/files \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form purpose=vision \
--form file='@example-file'import requests
url = "https://kaienapi.com/v1/files"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "purpose": "vision" }
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('purpose', 'vision');
form.append('file', '<binary>');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://kaienapi.com/v1/files', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://kaienapi.com/v1/files"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nvision\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<binary>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"url": "https://assets.kaien-canvas.cn/files/example.png",
"created": 1757403998946,
"expires_at": 1757490398946
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}上传本地图片并获得一个可公开访问的临时 URL,可用于图片展示或作为模型参考图。
请求格式
使用 multipart/form-data,必须包含 file 和 purpose。当前支持 JPG、PNG、GIF、WebP,默认单文件不超过 10 MiB。文件格式以实际内容为准。
purpose 填写
图片引用场景建议填写 vision。
有效期与限流
图片默认保留 1 天。默认每个用户每 60 秒最多上传 10 张、每天最多成功上传 200 张,账号下多个 API Key 共用额度。服务同时最多处理 64 个上传;触发限制时响应会提供 Retry-After。
读取结果
上传成功后读取响应中的 url;created 和 expires_at 均为 Unix 毫秒时间戳。URL 在有效期内访问无需携带 API Key。
POST
/
v1
/
files
上传图片
curl --request POST \
--url https://kaienapi.com/v1/files \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form purpose=vision \
--form file='@example-file'import requests
url = "https://kaienapi.com/v1/files"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "purpose": "vision" }
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('purpose', 'vision');
form.append('file', '<binary>');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://kaienapi.com/v1/files', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://kaienapi.com/v1/files"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nvision\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<binary>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"url": "https://assets.kaien-canvas.cn/files/example.png",
"created": 1757403998946,
"expires_at": 1757490398946
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}Authorizations
在请求头中传入:Authorization: Bearer sk-...
Body
multipart/form-data