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

# Preview message cost

> Prices a message before you send it, without sending anything. Returns the segment count, price per segment, and total in your account currency.



## OpenAPI

````yaml openapi-sms.yaml GET /api/v1/Account/{auth_id}/Sms/Message/CostPreview/
openapi: 3.0.3
info:
  title: Vobiz Messaging API
  description: >
    Send and receive SMS, MMS and RCS messages, buy messaging numbers, register
    for

    US 10DLC and toll-free, run broadcasts, manage conversations, opt-outs and
    webhooks.


    **Base URL:** `https://api.vobiz.ai/api/v1/Account/{auth_id}/Sms`, where
    `{auth_id}` is your

    account Auth ID. Paths in descriptions, such as `POST /Message/`, are
    relative to it.

    Coverage (`/api/v1/sms/coverage`) and `/api/v1/sms/numbers/countries` are
    not account data

    and keep their `https://api.vobiz.ai/api/v1/sms` URLs.


    **Authentication:** every request needs the `X-Auth-ID` and `X-Auth-Token`
    headers. The

    `{auth_id}` in the path must be the account those credentials belong to,
    otherwise the

    request returns `403`. Field names in this API are camelCase.


    The earlier URLs under `https://api.vobiz.ai/api/v1/sms` (for example `POST
    /api/v1/sms/messages`)

    still work.
  version: '1.0'
  contact:
    email: support@vobiz.ai
    url: https://www.vobiz.ai
servers:
  - url: https://api.vobiz.ai
    description: Production
security:
  - AuthID: []
    AuthToken: []
tags:
  - name: Messages
    description: Send messages and inspect their delivery state.
  - name: Numbers
    description: >-
      Messaging-capable numbers on your account, inventory search, purchase and
      release.
  - name: Number lookup
    description: >-
      Check whether numbers exist and are reachable on the mobile network, and
      which network serves them.
  - name: Coverage
    description: Where you can send, per country.
  - name: Conversations
    description: Two-way threads between one of your numbers and a contact.
  - name: Opt-outs
    description: Numbers that must not receive messages on a channel.
  - name: Webhooks
    description: Subscriptions that deliver message and broadcast events to your server.
  - name: Broadcasts
    description: Bulk sends from an uploaded recipient list.
  - name: RCS Senders
    description: RCS sender (agent) identities and their message templates.
  - name: 10DLC Brands
    description: US 10DLC brand registration.
  - name: 10DLC Campaigns
    description: US 10DLC campaigns, toll-free verification and supporting documents.
paths:
  /api/v1/Account/{auth_id}/Sms/Message/CostPreview/:
    parameters:
      - $ref: '#/components/parameters/AuthId'
    get:
      tags:
        - Messages
      summary: Preview message cost
      description: >-
        Estimates the cost of a message before you send it, without sending
        anything. It splits `text` into segments for the chosen channel and
        returns the segment count with an estimated price per segment and in
        total. Use it to show a cost estimate in your app or to keep long
        messages within a budget. The figures are for one recipient; multiply
        `totalCost` by the number of recipients for a multi-recipient send.
      operationId: preview-message-cost
      parameters:
        - name: from
          in: query
          required: true
          schema:
            type: string
          example: '+14155550100'
          description: >-
            Required. The sender you plan to use: one of your numbers in E.164
            format, or the `senderName` of your RCS sender when `channel` is
            `rcs`. It determines the route the message is priced on.
        - name: to
          in: query
          required: true
          schema:
            type: string
          example: '+14155550123'
          description: >-
            Required. One recipient number in E.164 format, for example
            `+14155550123`. Its destination country determines the price.
        - name: channel
          in: query
          schema:
            type: string
            enum:
              - sms
              - mms
              - rcs
            default: sms
          description: 'Channel to price: `sms`, `mms` or `rcs`. Defaults to `sms`.'
        - name: text
          in: query
          description: >-
            The message body to segment and price, URL-encoded. Pass the exact
            text you plan to send: the segment count depends on its length and
            on whether it fits the GSM-7 character set. Defaults to an empty
            string.
          schema:
            type: string
      responses:
        '200':
          description: Segment count and cost.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CostPreview'
              example:
                channel: sms
                segmentCount: 2
                unitCost: 0.01
                totalCost: 0.02
                currency: USD
        '400':
          description: '`from` and `to` are required.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: from and to are required
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/ServerError'
      x-codeSamples:
        - lang: typescript
          label: Node SDK
          source: >
            import { VobizClient } from "@vobiz/sdk";


            const client = new VobizClient({ apiKey: "MA_XXXXXXXX", authToken:
            "YOUR_AUTH_TOKEN" });


            await client.sms.messages.previewMessageCost({
                from: "+14155550100",
                to: "+14155550123"
            })
        - lang: python
          label: Python SDK
          source: |
            from vobiz import Vobiz

            client = Vobiz(api_key="MA_XXXXXXXX", auth_token="YOUR_AUTH_TOKEN")

            client.sms.messages.preview_message_cost(
                from_="+14155550100",
                to="+14155550123",
            )
        - lang: go
          label: Go SDK
          source: |
            import (
                "context"

                vobiz "github.com/vobiz-ai/Vobiz-Go-SDK"
                "github.com/vobiz-ai/Vobiz-Go-SDK/client"
                "github.com/vobiz-ai/Vobiz-Go-SDK/option"
                "github.com/vobiz-ai/Vobiz-Go-SDK/sms"
            )

            c := client.NewClient(
                option.WithAPIKey("MA_XXXXXXXX"),
                option.WithAuthToken("YOUR_AUTH_TOKEN"),
            )

            request := &sms.PreviewMessageCostRequest{
                    From: "+14155550100",
                    To: "+14155550123",
                }
            c.Sms.Messages.PreviewMessageCost(
                    context.TODO(),
                    request,
                )
        - lang: java
          label: Java SDK
          source: |
            import com.vobiz.api.VobizApiClient;

            VobizApiClient client = VobizApiClient
                .builder()
                .apiKey("MA_XXXXXXXX")
                .authToken("YOUR_AUTH_TOKEN")
                .build();

            client.sms().messages().previewMessageCost(
                PreviewMessageCostRequest
                    .builder()
                    .from("+14155550100")
                    .to("+14155550123")
                    .build()
            );
        - lang: ruby
          label: Ruby SDK
          source: >
            require 'vobiz'


            client = Vobiz::Client.new(api_key: 'MA_XXXXXXXX', auth_token:
            'YOUR_AUTH_TOKEN')


            client.sms.messages.preview_message_cost(
              from: "+14155550100",
              to: "+14155550123"
            )
        - lang: csharp
          label: C# SDK
          source: |
            using Vobiz;
            using Vobiz.Sms;

            var client = new VobizApiClient("YOUR_AUTH_TOKEN", "MA_XXXXXXXX");

            await client.Sms.Messages.PreviewMessageCostAsync(
                new PreviewMessageCostRequest { From = "+14155550100", To = "+14155550123" }
            );
        - lang: php
          label: PHP SDK
          source: >
            <?php


            require 'vendor/autoload.php';


            use Vobiz\VobizClient;


            $client = new VobizClient(apiKey: 'MA_XXXXXXXX', authToken:
            'YOUR_AUTH_TOKEN');


            $client->sms->messages->previewMessageCost(
                new PreviewMessageCostRequest([
                    'from' => '+14155550100',
                    'to' => '+14155550123',
                ]),
            );
