Authentication overview

US Autocomplete secures access to its address validation and autocomplete APIs through API key-based authentication. This mechanism requires developers to include a unique, secret key with each request to the API. The API key serves as both an identifier for the calling application and a credential for authorization, ensuring that only legitimate and subscribed users can access the service and manage their usage against their account limits.

The system is designed to provide a straightforward integration experience while maintaining security. When a client application sends a request to the US Autocomplete API, the API key is validated against the user's account. If the key is valid and the account has sufficient lookup credits, the request is processed, and the relevant address data is returned. This method is common for RESTful APIs due to its simplicity and ease of implementation across various programming languages and platforms, as detailed in the US Autocomplete API documentation.

Understanding the proper handling of API keys is crucial for maintaining the security and integrity of your application and preventing unauthorized use of your US Autocomplete account. Best practices include storing keys securely, transmitting them over encrypted channels, and rotating them periodically.

Supported authentication methods

US Autocomplete primarily supports API Key authentication for accessing its services. This method is widely adopted for its balance of security and ease of use, particularly for web and mobile applications consuming RESTful APIs.

Method When to Use Security Level
API Key Direct API calls from server-side applications, client-side applications (with caution and appropriate security measures) Moderate (depends heavily on secure key management and transmission)

API keys are typically passed as a query parameter or an HTTP header with each request. While simple to implement, the security of API keys relies heavily on how they are managed and protected by the developer. Unlike more complex methods like OAuth 2.0, API keys do not inherently provide mechanisms for user consent or granular permission management beyond access to the specific API. For a broader understanding of API key security, consult resources like the Google Maps API key security recommendations.

Getting your credentials

To obtain your US Autocomplete API key, follow these steps:

  1. Sign Up or Log In: Navigate to the US Autocomplete website and either create a new account or log in to your existing one.
  2. Access Dashboard: After logging in, you will be directed to your account dashboard.
  3. Locate API Key Section: Within the dashboard, look for a section dedicated to 'API Keys', 'Developer Settings', or 'Account Settings'. The exact label may vary but it will typically be clearly identifiable.
  4. Generate/Retrieve Key: Your API key will either be displayed directly or you may need to generate a new one. Some platforms allow you to create multiple keys for different applications or environments, which is a recommended practice for better security and management.
  5. Copy Your Key: Carefully copy your API key. It is a long string of alphanumeric characters. Treat this key as sensitive information, similar to a password.

US Autocomplete provides a free tier offering 500 lookups per month, allowing developers to obtain an API key and test the service without immediate cost. This is an ideal way to familiarize yourself with the API and its authentication process before committing to a paid plan. Details on pricing and tiers are available on the US Autocomplete pricing page.

Authenticated request example

Once you have your API key, you can integrate it into your API requests. The following examples demonstrate how to make an authenticated request using common programming languages. Replace YOUR_API_KEY with your actual US Autocomplete API key.

JavaScript (Fetch API)


fetch('https://api.usautocomplete.com/v1/autocomplete?api_key=YOUR_API_KEY&query=123 Main St', {
  method: 'GET',
  headers: {
    'Accept': 'application/json'
  }
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Python (Requests library)


import requests

api_key = 'YOUR_API_KEY'
query = '123 Main St'
url = f'https://api.usautocomplete.com/v1/autocomplete?api_key={api_key}&query={query}'

headers = {
    'Accept': 'application/json'
}

response = requests.get(url, headers=headers)

if response.status_code == 200:
    print(response.json())
else:
    print(f"Error: {response.status_code} - {response.text}")

PHP (cURL)


<?php

$apiKey = 'YOUR_API_KEY';
$query = '123 Main St';
$url = "https://api.usautocomplete.com/v1/autocomplete?api_key={$apiKey}&query=" . urlencode($query);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Accept: application/json'
));

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);

?>

These examples illustrate passing the API key as a query parameter. For server-side applications, consider passing the API key in an Authorization header if the API supports it, or ensure strict control over environments where query parameters are exposed. Refer to the US Autocomplete REST API reference for specific requirements and recommendations on parameter placement.

Security best practices

Effective API key management is critical for the security of your application and compliance with data privacy regulations like GDPR, which US Autocomplete adheres to. Implement the following best practices:

  • Always Use HTTPS: Ensure all communication with the US Autocomplete API occurs over HTTPS. This encrypts the data in transit, protecting your API key and sensitive address data from interception. Most modern HTTP client libraries enforce HTTPS by default, but it's important to verify. The Mozilla Developer Network's guide on secure contexts provides further information on secure web communication.
  • Restrict Referrers and IP Addresses: If US Autocomplete's dashboard allows, configure your API key to only accept requests from specific HTTP referrers (for web applications) or IP addresses (for server-side applications). This significantly limits the usability of your key if it is compromised.
  • Do Not Embed API Keys Directly in Client-Side Code: Avoid hardcoding API keys directly into front-end JavaScript, mobile apps, or other publicly accessible client-side code. If a key is exposed, it can be easily extracted and misused. Instead, use a backend proxy server to make API calls, or use environment variables for server-side applications.
  • Use Environment Variables for Server-Side Keys: For applications running on a server, store your API key in environment variables rather than directly in your codebase. This prevents the key from being committed to version control systems like Git.
  • Implement Rate Limiting and Monitoring: Monitor your API usage patterns for any unusual spikes or activity that might indicate a compromised key. Implement rate limiting in your application to prevent abuse, even if the API key is exposed.
  • Rotate API Keys Regularly: Periodically generate new API keys and revoke old ones. This minimizes the window of opportunity for a compromised key to be exploited.
  • Principle of Least Privilege: If US Autocomplete offers different types of API keys or granular permissions, use the key with the minimum necessary privileges for your application's function.
  • Secure Your Development Environment: Ensure that your development machines and build systems are secure to prevent unauthorized access to your API keys during the development process.

By adhering to these practices, developers can significantly reduce the risk of unauthorized access and ensure the secure and reliable operation of applications integrating with the US Autocomplete API.