Token calculator (Embedding v2)
    • PDF

    Token calculator (Embedding v2)

    • PDF

    Article summary

    Available in Classic and VPC

    Calculate the number of tokens in a sentence entered in Embedding v2.

    Request

    The following describes the request format for the endpoint. The request format is as follows:

    MethodURI
    POST/v1/api-tools/embedding/v2/tokenize

    Request headers

    The following describes the headers.

    HeadersRequiredDescription
    X-NCP-CLOVASTUDIO-API-KEYRequiredAPI key issued when creating the test app or service app
    X-NCP-APIGW-API-KEYRequiredAPI Gateway key issued when creating the test app or service app
    X-NCP-CLOVASTUDIO-REQUEST-IDOptionalRequest ID
    Content-TypeRequiredRequest data format
    • application/json

    Request body

    The following describes the request body.

    FieldTypeRequiredDescription
    textStringRequiredList of conversation messages to count tokens for
    • 1 - 10,000 characters (based on Korean)

    Request example

    The following is a sample request.

    curl --location --request POST 'https://clovastudio.apigw.ntruss.com/v1/api-tools/embedding/v2/tokenize' \
    --header 'X-NCP-CLOVASTUDIO-API-KEY: {CLOVA Studio API Key}' \
    --header 'X-NCP-APIGW-API-KEY: {API Gateway API Key}' \
    --header 'X-NCP-CLOVASTUDIO-REQUEST-ID: {Request ID}' \
    --header 'Content-Type: application/json' \
    --data '{
        "text": "Tell me the total number of tokens."
    }'
    

    Response

    The following describes the response format.

    Response body

    The following describes the response body.

    FieldTypeRequiredDescription
    numTokensInteger-Result of calculating the number of tokens

    Response example

    The following is a sample example.

    Succeeded

    The following is a sample response upon a successful call.

    {
        "status": {
            "code": "20000",
            "message": "OK"
        },
        "result": {
            "numTokens": 1000
        }
    }
    

    Failure

    The following is a sample response upon a failed call.


    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.