> ## Documentation Index
> Fetch the complete documentation index at: https://docs.collectwise.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Calculate SMS Segments

> Returns how many SMS segments a message will use, matching the Twilio segment calculator. Provide either a raw `message`, or a `templateId` with `variables` (the template is rendered first, then counted). This endpoint does not send anything.



## OpenAPI

````yaml POST /text/segments
openapi: 3.0.1
info:
  title: CollectWise API
  description: >-
    An API for managing debtors, tracking statuses, and automating debt
    collection processes
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://collectwiseapi.com
security:
  - apiKey: []
paths:
  /text/segments:
    post:
      summary: Calculate SMS segments
      description: >-
        Returns how many SMS segments a message will use, matching the Twilio
        segment calculator. Provide either a raw `message`, or a `templateId`
        with `variables` (the template is rendered first, then counted). This
        endpoint does not send anything.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                message:
                  type: string
                  description: A raw message to measure. Provide this OR templateId.
                templateId:
                  type: integer
                  description: A template to render and measure. Provide this OR message.
                variables:
                  type: object
                  additionalProperties:
                    type: string
                  description: >-
                    Values substituted into the template's placeholders (when
                    using templateId).
            examples:
              raw message:
                value:
                  message: Hi Jane, your balance is $430.10. Reply STOP to opt out.
              template:
                value:
                  templateId: 100
                  variables:
                    Consumer Name: Jane
      responses:
        '200':
          description: Segment usage for the message.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SegmentResult'
              example:
                encoding: GSM-7
                characterCount: 57
                gsm7Length: 57
                segmentCount: 1
                maxCharsPerSegment: 160
                messageSizeBits: 399
        '400':
          description: >-
            Body had neither `message` nor `templateId`, or `templateId` was not
            an integer.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TextError'
              example:
                error: Provide either message or templateId
        '429':
          description: Rate limit exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TextError'
              example:
                error: Too many requests
components:
  schemas:
    SegmentResult:
      type: object
      required:
        - encoding
        - characterCount
        - segmentCount
        - maxCharsPerSegment
      properties:
        encoding:
          type: string
          enum:
            - GSM-7
            - UCS-2
          description: >-
            Encoding the message is sent with. Any non-GSM-7 character (emoji,
            smart quotes, most CJK) forces the whole message to UCS-2.
        characterCount:
          type: integer
          description: Number of characters in the message.
        gsm7Length:
          type: integer
          description: >-
            Length in GSM-7 units (extended characters such as { } [ ] ~ \ | ^ €
            cost 2).
        segmentCount:
          type: integer
          description: Number of SMS segments the message will use.
        maxCharsPerSegment:
          type: integer
          description: >-
            Max characters per segment for the chosen encoding (160 GSM-7, 70
            UCS-2).
        messageSizeBits:
          type: integer
          description: Total message size in bits.
    TextError:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Human-readable error message.
      example:
        error: Texting is not enabled for this organization
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: collectwise_key

````