切换外观
估算 Coding Anthropic 输入 Token
只鉴权并保留 Coding 输入字节限长。
POST/anthropic/v1/messages/count_tokens- 鉴权与权益
- api-key-only
- 入口语境
- anthropic-alias
POST /anthropic/v1/messages/count_tokens 接口
方法:
POST路径:
/anthropic/v1/messages/count_tokens入口家族:
anthropic-alias计费语境:
coding-plan调用前置:
api-key-only
鉴权
以下方案任选其一:
AnthropicApiKeyBearerAuth
请求
请求体:application/json
json
{"$ref":"#/components/schemas/AnthropicCountTokensRequest"}响应
| 状态 | 说明 | Schema |
|---|---|---|
| 200 | 成功 | {"$ref":"#/components/schemas/AnthropicCountTokensResponse"} |
| 401 | API Key 无效或供应商同状态响应 | {"$ref":"#/components/schemas/AnthropicError"} |
| 413 | 请求超过输入字节上限或供应商同状态响应 | {"$ref":"#/components/schemas/AnthropicError"} |
| 500 | 平台内部错误或供应商同状态响应 | {"$ref":"#/components/schemas/AnthropicError"} |
流式行为
non-streaming
错误
invalid_api_keypackage_input_too_largeinternal_error
限制
额外执行 Coding Plan 输入字节上限只鉴权,不校验 active package、不预留套餐、不扣余额
兼容性
inventory:contract-coding-anthropic-count-tokens-aliasprotocol:anthropic-compatible
可执行示例
cURL
sh
curl --request POST "${TOKENFACTORY_API_BASE_URL}/anthropic/v1/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\":\"你好\"}]}"