---
title: "Validate contact data in Twilio"
url: "https://lookvalid.com/integrations/twilio.md"
canonical_url: "https://lookvalid.com/integrations/twilio"
last_updated: "2026-10-22"
type: "how-to"
summary: "Screen a US number before your Twilio code sends to it."
related: ["https://lookvalid.com/integrations.md", "https://lookvalid.com/docs/api/carrier-lookup.md", "https://lookvalid.com/docs/quickstart.md"]
---

# Validate contact data in Twilio

Screen a US number before your Twilio code sends to it.

Apps built on Twilio tend to take numbers straight from a signup form, so malformed input, blocks that are not assigned and numbers in the wrong country all become failed sends, error callbacks and a log full of undelivered rows. Checking the number in your own code, before the API call, keeps those out.

## What LookValid checks

- [Carrier Lookup (original carrier)](https://lookvalid.com/products/carrier-lookup.md): Returns the carrier originally assigned a US number block, with its state, rate center and whether the block is in service. It does not reflect a number that was moved to another carrier. (1 credit per lookup (numbers outside the covered numbering plan areas are free))
- [Phone Numbering-Plan Validation](https://lookvalid.com/products/phone.md): Checks the number against its numbering plan and returns the E.164 form your send call expects, plus the type the plan assigns it. (1 credit per valid number)
- [Phone Spam Check](https://lookvalid.com/products/phone-spam.md): Returns public consumer complaint counts for a number, useful before you call back a number that showed up on an inbound log. (1 credit per number with complaints on record)
- [Country Calling Codes](https://lookvalid.com/products/country-code.md): Describes a country calling code, its national number lengths and example numbers, for sign-up forms that take international numbers. (1 credit per lookup (an unknown code, country or name is free))

## Connect it in four steps

1. Create your LookValid account first, then issue a key from the API keys area.
2. Add the key as an Environment Variable named LOOKVALID_API_KEY in the Settings of your Functions Service (with the Serverless Toolkit, in its .env file instead), and read it from context.LOOKVALID_API_KEY inside the Function.
3. Call the carrier lookup endpoint with the destination number before you send; on found:false hold the send for review, and on an error answer stop and log the returned code.
4. Store numberState and numberRateCenter next to the destination number and skip the send when blockInService comes back false.

A Twilio Function (Node.js, edited in the Functions Editor or deployed with the Serverless Toolkit) or a route in your own Node service, called before the code that sends a message or places a call. The call is `POST https://YOUR_API_HOST/v1/carrier-lookup`.

```js
const API_URL = "https://YOUR_API_HOST/v1/carrier-lookup";

export async function screenTwilioNumber(value) {
  const response = await fetch(API_URL, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.LOOKVALID_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      "phone": value,
    }),
  });
  const result = await response.json();
  if (!response.ok) throw new Error(`${result.error.code}: ${result.error.fix}`);
  if (!result.found) return null;
  return {
      "numberState": result.data?.state ?? null,
      "numberRateCenter": result.data?.rate_center ?? null,
      "blockInService": result.data?.in_service ?? null,
  };
}
```

| Response field | Goes into |
| --- | --- |
| `data.state` | numberState |
| `data.rate_center` | numberRateCenter |
| `data.in_service` | blockInService |

## Without code

If your messages go out from a Studio flow, its Run Function widget can call a Function that makes the lookup. If they go out from an automation platform instead, put a generic HTTP request step in front of the send action. It posts the destination number to the carrier lookup endpoint with your key in the Authorization header, and a condition on the in-service field decides whether the send step runs. No dedicated app is involved, only the URL, one header and a small JSON body.

## Questions

### What is the price of a number check before a Twilio send?

Each lookup costs the credits shown on the pricing page. That is separate from anything you pay for the send itself.

### Does it cover numbers outside the United States?

The carrier lookup covers US number blocks only; Canada and the Caribbean are not included. The phone check works for numbers worldwide but reads the numbering plan, not a carrier.

### Where do I keep the key next to my Twilio credentials?

As its own Environment Variable in the Functions Service, which Twilio stores encrypted. Keep it apart from the account SID and auth token values so you can change each one on its own.

## Sources

- [Twilio documentation: Functions](https://www.twilio.com/docs/serverless/functions-assets/functions), read 2026-10-18
- [Twilio documentation: Environment Variables for Functions](https://www.twilio.com/docs/serverless/functions-assets/functions/variables), read 2026-10-18

## Related

- [LookValid integrations](https://lookvalid.com/integrations.md)
- [Carrier Lookup (original carrier) reference](https://lookvalid.com/docs/api/carrier-lookup.md)
- [Quickstart](https://lookvalid.com/docs/quickstart.md)
