Skip to content

估算 Coding Anthropic 输入 Token

只鉴权并保留 Coding 输入字节限长。

POST/v1/coding/anthropic/messages/count_tokens
鉴权与权益
api-key-only
入口语境
coding-plan
跳到可执行示例

POST /v1/coding/anthropic/messages/count_tokens 接口

  • 方法:POST

  • 路径:/v1/coding/anthropic/messages/count_tokens

  • 入口家族:coding-plan

  • 计费语境:coding-plan

  • 调用前置:api-key-only

鉴权

以下方案任选其一:

  • AnthropicApiKey
  • BearerAuth

请求

请求体:application/json

json
{"$ref":"#/components/schemas/AnthropicCountTokensRequest"}

响应

状态说明Schema
200成功{"$ref":"#/components/schemas/AnthropicCountTokensResponse"}
401API Key 无效或供应商同状态响应{"$ref":"#/components/schemas/AnthropicError"}
413请求超过输入字节上限或供应商同状态响应{"$ref":"#/components/schemas/AnthropicError"}
500平台内部错误或供应商同状态响应{"$ref":"#/components/schemas/AnthropicError"}

流式行为

non-streaming

错误

  • invalid_api_key
  • package_input_too_large
  • internal_error

限制

  • 额外执行 Coding Plan 输入字节上限
  • 只鉴权,不校验 active package、不预留套餐、不扣余额

兼容性

  • inventory:contract-coding-anthropic-count-tokens
  • protocol:anthropic-compatible

可执行示例

cURL

sh
curl --request POST "${TOKENFACTORY_API_BASE_URL}/v1/coding/anthropic/messages/count_tokens" --silent --show-error --fail-with-body --max-time 60 --header "x-api-key: ${TOKENFACTORY_API_KEY}" --header "anthropic-version: 2023-06-01" --header "Content-Type: application/json" --data "{\"model\":\"${TOKENFACTORY_MODEL_ID}\",\"messages\":[{\"role\":\"user\",\"content\":\"你好\"}]}"

Token Factory · 国产合规 AI Gateway