API Documentation

API Reference

The CrimeLayer API base URL is https://api.crimelayer.com. All endpoints require an X-API-Key header. See Authentication for details.

GET /v1/safety/:city

Returns a safety score and crime statistics for a specific California city.

Parameters

Parameter In Required Description
city path Yes City name. URL-encode spaces as + or %20 (e.g. San+Diego).

Example Request

curl https://api.crimelayer.com/v1/safety/Irvine \
  -H "X-API-Key: cl_live_your_key_here"

Example Response

{
  "found": true,
  "data": {
    "city": "Irvine",
    "county": "Orange County",
    "population": 316132,
    "crime_rate_per_1k": 16.4,
    "safety_score": 83,
    "grade": "A",
    "grade_label": "Very Safe",
    "stars": 5,
    "grade_color": "#16a34a",
    "data_year": 2023,
    "state_average_rate": 30.4,
    "comparison": "46% below CA average"
  }
}

When a city is not found, found is false and data is null:

{ "found": false, "data": null }

GET /v1/safety/county/:name

Returns a safety summary for a California county. Useful as a fallback when a specific city isn't in the database.

Parameters

Parameter In Required Description
name path Yes County name. The "County" suffix is optional — Orange and Orange+County both work.

Example Request

curl https://api.crimelayer.com/v1/safety/county/Orange \
  -H "X-API-Key: cl_live_your_key_here"

Example Response

{
  "found": true,
  "data": {
    "county": "Orange County",
    "state": "California",
    "population": 3186989,
    "crime_rate_per_1k": 18.2,
    "safety_score": 79,
    "grade": "B+",
    "grade_label": "Safe",
    "data_year": 2023,
    "state_average_rate": 30.4,
    "comparison": "40% below CA average",
    "cities_covered": 34
  }
}

POST /v1/safety/batch

Look up multiple cities in a single request. Ideal for populating tables, maps, or comparison views.

Request Body

Field Type Required Description
cities string[] Yes Array of city name strings. No need to URL-encode — use plain names in JSON. Limit: 25 (Free), 50 (Pro), 100 (Enterprise).

Example Request

curl -X POST https://api.crimelayer.com/v1/safety/batch \
  -H "X-API-Key: cl_live_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{"cities": ["Irvine", "Oakland", "San Francisco"]}'

Example Response

{
  "results": [
    {
      "city": "Irvine",
      "found": true,
      "data": {
        "safety_score": 83,
        "grade": "A",
        "grade_label": "Very Safe",
        "crime_rate_per_1k": 16.4
      }
    },
    {
      "city": "Oakland",
      "found": true,
      "data": {
        "safety_score": 22,
        "grade": "D",
        "grade_label": "High Crime",
        "crime_rate_per_1k": 74.1
      }
    },
    {
      "city": "San Francisco",
      "found": true,
      "data": {
        "safety_score": 35,
        "grade": "C-",
        "grade_label": "Below Average",
        "crime_rate_per_1k": 58.3
      }
    }
  ]
}

GET /v1/stats

Returns metadata about the CrimeLayer dataset — useful for displaying data freshness or coverage badges in your app.

Parameters

None. This endpoint requires authentication but takes no query parameters.

Example Request

curl https://api.crimelayer.com/v1/stats \
  -H "X-API-Key: cl_live_your_key_here"

Example Response

{
  "cities": 457,
  "counties": 58,
  "data_year": 2023,
  "last_updated": "2024-09-15T00:00:00Z",
  "grade_distribution": {
    "A": 89,
    "B": 142,
    "C": 118,
    "D": 73,
    "F": 35
  }
}