LocalityAPI
Get API Key

Authentication

LocalityAPI uses API key authentication. Pass your key in the X-API-Key header on every request.

Get your free API key at localityapi.com — no credit card required.

Making Authenticated Requests

Include your API key in all requests using the X-API-Key header:

bash
curl "https://api.localityapi.com/v1/search?q=Dubai&country=AE" \
  -H "X-API-Key: lapi_your_key_here"
Security Warning: Never expose your API key in client-side JavaScript or public GitHub repositories. Always use environment variables and make API calls from your backend server.

Code Examples

Here's how to authenticate requests in different languages:

// Using fetch
const response = await fetch(
  'https://api.localityapi.com/v1/search?q=Dubai&country=AE',
  {
    headers: {
      'X-API-Key': process.env.LOCALITY_API_KEY
    }
  }
);

const data = await response.json();
console.log(data);

// Using axios
import axios from 'axios';

const client = axios.create({
  baseURL: 'https://api.localityapi.com/v1',
  headers: {
    'X-API-Key': process.env.LOCALITY_API_KEY
  }
});

const { data } = await client.get('/search', {
  params: { q: 'Dubai', country: 'AE' }
});

Environment Variables

We recommend storing your API key in environment variables:

bash
# .env file
LOCALITY_API_KEY=lapi_your_key_here

Then access it in your code using your language's environment variable methods.

Authentication Errors

If authentication fails, you will receive one of the following errors:

401Unauthorized

Missing or invalid API key. Make sure you include the X-API-Key header.

json
{
  "error": "unauthorized",
  "message": "Invalid API key. Get your key at localityapi.com"
}