MENU
      Sliding window
        • PDF

        Sliding window

        • PDF

        Article summary

        Available in Classic and VPC

        Delete sentences that exceed the maximum number of tokens when using Chat completions API. The oldest conversation turns are deleted to free up tokens so that conversations can be created without interruption.

        Note

        For a detailed description of how the sliding window works and how to work with it, see Utilize API of the CLOVA Studio user guide.

        Request

        This section describes the request format. The method and URI are as follows:

        MethodURI
        POST/v1/api-tools/sliding/chat-messages/{modelName}

        Request headers

        The following describes the request headers.

        FieldRequiredDescription
        AuthorizationRequiredAPI key for authentication <e.g.,> Bearer nv-************
        X-NCP-CLOVASTUDIO-REQUEST-IDOptionalRequest ID
        Content-TypeRequiredRequest data format
        • application/json

        Request path parameters

        You can use the following path parameters with your request:

        FieldTypeRequiredDescription
        modelNameStringRequiredModel name
        • <e.g.> HCX-003

        Request body

        You can include the following data in the body of your request:

        FieldTypeRequiredDescription
        maxTokensIntegerRequiredMaximum number of generated tokens
      • 0 < maxTokens ≤ 4096 (default: 100)
      • messagesArrayRequiredConversation message list
        • Need to be adjusted for maximum number of tokens
        messages.roleEnumRequiredRole of conversation messages
        • system | user | assistant
          • system: directives that define roles
          • user: user utterances/questions
          • assistant: answers to user utterances/questions
        messages.contentStringRequiredContent of conversation messages
        Note

        When entering some fields, check the following.

        • messages: The sum of the number of tokens entered and the number of tokens entered in maxTokens can't exceed 4096 tokens. The number of tokens entered in messages can be checked by calling the Token calculation API.

        Request example

        The request example is as follows:

        curl --location --request POST 'https://clovastudio.stream.ntruss.com/v1/api-tools/sliding/chat-messages/{modelName}' \
        --header 'Authorization: Bearer {API Key}' \
        --header 'X-NCP-CLOVASTUDIO-REQUEST-ID: {Request ID}' \
        --header 'Content-Type: application/json' \
        --data '{
              "maxTokens" : 200,
              "messages" : [ {
                "role" : "user",
                "content" : "hello"
              } ]
        }'
        Shell

        Response

        This section describes the response format.

        Response body

        The following describes the body.

        FieldTypeRequiredDescription
        resultObject-Response result
        • Result of adjusting for the maximum number of tokens
        result.messagesArray-Conversation message list
        result.messages.roleEnum-Role of conversation messages
        • system | user | assistant
          • system: directives that define roles
          • user: user utterances/questions
          • assistant: answers to user utterances/questions
        result.messages.contentString-Content of conversation messages

        Response example

        The response example is as follows:

        Succeeded

        The following is a sample response upon a successful call.

        {
            "status": {
                "code": "20000",
                "message": "OK"
            },
            "result": {
                "messages": [
                    {
                        "role": "user",
                        "content": "hello"
                    }
                ]
            }
        }
        Plain text

        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.