
Updated December 2026. Codes and rules verified against carrier documentation; see references at the end.
To validate a US shipping address, call the USPS Addresses API v3 (GET /addresses/v3/address) and read DPVConfirmation: Y means the primary and any secondary number confirmed, D means the apartment or suite is missing, S means the apartment or suite was not confirmed, and N means the address did not confirm. If you ship UPS, also call UPS Address Validation with request option 2 or 3 to get its Commercial or Residential classification, which matters for the UPS residential surcharge. At checkout, block on N, warn on D, S and vacant addresses, and accept the rest.
| Item | USPS Addresses API v3 | UPS Address Validation (Street Level) |
|---|---|---|
| Endpoint | GET https://apis.usps.com/addresses/v3/address | POST https://onlinetools.ups.com/api/addressvalidation/v2/{requestoption} |
| Inputs | streetAddress (required), secondaryAddress, city + state or ZIPCode, optional ZIPPlus4, firm, urbanization | Up to 3 address lines, city, state, postal code, country code |
| Modes | Also /city-state and /zipcode lookups | requestoption 1 = validation, 2 = classification, 3 = both; regionalrequestindicator=True for city, state and ZIP level |
| Returns | Standardized address, ZIP+4, delivery point, carrier route, DPV flags, vacant, business, CMRA, record type, return codes | ValidAddressIndicator, AmbiguousAddressIndicator or NoCandidatesIndicator; candidates (default 15, max 50); classification 0, 1 or 2 |
| Apartments and suites | Confirmed through DPV (D and S codes) | UPS FAQ: does not provide any information for apartment or suite |
| Coverage | US addresses, including APO/FPO/DPO state codes AA, AE, AP | US and Puerto Rico |
| Test host | apis-tem.usps.com (needs production onboarding) | wwwcie.ups.com; street level returns results only for New York and California addresses |
| Usage rules | USPS FAQ: only for validating shipping addresses during label generation; no bulk, batch or list use | Only for users shipping with UPS; data mining gets access revoked; no batch upload; a required liability notice must appear near the input and output screens |
Both APIs take an OAuth 2.0 bearer token. Both document HTTP 429 for rate limiting, and USPS includes a Retry-After header. USPS says higher limits are requested through USPS API Support.
Delivery Point Validation (DPV) checks the address against USPS delivery point records. The additionalInfo.DPVConfirmation values, per the spec:
| Code | USPS definition | Checkout action |
|---|---|---|
| Y | Confirmed for both primary and (if present) secondary numbers. Does not necessarily mean USPS delivers there. | Accept |
| D | Confirmed for the primary number only; secondary number information was missing. | Warn: ask for the apartment or suite |
| S | Confirmed for the primary number only; secondary number was present but not confirmed. | Warn: ask the customer to check the unit |
| N | Both primary and (if present) secondary number failed to confirm. | Block, or require explicit confirmation |
The response also has DPVEnhancedConfirmation, which adds R: "Address DPV Confirmed but USPS does not deliver to the address." Its D and S definitions are worded differently from DPVConfirmation, so pick one field and code against it. Carrier routes R777 and R779 may mean you need to ask where the recipient receives USPS mail.
| Field | Values (from the spec) | Use |
|---|---|---|
returnCode | 31 single match, 32 default match (more information such as apartment, suite or box needed), 22 multiple matches with no default, 21 not found, 13 invalid city, 12 invalid state, 11 invalid ZIP, 10 invalid address | Show the right error message |
recordType | G general delivery, P PO Box, R rural route or highway contract, H highrise, F firm, S street | Detect PO Boxes |
vacant / DPVVacant | Y not occupied, N occupied | Warn |
DPVCMRA | Y found in the Commercial Mail Receiving Agency table | Flag private mailboxes |
DPVBusiness (business is deprecated) | Y business address, N not a business | A hint only; UPS classification decides the UPS surcharge |
DPVNoSecureLocation | Y flagged as not a secure location | Suggest signature or pickup options |
ZIPPlus4, deliveryPoint | 4-digit add-on and 2-digit delivery point | Store the standardized result, not the raw input |
A USPS miss comes back as HTTP 404 with examples such as "Address Not Found," "Multiple Addresses Found" and "Insufficient Address Data." Handle a 404 in your checkout logic as a failed validation; save outage handling for timeouts and 5xx responses.
UPS returns AddressClassification.Code 0 (UnClassified), 1 (Commercial) or 2 (Residential) when you call with request option 2 or 3. Classification matters for pricing: UPS's tariff says a Residential Surcharge applies if either the address entered in the UPS shipping system or the actual delivery address is residential, regardless of the shipper calling it commercial. The tariff defines residential as a home, including a business operating out of a home, and says an address that could be either is treated as residential.
Quoting a home delivery at the commercial price means the surcharge shows up later as an adjustment. Classify before you rate, and quote 0 (UnClassified) as residential, since the tariff resolves doubtful addresses that way. The USPS DPVBusiness flag is useful context, but it is not what UPS bills on.
Collect the unit in its own field and send it as USPS secondaryAddress (USPS also accepts it at the end of streetAddress). USPS Publication 28 lists the approved designators:
| Designator | Abbreviation | Needs a number? |
|---|---|---|
| Apartment | APT | Yes |
| Suite | STE | Yes |
| Unit | UNIT | Yes |
| Building | BLDG | Yes |
| Floor | FL | Yes |
| Room | RM | Yes |
| Space, Lot, Trailer | SPC, LOT, TRLR | Yes |
| Basement, Front, Lobby, Office, Penthouse, Rear | BSMT, FRNT, LBBY, OFC, PH, REAR | No |
| Unknown designator | # | Pub 28 requires the pound sign |
Because UPS Address Validation does not check apartments or suites, a UPS "valid" result for an apartment building says nothing about the unit. Use the USPS DPV result for units even when the label is UPS.
USPS delivers to PO Boxes; you can detect one from recordType P. On the UPS side, the UPS tariff says UPS does not deliver to a P.O. Box and that APO and FPO addresses are not accepted. UPS Ground Saver is the exception: UPS lists US PO Boxes and APO, FPO and DPO addresses as Ground Saver destinations, and says Ground Saver packages may be delivered by UPS or the USPS. See Can you ship to a PO Box? and UPS Ground Saver vs USPS Ground Advantage.
Military and diplomatic addresses follow DMM 703. The city line is APO, FPO or DPO, the "state" is AA, AE or AP (used for ZIP Code prefixes 340, 090 to 098 and 962 to 966 respectively), and the address must not include a foreign city or country name. The delivery line carries a unit type and number such as UNIT or PSC plus a box number where applicable. Don't let address autocomplete "fix" APO into a city name.
#, hyphens, slashes and apostrophes, which appear in real unit numbers, fractional addresses and street names.D.streetAddressAbbreviation and cityAbbreviation; store what it returns.urbanization when the customer gives one.import re
def normalize_line(line: str) -> str:
"""Light cleanup before calling a validation API: uppercase, drop most
punctuation, collapse spaces. Leave abbreviation to the carrier."""
s = line.upper().replace("P.O.", "PO")
s = re.sub(r"#\s*", "# ", s) # "#4" -> "# 4"
s = re.sub(r"[^\w#\-/' ]", " ", s) # keep #, hyphen, slash, apostrophe
return re.sub(r"\s+", " ", s).strip()
# normalize_line("123 Main St. #4") returns "123 MAIN ST # 4"
Block only when the address can't work for the chosen service, and warn when the customer can fix the problem in one step. On a warning, offer "use the address as entered" and log the choice.
| Signal | Action |
|---|---|
DPV N, or a 404 from USPS | Block (or require explicit confirmation) |
| PO Box or AA/AE/AP address with a UPS service other than Ground Saver | Block; offer USPS or Ground Saver |
DPV D or S | Warn: ask for or correct the unit |
Vacant, CMRA, enhanced R, route R777/R779 | Warn |
DPV Y with no flags | Accept and save the standardized address |
This function implements that table. Pass the parsed body for a USPS 404 (it blocks) and an empty dict when the call times out or returns 5xx (it warns, so an outage doesn't stop checkout).
MILITARY_STATES = {"AA", "AE", "AP"}
def checkout_decision(usps: dict, service: str = "usps", ups_class=None): # ups_class: str or None
"""Return {"action": block|warn|accept, "reasons": [...], "residential": bool|None}.
usps: parsed USPS Addresses v3 /address response. service: "usps", "ups",
or "ups_ground_saver". ups_class: UPS AddressClassification Code if called."""
if not usps: # timeout or 5xx: don't block checkout on a USPS outage
return {"action": "warn", "reasons": ["Address could not be verified"],
"residential": None}
info = usps.get("additionalInfo", {})
state = usps.get("address", {}).get("state")
dpv = info.get("DPVConfirmation") # Y, D, S or N
reasons = []
if dpv not in ("Y", "D", "S"):
return {"action": "block", "reasons": ["USPS could not confirm this address"],
"residential": None}
if dpv == "D":
reasons.append("Add the apartment, suite or unit number")
if dpv == "S":
reasons.append("Check the apartment, suite or unit number")
if info.get("vacant") == "Y":
reasons.append("USPS lists this address as vacant")
if info.get("DPVCMRA") == "Y":
reasons.append("Address is a private mailbox (CMRA)")
if info.get("DPVEnhancedConfirmation") == "R" or info.get("carrierRoute") in ("R777", "R779"):
reasons.append("USPS may not deliver here: confirm where the recipient gets mail")
po_box = info.get("recordType") == "P"
military = state in MILITARY_STATES
if service == "ups" and (po_box or military):
return {"action": "block", "residential": None,
"reasons": ["Choose USPS or UPS Ground Saver for PO Box or APO/FPO/DPO"]}
# UPS classification: "1" Commercial, "2" Residential, "0" UnClassified
residential = {"1": False, "2": True}.get(ups_class or "")
return {"action": "warn" if reasons else "accept", "reasons": reasons,
"residential": residential}
A residential value of None means UPS gave no Commercial or Residential answer; rate those as residential. Validate once at submit and cache the result with the order. If an AI agent buys your labels, give it this same decision output so it can ask the user about a unit number instead of guessing; see the shipping API guide for AI agents.
USPS confirmed the building (primary number) but the secondary information, such as an apartment or suite number, was missing. Ask the customer for the unit before you buy the label.
It returns a DPVBusiness flag (Y or N); the older business field is marked deprecated in the spec. For UPS shipments, the residential surcharge follows UPS's own classification, which you get from UPS Address Validation with request option 2 or 3.
No. The UPS FAQ says it validates street address, city, state and ZIP Code and does not provide any information for apartment or suite. Use USPS DPV for units.
No. USPS says the Addresses API is only for validating shipping addresses during label generation, and bulk, batch or mailing list use is not permitted.
Through UPS Ground Saver, yes: UPS lists APO/FPO/DPO addresses as Ground Saver destinations, and those packages may be delivered by UPS or the USPS. UPS's general tariff says APO and FPO addresses are not accepted.
Ship.com gives you USPS and UPS labels at up to 89% off USPS and up to 87% off UPS without your own carrier accounts, from your code through the REST API or from AI agents through the MCP server. Every account starts with a 30-day free trial, no credit card required. Read the Ship MCP setup guide or See plans and pricing.