components:
  parameters:
    AuthId:
      name: auth_id
      in: path
      required: true
      description: Your account Auth ID. It must match the `X-Auth-ID` header.
      schema:
        type: string
        example: MA_XXXXXXXX
  schemas:
    CostPreview:
      type: object
      properties:
        channel:
          type: string
          example: sms
          description: >-
            Channel the estimate is for: `sms`, `mms` or `rcs`, matching the
            `channel` you requested.
        segmentCount:
          type: integer
          example: 2
          description: >-
            Number of segments the text splits into. A GSM-7 SMS fits 160
            characters in one segment and 153 per segment when split; text with
            other characters uses UCS-2 (70 and 67).
        unitCost:
          type: number
          example: 0.01
          description: Price of one segment, in `currency`.
        totalCost:
          type: number
          example: 0.02
          description: >-
            Estimated price of the message to one recipient, in `currency`:
            `unitCost` multiplied by `segmentCount`.
        currency:
          type: string
          example: USD
          description: ISO 4217 code of the currency the prices are in, for example `USD`.
        country:
          type: string
          description: >-
            ISO 3166-1 alpha-2 code of the destination country, for example
            `US`. Omitted when the destination country is not resolved.
          example: US
      description: >-
        An estimate of what a message costs before you send it: how many
        segments the text splits into, and the price per segment and in total.
    Error:
      type: object
      description: >-
        The body of every error response: a flat object with one `error` string
        that explains what went wrong. Use the HTTP status code to decide how to
        handle the error, and log `error` for diagnosis.
      required:
        - error
      properties:
        error:
          type: string
          example: 'recipient has opted out: +14155550123'
          description: >-
            Human-readable explanation of the error, for example `phoneNumber is
            required` or `recipient has opted out: +14155550123`. Branch on the
            HTTP status code rather than on this text.
    GatewayError:
      type: object
      description: >-
        Error body returned by the Vobiz API gateway for authentication (`401`)
        and account-mismatch (`403`) failures, before the request reaches the
        messaging service. Unlike `Error`, `error` is an object.
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: integer
              example: 401
              description: The HTTP status code, repeated.
            message:
              type: string
              example: Invalid authentication credentials
              description: Human-readable explanation of the failure.
  responses:
    Unauthorized:
      description: >-
        Missing or invalid `X-Auth-ID` / `X-Auth-Token`. The API gateway answers
        before the request reaches the messaging service, so `error` is an
        object with `code` and `message`.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/GatewayError'
          examples:
            missing:
              summary: No credentials
              value:
                error:
                  code: 401
                  message: >-
                    Authentication required: provide either Authorization header
                    or X-Auth-ID and X-Auth-Token headers
            invalid:
              summary: Wrong Auth Token
              value:
                error:
                  code: 401
                  message: Invalid authentication credentials
    Forbidden:
      description: >-
        The `{auth_id}` in the path is not the account that the `X-Auth-ID` /
        `X-Auth-Token` credentials belong to. The API gateway answers, so
        `error` is an object with `code` and `message`.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/GatewayError'
          example:
            error:
              code: 403
              message: 'Access denied: account ID mismatch'
    ServerError:
      description: Unexpected error. Retry with the same idempotency key where one applies.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: internal error
  securitySchemes:
    AuthID:
      type: apiKey
      in: header
      name: X-Auth-ID
      description: Your Vobiz account Auth ID (`MA_XXXXXXXX`).
    AuthToken:
      type: apiKey
      in: header
      name: X-Auth-Token
      description: Your Vobiz account Auth Token.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.