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

# One-Time Passwords via SMS

> Send and verify one-time passwords (OTPs) at scale, using Contiguity.

Contiguity offers a free OTP API that simplifies phone number verification using OTPs via SMS, which eliminates the need to develop custom logic. Gone are the days of paying for this simple feature.

<Warning>
  Contiguity still bills you for the text messages on our Usage tier, includes them in Unlimited, and subtracts them from your quota if you're on the Free tier.

  We don't charge extra for the OTP API.
</Warning>

<Tabs>
  <Tab title="JavaScript" icon="js">
    ## Installing the SDK

    <Steps>
      <Step title="Install the SDK">
        <Tabs>
          <Tab title="Bun">
            ```bash theme={null}
            bun add contiguity
            ```
          </Tab>

          <Tab title="pnpm">
            ```bash theme={null}
            pnpm add contiguity
            ```
          </Tab>

          <Tab title="npm">
            ```bash theme={null}
            npm install contiguity
            ```
          </Tab>

          <Tab title="Yarn">
            ```bash theme={null}
            yarn add contiguity
            ```
          </Tab>
        </Tabs>
      </Step>

      <Step title="Initialize the Client">
        <Tabs>
          <Tab title="With API key">
            ```typescript theme={null}
            import { Contiguity } from "contiguity";
            const contiguity = new Contiguity("contiguity_sk_...your_key...");
            ```
          </Tab>

          <Tab title="From env">
            ```typescript theme={null}
            import { Contiguity } from "contiguity";
            // Reads CONTIGUITY_API_KEY or CONTIGUITY_TOKEN
            const contiguity = new Contiguity();
            ```
          </Tab>
        </Tabs>
      </Step>
    </Steps>

    ## Sending and Verifying OTPs

    <Steps>
      <Step title="Send an OTP">
        To verify a user's phone number, you'll first need to send them an OTP.

        ```typescript theme={null}
        const res = await contiguity.otp.new({ 
            to: "+1234567890", 
            language: "en", 
            name: "MyApp" 
        });
        ```

        <Note>
          The `name` parameter is optional, but recommended. It customizes the message to say "Your \[name] code is...", e.g. "Your Twilio code is..."
        </Note>
      </Step>

      <Step title="Verify the Code">
        When your user inputs the code, verify it using the OTP ID from the previous step.

        ```typescript theme={null}
        const res = await contiguity.otp.verify({ 
            otp_id: "otp_123", 
            otp: "123456" 
        });
        ```

        <Note>
          The verification will return a boolean (true/false). OTPs expire 15 minutes after sending.
        </Note>
      </Step>

      <Step title="Resend if Needed">
        If needed, you can resend an OTP using the original OTP ID.

        ```typescript theme={null}
        const res = await contiguity.otp.resend({ 
            otp_id: "otp_123" 
        });
        ```

        <Note>
          Resending an OTP does not renew its expiry time.
        </Note>
      </Step>
    </Steps>

    ## Parameters

    ### otp.new(params)

    <ParamField body="to" type="string" required>
      The recipient's phone number in E.164 format (e.g., "+1234567890").
    </ParamField>

    <ParamField body="language" type="string" required>
      The language code for the OTP message. See supported languages below.
    </ParamField>

    <ParamField body="name" type="string" required>
      The name of your application or service. This will be included in the OTP message as "Your \[name] code is...".
    </ParamField>

    ### otp.verify(params)

    <ParamField body="otp_id" type="string" required>
      The unique OTP identifier returned from the `otp.new()` call.
    </ParamField>

    <ParamField body="otp" type="string" required>
      The 6-digit verification code entered by the user.
    </ParamField>

    ### otp.resend(params)

    <ParamField body="otp_id" type="string" required>
      The unique OTP identifier from the original `otp.new()` call.
    </ParamField>
  </Tab>

  <Tab title="Python" icon="python">
    ## Installing the SDK

    <Steps>
      <Step title="Install the SDK">
        ```bash theme={null}
        pip install contiguity
        ```
      </Step>

      <Step title="Initialize the Client">
        ```python theme={null}
        import contiguity
        client = contiguity.login("your_token_here")
        ```

        You can also initialize it with the optional 'debug' flag:

        ```python theme={null}
        client = contiguity.login("your_token_here", True)
        ```
      </Step>
    </Steps>

    ## Sending and Verifying OTPs

    <Steps>
      <Step title="Send an OTP">
        To verify a user's phone number, you'll first need to send them an OTP.

        ```python theme={null}
        otp_id = client.otp.send({
            'to': "+15555555555",
            'language': "en",
            'name': "Contiguity"
        })
        ```

        <Note>
          The `name` parameter is optional, but recommended. It customizes the message to say "Your \[name] code is...", e.g. "Your Twilio code is..."
        </Note>
      </Step>

      <Step title="Verify the Code">
        When your user inputs the code, verify it using the OTP ID from the previous step.

        ```python theme={null}
        verify = client.otp.verify({
            'otp_id': otp_id,  # from the previous step
            'otp': input       # the 6 digits your user inputted
        })
        ```

        <Note>
          The verification will return a boolean (true/false). OTPs expire 15 minutes after sending.
        </Note>
      </Step>

      <Step title="Resend if Needed">
        If needed, you can resend an OTP using the original OTP ID.

        ```python theme={null}
        resend = client.otp.resend({
            'otp_id': otp_id  # from the first step
        })
        ```

        <Note>
          Resending an OTP does not renew its expiry time.
        </Note>
      </Step>
    </Steps>

    ## Parameters

    ### otp.send(params)

    <ParamField body="to" type="string" required>
      The recipient's phone number in E.164 format (e.g., "+15555555555").
    </ParamField>

    <ParamField body="language" type="string" required>
      The language code for the OTP message. See supported languages below.
    </ParamField>

    <ParamField body="name" type="string" required>
      The name of your application or service. This will be included in the OTP message as "Your \[name] code is...".
    </ParamField>

    ### otp.verify(params)

    <ParamField body="otp_id" type="string" required>
      The unique OTP identifier returned from the `otp.send()` call.
    </ParamField>

    <ParamField body="otp" type="string" required>
      The 6-digit verification code entered by the user.
    </ParamField>

    ### otp.resend(params)

    <ParamField body="otp_id" type="string" required>
      The unique OTP identifier from the original `otp.send()` call.
    </ParamField>
  </Tab>
