Files API 作为文件管理接口,提供文件的上传、检索、列表查询及删除能力。
在多模态理解场景中,Files API 与 Responses API、Chat API 结合使用,具备以下优势:
- 大文件适配:文件存储在方舟平台托管的默认存储空间中时,支持最大 512 MB 文件的上传;文件存储在用户指定的火山引擎对象存储 TOS Bucket 中时,支持最大 2 GB 的视频文件的上传,从而满足大文件处理需求。
- 重复使用:支持通过 File ID 在多次请求中重复使用文件,避免重复上传,节省公网下载时延。
- 缩短推理时长:解耦数据预处理与模型推理环节,避免每次请求时重新上传内容,减少预处理导致的时延。
前提条件#
查看 API 文档#
Files API 使用示例#
上传文件#
使用 Files API 可上传文件,用于模型输入、智能体场景和音色注册,上传成功后返回 File ID。File ID 支持在多次请求中重复使用,而不需要重新上传内容,节省公网下载时延。如果文件大于 50 MB,或者要在多个请求中重复使用该文件,可以使用 Files API 上传文件,然后使用 File ID 发起请求。
文件存储位置由请求中 tos 参数决定,详情可参见 上传文件 字段说明:
- 未传入
tos参数:文件存储至方舟平台托管的默认存储空间。 - 传入
tos参数:文件存储至用户指定的火山引擎对象存储 TOS Bucket。
TOS 授权#
目标存储的火山引擎对象存储 TOS Bucket 需要在控制台完成授权后才能使用,具体参考 用户对象存储(TOS)授权。
选择文件用途#
上传文件时,通过 purpose 指定文件用途。请根据文件后续使用场景选择取值。
上传通用文件#
如需将图片、视频、音频、文档等通用文件作为 Responses API、Chat API 的模型输入,将 purpose 设置为 user_data。
curl https://ark.cn-beijing.volces.com/api/v3/files \
-H "Authorization: Bearer $ARK_API_KEY" \
-F 'purpose=user_data' \
-F 'file=@/Users/doc/demo.mp4' \
-F 'preprocess_configs[video][fps]=0.3'
import os
from arkruntime import Ark
client = Ark(
base_url='https://ark.cn-beijing.volces.com/api/v3',
api_key=os.getenv('ARK_API_KEY')
)
file = client.files.create(
# replace with your local video path
file=open("/root/projects/ark/ark_video.mp4", "rb"),
purpose="user_data",
preprocess_configs={
"video": {
"fps": 0.3, # define the sampling fps of the video, default is 1.0
}
}
)
print(file)
package main
import (
"context"
"fmt"
"os"
"github.com/volcengine/ark-runtime-go/arkruntime"
"github.com/volcengine/ark-runtime-go/arkruntime/model/file"
)
func main() {
client := arkruntime.NewClientWithApiKey(
os.Getenv("ARK_API_KEY"),
arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"),
)
ctx := context.Background()
data, err := os.Open("/root/projects/ark/ark_video.mp4")
if err != nil {
fmt.Printf("read file error: %v\n", err)
return
}
fileInfo, err := client.UploadFile(ctx, &file.FileCreateRequest{
Purpose: file.PurposeUserData,
PreprocessConfigs: file.NewOptPreprocessConfigs(file.PreprocessConfigs{
Video: file.NewOptVideo(file.Video{
Fps: file.NewOptFloat64(0.3),
}),
}),
}, data)
if err != nil {
fmt.Printf("upload file error: %v", err)
return
}
fmt.Printf("file info: %v\n", fileInfo)
}
package com.ark.example;
import com.volcengine.ark.runtime.models.file.*;
import com.volcengine.ark.runtime.service.ArkService;
import java.io.File;
public class demo {
public static void main(String[] args) {
String apiKey = System.getenv("ARK_API_KEY");
ArkService service = ArkService.builder().apiKey(apiKey)
.baseUrl("https://ark.cn-beijing.volces.com/api/v3")
.build();
System.out.println("===== Upload File Example=====");
FileObject fileMeta;
fileMeta = service.uploadFile(FileCreateRequest.builder() // replace with your image file path
.purpose(Purpose.USER_DATA)
.preprocessConfigs(PreprocessConfigs.builder().video(Video.builder().fps(0.3).build()).build())
.build(), new File("/root/projects/ark/ark_video.mp4"));
System.out.println("Uploaded file Meta: " + fileMeta);
service.shutdownExecutor();
}
}
上传智能体场景文件#
如需在 Managed Agents 会话或智能体相关流程中使用文件,将 purpose 设置为 agent。上传成功后,可通过 File ID 将文件挂载到会话资源中,供智能体读取。更多使用方式请参见 上传与挂载文件。
curl https://ark.cn-beijing.volces.com/api/v3/files \
-H "Authorization: Bearer $ARK_API_KEY" \
-F 'purpose=agent' \
-F 'file=@/Users/doc/agent_context.pdf'
import os
from arkruntime import Ark
client = Ark(
base_url="https://ark.cn-beijing.volces.com/api/v3",
api_key=os.getenv("ARK_API_KEY"),
)
# Replace with your local document path.
with open("/Users/doc/agent_context.pdf", "rb") as data:
file = client.files.create(
file=data,
purpose="agent",
)
print(file)
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/volcengine/ark-runtime-go/arkruntime"
"github.com/volcengine/ark-runtime-go/arkruntime/model/file"
)
func main() {
client := arkruntime.NewClientWithApiKey(
os.Getenv("ARK_API_KEY"),
arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"),
)
// Replace with your local document path.
data, err := os.Open("/Users/doc/agent_context.pdf")
if err != nil {
log.Fatal(err)
}
defer data.Close()
fileInfo, err := client.UploadFile(context.Background(), &file.FileCreateRequest{
Purpose: file.PurposeAgent,
}, data)
if err != nil {
log.Fatal(err)
}
fmt.Printf("file info: %v\n", fileInfo)
}
package com.ark.example;
import com.volcengine.ark.runtime.models.file.FileCreateRequest;
import com.volcengine.ark.runtime.models.file.FileObject;
import com.volcengine.ark.runtime.models.file.Purpose;
import com.volcengine.ark.runtime.service.ArkService;
import java.io.File;
public class demo {
public static void main(String[] args) {
ArkService service = ArkService.builder()
.apiKey(System.getenv("ARK_API_KEY"))
.baseUrl("https://ark.cn-beijing.volces.com/api/v3")
.build();
try {
// Replace with your local document path.
FileObject fileMeta = service.uploadFile(
FileCreateRequest.builder().purpose(Purpose.AGENT).build(),
new File("/Users/doc/agent_context.pdf"));
System.out.println(fileMeta);
} finally {
service.shutdownExecutor();
}
}
}
上传音色注册文件#
注册自定义音色时,将 purpose 设置为 voice,并将 model 设置为音色注册模型的 Model ID 或对应的 Endpoint ID。可通过 description 添加文件描述(不超过 500 个字符)。如需永久保留文件,将 expire_at 设置为 -1。
音色注册文件支持通过 file 上传本地文件,或通过 url 传入公网 HTTP/HTTPS URL,不支持通过 url 传入 tos:// URI。以下示例通过公网 HTTPS URL 上传参考音频。
curl "https://ark.cn-beijing.volces.com/api/v3/files" \
-H "Authorization: Bearer $ARK_API_KEY" \
-F "purpose=voice" \
-F "model=doubao-seed-audio-1-5-261128" \
-F "description=中文青年女性,甜美" \
-F "expire_at=-1" \
-F "url=https://arkdocs.tos-cn-beijing.volces.com/files/audio-generation/seed-audio-1-5-tav2a-reference-audio.wav"
import os
from arkruntime import Ark
client = Ark(
base_url="https://ark.cn-beijing.volces.com/api/v3",
api_key=os.getenv("ARK_API_KEY"),
)
file = client.files.create(
url="https://arkdocs.tos-cn-beijing.volces.com/files/audio-generation/seed-audio-1-5-tav2a-reference-audio.wav",
purpose="voice",
model="doubao-seed-audio-1-5-261128",
description="中文青年女性,甜美",
expire_at=-1,
)
print(file)
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/volcengine/ark-runtime-go/arkruntime"
"github.com/volcengine/ark-runtime-go/arkruntime/model/file"
)
func main() {
client := arkruntime.NewClientWithApiKey(
os.Getenv("ARK_API_KEY"),
arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"),
)
ctx := context.Background()
fileInfo, err := client.UploadFile(ctx, &file.FileCreateRequest{
URL: file.NewOptString("https://arkdocs.tos-cn-beijing.volces.com/files/audio-generation/seed-audio-1-5-tav2a-reference-audio.wav"),
Purpose: file.PurposeVoice,
Model: file.NewOptString("doubao-seed-audio-1-5-261128"),
Description: file.NewOptDescription(file.Description("中文青年女性,甜美")),
ExpireAt: file.NewOptInt64(-1),
}, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("file info: %v\n", fileInfo)
}
上传后,使用返回的 File ID 调用 查询文件详情,根据 status 判断音色是否可用:
processing:文件正在处理,暂不可引用该音色。active:可在 Seed Audio 系列模型的生成请求中通过file://<FILE_ID>引用该音色,详见 引用固定音色。failed:注册失败,请查看error字段中的错误详情。
选择上传方式#
Files API 支持二进制文件、文件 URL 两种方式上传文件。
file(二进制文件):要上传的本地文件。文件可存储至方舟平台默认托管存储空间,或用户指定的火山引擎 TOS 存储桶。url(文件 URL):支持 HTTP/HTTPS URL、TOS URI 两种方式。- HTTP/HTTPS URL:公网可直接访问的文件 URL,请确保文件 URL 可被访问。文件可存储至方舟平台默认托管存储空间,或用户指定的火山引擎 TOS 存储桶。
- TOS URI:对象存储 TOS 专属的资源定位标识,格式为
tos://<bucket>/<prefix>/<file_name>。使用该方式时,文件仅支持存储至火山引擎 TOS 存储桶。
file 上传方式#
-
文件存储至方舟平台默认托管存储空间
curl https://ark.cn-beijing.volces.com/api/v3/files \ -H "Authorization: Bearer $ARK_API_KEY" \ -F 'purpose=user_data' \ -F 'file=@/Users/doc/demo.mp4' \ -F 'preprocess_configs[video][fps]=0.3'响应参数如下:
{ "object": "file", "id": "file-20251018114827-6zgrb", "purpose": "user_data", "filename": "demo.mp4", "bytes": 695110, "mime_type": "video/mp4", "created_at": 1760759307, "expire_at": 1761364107, "status": "processing", "preprocess_configs": { "video": { "fps": 0.3 } } }import os from arkruntime import Ark client = Ark( base_url='https://ark.cn-beijing.volces.com/api/v3', api_key=os.getenv('ARK_API_KEY') ) file = client.files.create( # replace with your local video path file=open("/Users/doc/demo.mp4", "rb"), purpose="user_data", preprocess_configs={ "video": { "fps": 0.3, # define the sampling fps of the video, default is 1.0 } } ) print(file)package main import ( "context" "fmt" "os" "github.com/volcengine/ark-runtime-go/arkruntime" "github.com/volcengine/ark-runtime-go/arkruntime/model/file" ) func main() { client := arkruntime.NewClientWithApiKey( os.Getenv("ARK_API_KEY"), arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"), ) ctx := context.Background() data, err := os.Open("/Users/doc/demo.mp4") if err != nil { fmt.Printf("read file error: %v ", err) return } fileInfo, err := client.UploadFile(ctx, &file.FileCreateRequest{ Purpose: file.PurposeUserData, PreprocessConfigs: file.NewOptPreprocessConfigs(file.PreprocessConfigs{ Video: file.NewOptVideo(file.Video{ Fps: file.NewOptFloat64(0.3), }), }), }, data) if err != nil { fmt.Printf("upload file error: %v", err) return } fmt.Printf("file info: %v ", fileInfo) }package com.ark.sample; import com.volcengine.ark.runtime.models.file.*; import com.volcengine.ark.runtime.models.file.FileObject; import com.volcengine.ark.runtime.models.file.PreprocessConfigs; import com.volcengine.ark.runtime.models.file.FileCreateRequest; import com.volcengine.ark.runtime.models.file.Video; import com.volcengine.ark.runtime.service.ArkService; import java.io.File; public class demo { public static void main(String[] args) { String apiKey = System.getenv("ARK_API_KEY"); ArkService service = ArkService.builder().apiKey(apiKey) .baseUrl("https://ark.cn-beijing.volces.com/api/v3") .build(); System.out.println("===== Upload File Example====="); FileObject fileMeta; fileMeta = service.uploadFile(FileCreateRequest.builder() // replace with your video file path .purpose(Purpose.USER_DATA) .preprocessConfigs(PreprocessConfigs.builder().video(Video.builder().fps(0.3).build()).build()) .build(), new File("/Users/doc/demo.mp4")); System.out.println("Uploaded file Meta: " + fileMeta); service.shutdownExecutor(); } }import os from openai import OpenAI client = OpenAI( base_url='https://ark.cn-beijing.volces.com/api/v3', api_key=os.getenv('ARK_API_KEY') ) file = client.files.create( # replace with your local video path file=open("/Users/doc/demo.mp4", "rb"), purpose="user_data", extra_body={ "preprocess_configs":{ "video": { "fps": 0.3 } } } ) print(file) -
文件存储至火山引擎对象存储 TOS Bucket:
curl https://ark.cn-beijing.volces.com/api/v3/files \ -H "Authorization: Bearer $ARK_API_KEY" \ -F 'purpose=user_data' \ -F 'file=@/Users/doc/demo.mp4' \ -F 'preprocess_configs[video][fps]=0.3' \ -F "tos[bucket]=my-bucket" \ -F "tos[prefix]=ark-files/"import os from arkruntime import Ark client = Ark( base_url='https://ark.cn-beijing.volces.com/api/v3', api_key=os.getenv('ARK_API_KEY') ) file = client.files.create( file=open("/Users/doc/demo.mp4", "rb"), purpose="user_data", preprocess_configs={ "video": { "fps": 0.3 } }, tos={ "bucket": "my-bucket", "prefix": "ark-files/" } ) print(file)package main import ( "context" "fmt" "os" "github.com/volcengine/ark-runtime-go/arkruntime" "github.com/volcengine/ark-runtime-go/arkruntime/model/file" ) func main() { client := arkruntime.NewClientWithApiKey( os.Getenv("ARK_API_KEY"), arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"), ) ctx := context.Background() data, err := os.Open("/Users/doc/demo.mp4") if err != nil { fmt.Printf("read file error: %v ", err) return } fileInfo, err := client.UploadFile(ctx, &file.FileCreateRequest{ Purpose: file.PurposeUserData, Tos: file.NewOptTosStorage(file.TosStorage{ Bucket: file.NewOptString("my-bucket"), Prefix: file.NewOptString("ark-files/"), }), PreprocessConfigs: file.NewOptPreprocessConfigs(file.PreprocessConfigs{ Video: file.NewOptVideo(file.Video{ Fps: file.NewOptFloat64(0.3), }), }), }, data) if err != nil { fmt.Printf("upload file error: %v", err) return } fmt.Printf("file info: %v ", fileInfo) }package com.ark.sample; import com.volcengine.ark.runtime.models.file.*; import com.volcengine.ark.runtime.service.ArkService; import java.io.File; public class demo { public static void main(String[] args) { String apiKey = System.getenv("ARK_API_KEY"); ArkService service = ArkService.builder() .apiKey(apiKey) .baseUrl("https://ark.cn-beijing.volces.com/api/v3") .build(); System.out.println("===== Upload File Example ====="); FileObject fileMeta; fileMeta = service.uploadFile(FileCreateRequest.builder() .purpose(Purpose.USER_DATA) .tos(TosStorage.builder() .bucket("my-bucket") .prefix("ark-files/") .build()) .preprocessConfigs(PreprocessConfigs.builder() .video(Video.builder().fps(0.3).build()) .build()) .build(), new File("/Users/doc/demo.mp4")); System.out.println("Uploaded file Meta: " + fileMeta); service.shutdownExecutor(); } }
HTTP/HTTPS URL 上传方式#
-
文件存储至方舟平台默认托管存储空间
curl "https://ark.cn-beijing.volces.com/api/v3/files" \ -H "Authorization: Bearer $ARK_API_KEY" \ -F "purpose=user_data" \ -F "url=https://example.com/docs/demo_img.png"import os from arkruntime import Ark client = Ark( base_url='https://ark.cn-beijing.volces.com/api/v3', api_key=os.getenv('ARK_API_KEY') ) file = client.files.create( purpose="user_data", url="https://example.com/docs/demo_img.png" ) print(file)package main import ( "context" "fmt" "os" "github.com/volcengine/ark-runtime-go/arkruntime" "github.com/volcengine/ark-runtime-go/arkruntime/model/file" ) func main() { client := arkruntime.NewClientWithApiKey( os.Getenv("ARK_API_KEY"), arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"), ) ctx := context.Background() fileInfo, err := client.UploadFile(ctx, &file.FileCreateRequest{ Purpose: file.PurposeUserData, URL: file.NewOptString("https://example.com/docs/demo_img.png"), }, nil) if err != nil { fmt.Printf("upload file error: %v", err) return } fmt.Printf("file info: %v ", fileInfo) }package com.ark.sample; import com.volcengine.ark.runtime.model.files.*; import com.volcengine.ark.runtime.service.ArkService; public class demo { public static void main(String[] args) { String apiKey = System.getenv("ARK_API_KEY"); ArkService service = ArkService.builder() .apiKey(apiKey) .baseUrl("https://ark.cn-beijing.volces.com/api/v3") .build(); System.out.println("===== Upload File Example ====="); FileMeta fileMeta; try { fileMeta = service.uploadFile( UploadFileRequest.builder() .url("https://example.com/docs/demo_img.png") .purpose("user_data") .build()); System.out.println("Uploaded file Meta: " + fileMeta); } catch (Exception e) { e.printStackTrace(); } service.shutdownExecutor(); } } -
文件存储至火山引擎对象存储 TOS Bucket
curl "https://ark.cn-beijing.volces.com/api/v3/files" \ -H "Authorization: Bearer $ARK_API_KEY" \ -F "purpose=user_data" \ -F "url=https://example.com/docs/demo_img.png" \ -F "tos[bucket]=my-bucket" \ -F "tos[prefix]=ark-files/"import os from arkruntime import Ark client = Ark( base_url='https://ark.cn-beijing.volces.com/api/v3', api_key=os.getenv('ARK_API_KEY') ) file = client.files.create( url="https://example.com/docs/demo_img.png", purpose="user_data", tos={ "bucket": "my-bucket", "prefix": "ark-files/" } ) print(file)package main import ( "context" "fmt" "os" "github.com/volcengine/ark-runtime-go/arkruntime" "github.com/volcengine/ark-runtime-go/arkruntime/model/file" ) func main() { client := arkruntime.NewClientWithApiKey( os.Getenv("ARK_API_KEY"), arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"), ) ctx := context.Background() fileInfo, err := client.UploadFile(ctx, &file.FileCreateRequest{ Purpose: file.PurposeUserData, URL: file.NewOptString("https://example.com/docs/demo_img.png"), Tos: file.NewOptTosStorage(file.TosStorage{ Bucket: file.NewOptString("my-bucket"), Prefix: file.NewOptString("ark-files/"), }), }, nil) if err != nil { fmt.Printf("upload file error: %v", err) return } fmt.Printf("file info: %v ", fileInfo) }package com.ark.sample; import com.volcengine.ark.runtime.model.files.*; import com.volcengine.ark.runtime.service.ArkService; public class demo { public static void main(String[] args) { String apiKey = System.getenv("ARK_API_KEY"); ArkService service = ArkService.builder() .apiKey(apiKey) .baseUrl("https://ark.cn-beijing.volces.com/api/v3") .build(); System.out.println("===== Upload File Example ====="); FileMeta fileMeta; try { fileMeta = service.uploadFile( UploadFileRequest.builder() .url("https://example.com/docs/demo_img.png") .purpose("user_data") .tos(TosStorage.builder() .bucket("my-bucket") .prefix("ark-files/") .build()) .build()); System.out.println("Uploaded file Meta: " + fileMeta); } catch (Exception e) { e.printStackTrace(); } service.shutdownExecutor(); } }
TOS URI 上传方式#
传入 TOS URI 时,必须将文件存储到火山引擎对象存储 TOS Bucket 中。其中:
url用于指定待读取的源文件位置,即火山引擎对象存储 TOS Bucket 中的已有文件。tos[bucket]和tos[prefix]用于指定上传文件至火山引擎对象存储 TOS Bucket 中的存储桶和存储路径。
如果
url指向其他账号的火山引擎对象存储 TOS Bucket,当前调用 Files API 的账号或项目需要具备该 Bucket 的读取权限。跨账号访问 TOS Bucket 时,请参考 授权其他账号访问存储桶 完成授权后再调用 Files API。
curl "https://ark.cn-beijing.volces.com/api/v3/files" \
-H "Authorization: Bearer $ARK_API_KEY" \
-F "purpose=user_data" \
-F "url=tos://my-bucket/source/raw_video.mp4" \
-F "tos[bucket]=my-bucket" \
-F "tos[prefix]=ark-files/"
import os
from arkruntime import Ark
client = Ark(
base_url='https://ark.cn-beijing.volces.com/api/v3',
api_key=os.getenv('ARK_API_KEY')
)
file = client.files.create(
url="tos://my-bucket/source/raw_video.mp4",
purpose="user_data",
tos={
"bucket": "my-bucket",
"prefix": "ark-files/"
}
)
print(file)
package main
import (
"context"
"fmt"
"os"
"github.com/volcengine/ark-runtime-go/arkruntime"
"github.com/volcengine/ark-runtime-go/arkruntime/model/file"
)
func main() {
client := arkruntime.NewClientWithApiKey(
os.Getenv("ARK_API_KEY"),
arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"),
)
ctx := context.Background()
fileInfo, err := client.UploadFile(ctx, &file.FileCreateRequest{
Purpose: file.PurposeUserData,
URL: file.NewOptString("tos://my-bucket/source/raw_video.mp4"),
Tos: file.NewOptTosStorage(file.TosStorage{
Bucket: file.NewOptString("my-bucket"),
Prefix: file.NewOptString("ark-files/"),
}),
}, nil)
if err != nil {
fmt.Printf("upload file error: %v", err)
return
}
fmt.Printf("file info: %v
", fileInfo)
}
package com.ark.sample;
import com.volcengine.ark.runtime.model.files.*;
import com.volcengine.ark.runtime.service.ArkService;
public class demo {
public static void main(String[] args) {
String apiKey = System.getenv("ARK_API_KEY");
ArkService service = ArkService.builder()
.apiKey(apiKey)
.baseUrl("https://ark.cn-beijing.volces.com/api/v3")
.build();
System.out.println("===== Upload File Example =====");
FileMeta fileMeta;
try {
fileMeta = service.uploadFile(
UploadFileRequest.builder()
.url("tos://my-bucket/source/raw_video.mp4")
.purpose("user_data")
.tos(TosStorage.builder()
.bucket("my-bucket")
.prefix("ark-files/")
.build())
.build());
System.out.println("Uploaded file Meta: " + fileMeta);
} catch (Exception e) {
e.printStackTrace();
}
service.shutdownExecutor();
}
}
在大视频理解场景下,通过 Files API 以 url 方式上传,并传入 tos 参数时,视频文件单文件最大支持 2GB(该能力仅适用于视频文件,其他类型文件容量限制仍保持 512 MB)。文件上传后会进入异步处理流程,需待文件状态变为 active 后方可使用。
curl "https://ark.cn-beijing.volces.com/api/v3/files" \
-H "Authorization: Bearer $ARK_API_KEY" \
-F "purpose=user_data" \
-F "url=tos://my-bucket/videos/long-video.mp4" \
-F "tos[bucket]=my-bucket" \
-F "tos[prefix]=ark-files/" \
-F "preprocess_configs[video][model]=doubao-seed-2-1-pro-260915" \
-F "preprocess_configs[video][max_video_tokens]=200000" \
-F "preprocess_configs[video][min_frames]=16"
import os
from arkruntime import Ark
client = Ark(
base_url='https://ark.cn-beijing.volces.com/api/v3',
api_key=os.getenv('ARK_API_KEY')
)
file = client.files.create(
url="tos://my-bucket/videos/long-video.mp4",
purpose="user_data",
tos={
"bucket": "my-bucket",
"prefix": "ark-files/"
},
preprocess_configs={
"video": {
"model": "doubao-seed-2-1-pro-260915",
"max_video_tokens": 200000,
"min_frames": 16
}
}
)
print(file)
package main
import (
"context"
"fmt"
"os"
"github.com/volcengine/volcengine-go-sdk/service/arkruntime"
"github.com/volcengine/volcengine-go-sdk/service/arkruntime/model/file"
"github.com/volcengine/volcengine-go-sdk/volcengine"
)
func main() {
client := arkruntime.NewClientWithApiKey(
os.Getenv("ARK_API_KEY"),
arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"),
)
ctx := context.Background()
fileInfo, err := client.UploadFile(ctx, &file.UploadFileRequest{
Purpose: file.PurposeUserData,
URL: volcengine.String("tos://my-bucket/videos/long-video.mp4"),
Tos: &file.TosStorage{
Bucket: volcengine.String("my-bucket"),
Prefix: volcengine.String("ark-files/"),
},
PreprocessConfigs: &file.PreprocessConfigs{
Video: &file.Video{
Model: volcengine.String("doubao-seed-2-1-pro-260915"),
MaxVideoTokens: volcengine.Int64(200000),
MinFrames: volcengine.Int64(16),
},
},
})
if err != nil {
fmt.Printf("upload file error: %v", err)
return
}
fmt.Printf("file info: %v
", fileInfo)
}
package com.ark.sample;
import com.volcengine.ark.runtime.model.files.*;
import com.volcengine.ark.runtime.service.ArkService;
public class demo {
public static void main(String[] args) {
String apiKey = System.getenv("ARK_API_KEY");
ArkService service = ArkService.builder()
.apiKey(apiKey)
.baseUrl("https://ark.cn-beijing.volces.com/api/v3")
.build();
System.out.println("===== Upload File Example =====");
FileMeta fileMeta;
try {
fileMeta = service.uploadFile(
UploadFileRequest.builder()
.url("tos://my-bucket/videos/long-video.mp4")
.purpose("user_data")
.tos(TosStorage.builder()
.bucket("my-bucket")
.prefix("ark-files/")
.build())
.preprocessConfigs(PreprocessConfigs.builder()
.video(Video.builder()
.model("doubao-seed-2-1-pro-260915")
.maxVideoTokens(200000L)
.minFrames(16L)
.build())
.build())
.build());
System.out.println("Uploaded file Meta: " + fileMeta);
} catch (Exception e) {
e.printStackTrace();
}
service.shutdownExecutor();
}
}
文件存储限制#
文件存储限制由文件用途和存储位置共同决定。
方舟平台托管的默认存储空间每个账号提供 20 GB 免费存储额度,跨项目共享。存储在该空间中的通用文件、智能体场景文件和音色注册文件均计入总容量,包括将 expire_at 设置为 -1 的永久音色文件。超出额度后无法继续上传,删除文件释放存储空间后可继续上传。
通用文件和智能体场景文件的存储限制如下:
| 对比项 | 方舟平台托管的默认存储空间 | 火山引擎对象存储 TOS Bucket |
|---|---|---|
| 授权要求 | 无需额外授权 | 目标存储 Bucket 需提前完成授权,具体参见 用户对象存储(TOS)授权 |
| 文件格式 | user_data 的支持范围参见 文件类型;agent 不限制文件格式 |
user_data 的支持范围参见 文件类型;agent 不限制文件格式 |
| 单文件大小 | 512 MB | 视频文件 2 GB,其他类型文件 512 MB |
| 总存储容量 | 与音色注册文件共享账号级 20 GB 免费存储额度 | 无限制 |
| 存储有效期 | 默认保留 7 天,支持通过 expire_at 设置为 1–30 天 |
默认保留 7 天,支持通过 expire_at 设置为 1–30 天 |
| 对象操作限制 | 通过 Files API 删除文件 | 对象被托管后仅支持读取,不支持通过 TOS 控制台或 TOS API 删除、覆盖或修改;生命周期删除、覆盖式复制等操作也受到托管保护限制 |
音色注册文件仅支持存储在方舟平台托管的默认存储空间中,限制如下:
- 文件大小与时长:单文件不超过 15 MB,音频时长为 2–30 秒。
- 音色数量:每个账号最多注册 1000 个音色文件,跨项目共享。处理中的文件和处理失败的文件也计入数量上限。
- 存储有效期:默认保留 7 天,支持设置 1–30 天的存储有效期;将
expire_at设置为-1时永久有效,可调用 Files API 删除文件。
针对高频存储场景,建议通过缩短文件存储时长、主动删除低频文件管理存储空间。删除方式请参见 删除文件。
文件预处理#
文件上传后的处理方式由 purpose 决定。
- 通用文件:当
purpose为user_data时,接口根据文件类型进行预处理。文件状态变为active后,才可在模型请求中引用。 - 智能体场景文件:当
purpose为agent时,文件不进行预处理,上传成功后状态即为active。 - 音色注册文件:当
purpose为voice时,文件进入异步处理流程。上传接口返回 File ID 后,需查询文件状态,待status变为active后才可引用该自定义音色;处理失败时,查看error字段中的错误详情。
通用文件的预处理规则如下:
- 视频文件:默认会按 1 帧/秒(FPS)的速率提取选段,可通过 preprocess_configs.video.fps 设置自定义帧速率。长视频且画面变化较小时,可设置较低的 FPS 值;需精细捕捉画面变化时,可设置较高的 FPS 值。同时可通过
min_frame_tokens、max_frame_tokens、max_video_tokens用于控制单帧压缩与整体视频信息保留策略。文件预处理后,在 Responses API 中使用 File ID,可以缩短推理时长。 - PDF 文件:会分页来处理成多图,在预处理时不会对拆分的图片做分辨率缩放,以确保图片能够完整且清晰地保留 PDF 文件中的原始信息。
预处理超时限制#
视频和 PDF 文件的预处理超时限制为 5 分钟。视频时长、PDF 页数及单页像素等因素可能导致预处理超时。
超时解决方案:
优先检查是否存在像素过大的问题,其中对 1080p 视频抽帧操作容易导致超时,建议压缩至 720p 及以下。
模型推理阶段会压缩分辨率,所以提升原始像素对最终效果无增益。
视频压缩工具及命令
将视频文件压缩至 720p 的命令示例如下。FFmpeg 工具下载可参见 下载 FFmpeg。
ffmpeg -i input.mp4 \
-vf "scale=1280:720" \
-c:v libx264 -crf 23 \
-c:a aac -b:a 128k \
output_720p.mp4
文件类型#
下表列出了通用文件(purpose 为 user_data)和音色注册文件(purpose 为 voice)支持的文件类型。
| 文件类型 | 文件格式 | MIME 类型 |
|---|---|---|
| 图片 | .jpg、.jpeg、.png、.gif、.webp、.bmp、.tiff、.ico、.icns、.sgi、.jp2、.heic、.heif |
image/jpeg、image/png、image/gif、image/webp、image/bmp、image/tiff、image/x-icon、image/x-icns、image/sgi、image/jp2、image/heic、image/heif |
| 视频 | .mp4、.avi、.mov |
video/mp4、video/x-msvideo、video/quicktime |
| 文档 | .pdf |
application/pdf |
| 音频(通用) | .mp3、.wav、.aac、.m4a |
audio/mpeg、audio/wav、audio/aac、audio/x-m4a |
| 音频(音色注册) | .mp3、.wav |
audio/mpeg、audio/wav |
当 purpose 为 agent 时,不限制文件格式。
管理文件#
检索文件#
通过 File ID 检索文件信息,如文件大小、过期时间、MIME 类型及文件处理状态等信息,可参见 检索文件 接口说明。
上传接口返回 File ID 后,可调用检索文件接口查询文件处理状态。当 status 为 active 时,文件才可使用;当 status 为 failed 时,请查看 error 字段中的错误详情。音色注册文件需要等待异步处理完成,智能体场景文件上传成功后即为 active。
# Replace <FILE_ID> with the ID returned by the file upload API.
curl "https://ark.cn-beijing.volces.com/api/v3/files/<FILE_ID>" \
-H "Authorization: Bearer $ARK_API_KEY"
import os
from arkruntime import Ark
# Get API Key: https://ark.volcengine.com/region:cn-beijing/apikey
api_key = os.getenv('ARK_API_KEY')
client = Ark(
base_url='https://ark.cn-beijing.volces.com/api/v3',
api_key=api_key,
)
# Retrieve file
response = client.files.retrieve(
file_id="<FILE_ID>"
)
print(response)
package main
import (
"context"
"fmt"
"os"
"github.com/volcengine/ark-runtime-go/arkruntime"
)
func main() {
client := arkruntime.NewClientWithApiKey(
os.Getenv("ARK_API_KEY"),
arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"),
)
ctx := context.Background()
fileInfo, err := client.RetrieveFile(ctx, "<FILE_ID>")
if err != nil {
fmt.Printf("get file status error: %v", err)
return
}
fmt.Printf("file info: %v", fileInfo)
}
package com.ark.sample;
import com.volcengine.ark.runtime.models.file.*;
import com.volcengine.ark.runtime.service.ArkService;
public class demo {
public static void main(String[] args) {
String apiKey = System.getenv("ARK_API_KEY");
ArkService service = ArkService.builder().apiKey(apiKey)
.baseUrl("https://ark.cn-beijing.volces.com/api/v3")
.build();
// Retrieve the file metadata.
FileObject fileMeta = service.retrieveFile("<FILE_ID>");
System.out.println("Retrieve File:" + fileMeta);
service.shutdownExecutor();
}
}
import os
from openai import OpenAI
api_key = os.getenv('ARK_API_KEY')
client = OpenAI(
base_url='https://ark.cn-beijing.volces.com/api/v3',
api_key=api_key,
)
# Retrieve the file metadata.
response = client.files.retrieve(
file_id="<FILE_ID>"
)
print(response)
查询文件列表#
通过 Files API 查询已上传的文件列表,可参考 查询文件列表 接口说明。
curl https://ark.cn-beijing.volces.com/api/v3/files \
-H "Authorization: Bearer $ARK_API_KEY"
import os
from arkruntime import Ark
api_key = os.getenv('ARK_API_KEY')
client = Ark(
base_url='https://ark.cn-beijing.volces.com/api/v3',
api_key=api_key,
)
response = client.files.list()
print(response)
package main
import (
"context"
"fmt"
"os"
"github.com/volcengine/ark-runtime-go/arkruntime"
"github.com/volcengine/ark-runtime-go/arkruntime/model/file"
)
func main() {
client := arkruntime.NewClientWithApiKey(
os.Getenv("ARK_API_KEY"),
arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"),
)
ctx := context.Background()
fileInfo, err := client.ListFiles(ctx, &file.FilesListParams{})
if err != nil {
fmt.Printf("get file List error: %v", err)
return
}
fmt.Printf("file List: %v", fileInfo)
}
package com.ark.sample;
import com.volcengine.ark.runtime.models.file.*;
import com.volcengine.ark.runtime.service.ArkService;
public class demo {
public static void main(String[] args) {
String apiKey = System.getenv("ARK_API_KEY");
ArkService service = ArkService.builder().apiKey(apiKey)
.baseUrl("https://ark.cn-beijing.volces.com/api/v3")
.build();
FileListRequest request = new FileListRequest();
FileListResponse listFiles = service.listFiles(request);
System.out.println("List Files:" + listFiles);
service.shutdownExecutor();
}
}
import os
from openai import OpenAI
api_key = os.getenv('ARK_API_KEY')
client = OpenAI(
base_url='https://ark.cn-beijing.volces.com/api/v3',
api_key=api_key,
)
response = client.files.list()
print(response)
删除文件#
删除文件接口用于根据文件 ID 删除文件,并将文件从存储空间中移除,可参考 删除文件 接口说明。
针对高频存储场景,做好存储空间管理的方式如下。存储限制,具体参见 文件存储限制。
-
缩短文件存储时长:上传成功的文件默认存储 7 天,可以通过
expire_at参数自定义存储有效期,取值范围为 1–30 天。文件超过存储有效期后会自动删除。音色注册文件将expire_at设置为-1时永久有效,可通过删除文件接口主动删除。参数设置请参见 上传文件。 -
主动调用删除接口清理低频文件:通过 Files API 删除已上传的文件,使用示例如下。
# Replace <FILE_ID> with the ID returned by the file upload API. curl "https://ark.cn-beijing.volces.com/api/v3/files/<FILE_ID>" \ -X DELETE \ -H "Authorization: Bearer $ARK_API_KEY"import os from arkruntime import Ark api_key = os.getenv('ARK_API_KEY') client = Ark( base_url='https://ark.cn-beijing.volces.com/api/v3', api_key=api_key, ) if __name__ == "__main__": try: response = client.files.delete( file_id="<FILE_ID>" ) print(response) except Exception as e: print(f"failed to delete response: {e}")package main import ( "context" "fmt" "os" "github.com/volcengine/ark-runtime-go/arkruntime" ) func main() { client := arkruntime.NewClientWithApiKey( os.Getenv("ARK_API_KEY"), arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"), ) ctx := context.Background() fileInfo, err := client.DeleteFile(ctx, "<FILE_ID>") if err != nil { fmt.Printf("delete file error: %v", err) return } fmt.Printf(" delete file: %v", fileInfo) }package com.ark.sample; import com.volcengine.ark.runtime.models.file.*; import com.volcengine.ark.runtime.service.ArkService; public class demo { public static void main(String[] args) { String apiKey = System.getenv("ARK_API_KEY"); ArkService service = ArkService.builder().apiKey(apiKey) .baseUrl("https://ark.cn-beijing.volces.com/api/v3") .build(); // Delete the file. FileDeleted deleteFile = service.deleteFile("<FILE_ID>"); System.out.println("Delete File:" + deleteFile); service.shutdownExecutor(); } }import os from openai import OpenAI api_key = os.getenv('ARK_API_KEY') client = OpenAI( base_url='https://ark.cn-beijing.volces.com/api/v3', api_key=api_key, ) if __name__ == "__main__": try: response = client.files.delete( file_id="<FILE_ID>" ) print(response) except Exception as e: print(f"failed to delete response: {e}")
使用 File ID 实现多模态理解#
针对文件较大或需在多次请求中重复使用该文件的场景,建议通过 Files API 上传文件,然后在 Responses API、Chat API 中使用 File ID 的方式实现多模态理解。具体示例参见 视频理解、图片理解、文档理解、音频理解。
上传文件后,需等待文件处理完成后(即 status 为 active 时)才能在 Responses API、Chat API 中使用对应的 File ID 进行分析。下面是视频理解的示例代码。
-
上传视频文件获取 File ID。
curl https://ark.cn-beijing.volces.com/api/v3/files \ -H "Authorization: Bearer $ARK_API_KEY" \ -F 'purpose=user_data' \ -F 'file=@/Users/doc/demo.mp4' \ -F 'preprocess_configs[video][fps]=0.3' -
在 Responses API 中引用 File ID。
curl https://ark.cn-beijing.volces.com/api/v3/responses \ -H "Authorization: Bearer $ARK_API_KEY" \ -H 'Content-Type: application/json' \ -d '{ "model": "doubao-seed-2-1-pro-260915", "input": [ { "role": "user", "content": [ { "type": "input_file", "file_id": "file-20251018****" }, { "type": "input_text", "text": "请你描述下视频中的人物的一系列动作,以JSON格式输出开始时间(start_time)、结束时间(end_time)、事件(event)、是否危险(danger),请使用HH:mm:ss表示时间戳。" } ] } ] }'
import asyncio
import os
from arkruntime import AsyncArk
from arkruntime.types.responses.response_completed_event import ResponseCompletedEvent
from arkruntime.types.responses.response_reasoning_summary_text_delta_event import ResponseReasoningSummaryTextDeltaEvent
from arkruntime.types.responses.response_output_item_added_event import ResponseOutputItemAddedEvent
from arkruntime.types.responses.response_text_delta_event import ResponseTextDeltaEvent
from arkruntime.types.responses.response_text_done_event import ResponseTextDoneEvent
client = AsyncArk(
base_url='https://ark.cn-beijing.volces.com/api/v3',
api_key=os.getenv('ARK_API_KEY')
)
async def main():
# upload video file
print("Upload video file")
file = await client.files.create(
# replace with your local video path
file=open("/Users/doc/demo.mp4", "rb"),
purpose="user_data",
preprocess_configs={
"video": {
"model": "doubao-seed-2-1-pro-260915",
"fps": 0.3, # define the sampling fps of the video, default is 1.0
}
}
)
print(f"File uploaded: {file.id}")
# Wait for the file to finish processing
await client.files.wait_for_processing(file.id)
print(f"File processed: {file.id}")
stream = await client.responses.create(
model="doubao-seed-2-1-pro-260915",
input=[
{"role": "user", "content": [
{
"type": "input_video",
"file_id": file.id # ref video file id
},
{
"type": "input_text",
"text": "请你描述下视频中的人物的一系列动作,以JSON格式输出开始时间(start_time)、结束时间(end_time)、事件(event)、是否危险(danger),请使用HH:mm:ss表示时间戳。"
}
]},
],
caching={
"type": "enabled",
},
store=True,
stream=True
)
async for event in stream:
if isinstance(event, ResponseReasoningSummaryTextDeltaEvent):
print(event.delta, end="")
if isinstance(event, ResponseOutputItemAddedEvent):
print("\noutPutItem " + event.type + " start:")
if isinstance(event, ResponseTextDeltaEvent):
print(event.delta,end="")
if isinstance(event, ResponseTextDoneEvent):
print("\noutPutTextDone.")
if isinstance(event, ResponseCompletedEvent):
print("Response Completed. Usage = " + event.response.usage.model_dump_json())
if __name__ == "__main__":
asyncio.run(main())
package main
import (
"context"
"fmt"
"io"
"os"
"time"
"github.com/volcengine/ark-runtime-go/arkruntime"
"github.com/volcengine/ark-runtime-go/arkruntime/model/file"
"github.com/volcengine/ark-runtime-go/arkruntime/model/responses"
)
func main() {
client := arkruntime.NewClientWithApiKey(
// Get API Key: https://ark.volcengine.com/region:cn-beijing/apikey
os.Getenv("ARK_API_KEY"),
arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"),
)
ctx := context.Background()
fmt.Println("----- upload video data -----")
data, err := os.Open("/Users/doc/demo.mp4")
if err != nil {
fmt.Printf("read file error: %v\n", err)
return
}
fileInfo, err := client.UploadFile(ctx, &file.FileCreateRequest{
Purpose: file.PurposeUserData,
PreprocessConfigs: file.NewOptPreprocessConfigs(file.PreprocessConfigs{
Video: file.NewOptVideo(file.Video{
Model: file.NewOptString("doubao-seed-2-1-pro-260915"),
Fps: file.NewOptFloat64(0.3),
}),
}),
}, data)
if err != nil {
fmt.Printf("upload file error: %v", err)
return
}
// Wait for the file to finish processing
for fileInfo.Status == file.StatusProcessing {
fmt.Println("Waiting for video to be processed...")
time.Sleep(2 * time.Second)
fileInfo, err = client.RetrieveFile(ctx, fileInfo.ID) // Retrieve file info
if err != nil {
fmt.Printf("get file status error: %v", err)
return
}
}
fmt.Printf("Video processing completed: %s, status: %s\n", fileInfo.ID, fileInfo.Status)
inputMessage := responses.InputItem{
OneOf: responses.NewItemEasyMessageInputItemSum(
responses.ItemEasyMessage{
Role: responses.NewOptMessageRole(responses.MessageRoleUser),
Content: responses.NewContentItemArrayMessageContent(
[]responses.ContentItem{
responses.ContentItem{OneOf: responses.NewContentItemVideoContentItemSum(responses.ContentItemVideo{Type: responses.ContentItemVideoTypeInputVideo, VideoURL: "", FileID: responses.NewOptString(fileInfo.ID)})},
responses.ContentItem{OneOf: responses.NewContentItemTextContentItemSum(responses.ContentItemText{Type: responses.ContentItemTextTypeInputText, Text: "请你描述下视频中的人物的一系列动作,以JSON格式输出开始时间(start_time)、结束时间(end_time)、事件(event)、是否危险(danger),请使用HH:mm:ss表示时间戳。"})},
},
),
},
),
}
createResponsesReq := &responses.ResponsesRequest{
Model: "doubao-seed-2-1-pro-260915",
Input: responses.NewInputItemArrayResponsesInput([]responses.InputItem{inputMessage}),
}
resp, err := client.CreateResponsesStream(ctx, createResponsesReq)
if err != nil {
fmt.Printf("stream error: %v\n", err)
return
}
var responseId string
for {
event, err := resp.Recv()
if err == io.EOF {
break
}
if err != nil {
fmt.Printf("stream error: %v\n", err)
return
}
handleEvent(event)
if event.OneOf.Type == responses.ResponseCreatedEventResponseStreamEventSum {
responseId = event.OneOf.ResponseCreatedEvent.Response.ID
fmt.Printf("Response ID: %s", responseId)
}
}
}
func handleEvent(event *responses.ResponseStreamEvent) {
switch event.OneOf.Type {
case responses.ResponseReasoningSummaryTextDeltaEventResponseStreamEventSum:
print(event.OneOf.ResponseReasoningSummaryTextDeltaEvent.Delta.Or(""))
case responses.ResponseReasoningSummaryTextDoneEventResponseStreamEventSum:
fmt.Printf("\nAggregated reasoning text: %s\n", event.OneOf.ResponseReasoningSummaryTextDoneEvent.Text.Or(""))
case responses.ResponseTextDeltaEventResponseStreamEventSum:
print(event.OneOf.ResponseTextDeltaEvent.Delta.Or(""))
case responses.ResponseTextDoneEventResponseStreamEventSum:
fmt.Printf("\nAggregated output text: %s\n", event.OneOf.ResponseTextDoneEvent.Text.Or(""))
}
}
package com.ark.sample;
import com.volcengine.ark.runtime.models.file.*;
import com.volcengine.ark.runtime.service.ArkService;
import com.volcengine.ark.runtime.models.responses.*;
import java.io.File;
import java.util.concurrent.TimeUnit;
public class demo {
public static void main(String[] args) {
String apiKey = System.getenv("ARK_API_KEY");
ArkService service = ArkService.builder().apiKey(apiKey)
.baseUrl("https://ark.cn-beijing.volces.com/api/v3")
.build();
System.out.println("===== Upload File Example=====");
// upload a video for responses
FileObject fileMeta;
fileMeta = service.uploadFile(FileCreateRequest.builder() // replace with your video file path
.purpose(Purpose.USER_DATA)
.preprocessConfigs(PreprocessConfigs.builder().video(Video.builder().model("doubao-seed-2-1-pro-260915").fps(0.3).build()).build())
.build(), new File("/Users/doc/demo.mp4"));
System.out.println("Uploaded file Meta: " + fileMeta);
System.out.println("status:" + fileMeta.getStatus());
try {
while ("processing".equalsIgnoreCase(fileMeta.getStatus().toString())) {
System.out.println("Waiting for video to be processed...");
TimeUnit.SECONDS.sleep(2);
fileMeta = service.retrieveFile(fileMeta.getId());
}
} catch (Exception e) {
System.err.println("get file status error:" + e.getMessage());
}
System.out.println("Uploaded file Meta: " + fileMeta);
ResponsesRequest request = ResponsesRequest.builder()
.model("doubao-seed-2-1-pro-260915")
.stream(true)
.input(ResponsesInput.ofList(java.util.Arrays.asList(ItemEasyMessage.builder().role(MessageRole.USER).content(
MessageContent.ofList(java.util.Arrays.asList(ContentItemVideo.builder().fileId(fileMeta.getId()).build(), ContentItemText.builder().text("请你描述下视频中的人物的一系列动作,以JSON格式输出开始时间(start_time)、结束时间(end_time)、事件(event)、是否危险(danger),请使用HH:mm:ss表示时间戳。").build()))
).build())))
.build();
service.streamResponse(request)
.doOnError(Throwable::printStackTrace)
.blockingForEach(event -> {
if (event instanceof ResponseReasoningSummaryTextDeltaEvent) {
System.out.print(((ResponseReasoningSummaryTextDeltaEvent) event).getDelta());
}
if (event instanceof ResponseOutputItemAddedEvent) {
System.out.println("\nOutputItem " + (((ResponseOutputItemAddedEvent) event).getItem().getType()) + " Start: ");
}
if (event instanceof ResponseTextDeltaEvent) {
System.out.print(((ResponseTextDeltaEvent) event).getDelta());
}
if (event instanceof ResponseTextDoneEvent) {
System.out.println("\nOutputText End.");
}
if (event instanceof ResponseOutputItemDoneEvent) {
System.out.println("\nOutputItem " + ((ResponseOutputItemDoneEvent) event).getItem().getType() + " End.");
}
if (event instanceof ResponseFunctionCallArgumentsDoneEvent) {
System.out.println("\nFunctionCall Arguments: " + ((ResponseFunctionCallArgumentsDoneEvent) event).getArguments());
}
if (event instanceof ResponseCompletedEvent) {
System.out.println("\nResponse Completed. Usage = " + ((ResponseCompletedEvent) event).getResponse().getUsage());
}
});
service.shutdownExecutor();
}
}
import os
import time
from openai import OpenAI
api_key = os.getenv('ARK_API_KEY')
client = OpenAI(
base_url='https://ark.cn-beijing.volces.com/api/v3',
api_key=api_key,
)
file = client.files.create(
file=open("/Users/doc/demo.mp4", "rb"),
purpose="user_data",
extra_body={
"preprocess_configs": {
"video": {
"model": "doubao-seed-2-1-pro-260915",
"fps": 0.3,
}
}
},
)
# Wait for the file to finish processing
while (file.status == "processing"):
time.sleep(2)
file = client.files.retrieve(file.id)
print(f"File processed: {file}")
response = client.responses.create(
model="doubao-seed-2-1-pro-260915",
input=[
{
"role": "user",
"content": [
{
"type": "input_video",
"file_id": file.id,
},
{
"type": "input_text",
"text": "请你描述下视频中的人物的一系列动作,以JSON格式输出开始时间(start_time)、结束时间(end_time)、事件(event)、是否危险(danger),请使用HH:mm:ss表示时间戳。",
},
]
}
],
stream=True
)
for event in response:
if event.type == "response.reasoning_summary_text.delta":
print(event.delta, end="")
if event.type == "response.output_item.added":
print("\noutPutItem " + event.type + " start:")
if event.type == "response.output_text.delta":
print(event.delta,end="")
if event.type == "response.output_item.done":
print("\noutPutTextDone.")
if event.type == "response.completed":
print("\nResponse Completed. Usage = " + event.response.usage.model_dump_json())
计费说明#
Files API 提供的上传文件、管理文件等能力均不会产生费用。
上传的文件根据存储位置的不同,计费信息如下:
- 文件存储在方舟平台托管的默认存储空间:每个账号提供 20 GB 免费存储额度,跨项目共享。永久有效的音色注册文件也计入该额度,删除前持续占用存储空间。超出额度后无法上传文件,删除文件释放存储空间后可继续上传。
- 文件存储在用户指定的火山引擎对象存储 TOS Bucket:将产生存储容量、流量、请求次数、数据取回等费用,详细计费规则参考 对象托管。
使用限制及错误码#
- Files API QPS 限流及带宽限制如下。
- 上传文件:20 QPS、100 Mbps 带宽
- 检索文件:20 QPS
- 查询文件列表:20 QPS
- 删除文件:20 QPS
- 错误码:单击 错误码,获取相关信息。