You need to enable JavaScript to run this app.
文档中心
火山方舟

火山方舟

复制全文
下载 pdf
Messages API
统计 Messages 请求 token 数
复制全文
下载 pdf
统计 Messages 请求 token 数
POST https://ark.cn-beijing.volces.com/api/compatible/v1/messages/count_tokens​
统计 Messages 请求的输入 token 数,可用于请求预估、配额控制和成本测算。实际用量以真实请求结果为准。​
鉴权​
本接口支持鉴权方式如下,详情请参见 Base URL 及鉴权。​
  • API Key 鉴权,请在 API Key 管理 页面,获取长效 API Key。​
​​
请求参数​
Body 参数​
messages object[] 必选 | 消息列表​
​
model string 必选 | 模型 ID​
​
max_tokens integer | 最大输出 token 数​
​
output_config object | 输出配置​
​
output_format object | 输出格式​
​
service_tier string 默认值 default | 推理模式​
​
stop_sequences string / string[] | 停止序列​
​
stream boolean | 响应内容是否流式返回​
​
system string / object[] | 系统提示词​
​
temperature number | 采样温度​
​
thinking object | 深度思考配置​
​
tool_choice object | 工具调用策略​
​
tools object[] | 工具列表​
​
top_p number | 核采样概率​
​
​
响应参数​
input_tokens integer | 输入消息对应的 token 数​
​
​

Request

curl https://ark.cn-beijing.volces.com/api/compatible/v1/messages/count_tokens \
  -H "Content-Type: application/json" \
  -H "x-api-key: $ARK_API_KEY" \
  -d '{
    "model": "doubao-seed-2-1-pro-260915",
    "system": "You are a scientist.",
    "messages": [
      {
        "role": "user",
        "content": "Hello, Ark"
      }
    ]
  }'

Response

{
  "input_tokens": 23
}
最近更新时间:2026.10.09 14:36:35
这个页面对您有帮助吗?
有用
有用
无用
无用