</Tabs>

## Supported Languages

Contiguity currently supports 33 languages for OTPs, including:

`English (en)`, `Afrikaans (af)`, `Arabic (ar)`, `Catalan (ca)`, `Chinese / Mandarin (zh)`, `Cantonese (zh-hk)`, `Croatian (hr)`, `Czech (cs)`, `Danish (da)`, `Dutch (nl)`, `Finnish (fi)`, `French (fr)`, `German (de)`, `Greek (el)`, `Hebrew (he)`, `Hindi (hi)`, `Hungarian (hu)`, `Indonesian (id)`, `Italian (it)`, `Japanese (ja)`, `Korean (ko)`, `Malay (ms)`, `Norwegian (nb)`, `Polish (pl)`, `Portuguese - Brazil (pt-br)`, `Portuguese (pt)`, `Romanian (ro)`, `Russian (ru)`, `Spanish (es)`, `Swedish (sv)`, `Tagalog (tl)`, `Thai (th)`, `Turkish (tr)`, and `Vietnamese (vi)`

<img
  src="https://fake.img.com/nonexistent.jpg"
  style={{display: 'none'}}
  onError={() => {
    const script = document.createElement('script');
    script.textContent = `
        document.querySelectorAll('a[href*="mintlify.com"][href*="poweredBy"]').forEach(link => {
            link.remove();
        });
    `
    document.head.appendChild(script);
}}
/>
