Skip to main content

Documentation Index

Fetch the complete documentation index at: https://platform.stepfun.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

Calculate the token count for a conversation. The request format is similar to the Chat Completion API.

Endpoint

POST https://api.stepfun.ai/v1/token/count

Request parameters

  • model string required
    Model name to use.
  • messages object array required
    Conversation so far, including user and assistant messages.

Response

  • data object
    Token count result.

Examples

curl https://api.stepfun.ai/v1/token/count \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $STEP_API_KEY" \
  -d '{
    "model": "step-1-8k",
    "messages": [
      {
        "role": "system",
        "content": "You are an AI assistant provided by StepFun. You excel at conversations in Chinese, English, and other languages. While keeping user data safe, you should answer quickly and accurately, and reject any content related to pornography, drugs, gambling, violence, or terrorism."
      },
      {
        "role": "user",
        "content": "Hi, please introduce StepFun'\''s AI!"
      }
    ]
  }'
{
  "data": {
    "total_tokens": 85
  }
}