Use API Keys with Roads API

European Economic Area (EEA) developers If your billing address is in the European Economic Area, effective on 8 July 2025, the Google Maps Platform EEA Terms of Service will apply to your use of the Services. Functionality varies by region.Learn more.

Google Maps Platform products are secured from unauthorized use by restricting API calls to those that provide proper authentication credentials. These credentials are in the form of an API key - a unique alphanumeric string that associates your Google billing account with your project, and with the specific API or SDK.

This guide shows how to create, restrict, and use your API key for Google Maps Platform.

Before you begin

Before you start using theRoads API, you need a project with a billing account and theRoads API enabled. To learn more, seeSet up in Cloud console.

Creating API keys

The API key is a unique identifier that authenticates requests associated with your project for usage and billing purposes. You must have at least one API key associated with your project.

To create an API key:

Console

  1. Go to theGoogle Maps Platform > Credentials page.

    Go to the Credentials page

  2. On theCredentials page, clickCreate credentials > API key.
    TheAPI key created dialog displays your newly created API key.
  3. ClickClose.
    The new API key is listed on theCredentials page underAPI keys.
    (Remember torestrict the API key before using it in production.)

Cloud SDK

gcloudservicesapi-keyscreate\--project"PROJECT"\--display-name"DISPLAY_NAME"

Read more about theGoogle Cloud SDK ,Cloud SDK installation , and the following commands:

Restricting API keys

Google strongly recommends that you restrict your API keys by limiting their usage to those onlyAPIs needed for your application. Restricting API keys adds security to your application byprotecting it from unwarranted requests.You are financially responsible for charges caused by abuse of unrestricted API keys. For more information, seeAPI security best practices.When restricting an API key in the Cloud console,Application restrictions override any APIs enabled underAPI restrictions.Follow best practices by creating a separate API key for each app, and for each platformon which that app is available.

To restrict an API key:

Console

  1. Go to theGoogle Maps Platform > Credentials page.

    Go to the Credentials page

  2. Select the API key that you want to set a restriction on. The API key property page appears.
  3. UnderKey restrictions, set the following restrictions:
    • Application restrictions:
      1. To accept requests from the list of web server IP addresses that you supply, selectIP addresses (web servers, cron jobs, etc.) from the list ofApplication restrictions. Specify one or more IPv4 or IPv6 address, or subnet using CIDR notation. The IP addresses must match the source address the Google Maps Platform servers observe. If you usenetwork address translation (NAT), this would typically correspond to your machine'spublic IP address.
    • API restrictions:
      1. ClickRestrict key.
      2. SelectRoads API fromSelect APIs dropdown. If theRoads API is not listed, you need toenable it.
  4. To finalize your changes, clickSave.

Cloud SDK

List existing keys.

gcloudservicesapi-keyslist--project="PROJECT"

Clear existing restrictions on existing key.

gcloudservicesapi-keysupdate"projects/PROJECT/keys/KEY_ID"\--clear-restrictions

Set new restrictions on existing key.

gcloudservicesapi-keysupdateprojects/PROJECT/locations/global/keys/KEY_ID\--api-target=service=roads.googleapis.com--allowed-ips="IP_ADDRESS"

Read more about theGoogle Cloud SDK ,Cloud SDK installation , and the following commands:

Adding the API key to your request

You must include an API key with everyRoads API request. In the following example, replaceYOUR_API_KEY with your API key.

https://roads.googleapis.com/v1/snapToRoads?path=-35.27801,149.12958|-35.28032,149.12907|-35.28099,149.12929|-35.28144,149.12984|-35.28194,149.13003|-35.28282,149.12956|-35.28302,149.12881|-35.28473,149.12836 &interpolate=true &key=YOUR_API_KEY

HTTPS is required for requests that use an API key.

Note: When using Web Services, all special characters inside the parameters must be URL encoded.URLs must be properly encoded to be valid and are limited to 2048 characters for all web services.Be aware of this limit when constructing your URLs. Different browsers, proxies, andservers may have different URL character limits as well.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-02 UTC.