restrict an API key

Restrict an API key to your server IPs or website

Updated 23 November 2026

If an API key leaks, anyone who has it can use your daily lookups. When you restrict an API key, it only works from the servers or websites you choose, so a leaked key is useless to everyone else. This guide shows how to restrict an API key and which option to use.

Where to restrict an API key

Log in at app.ipzentra.com and open your dashboard. Next to each key under API keys, choose Settings. You can set three kinds of restriction, alone or together.

Option 1: allowed server IPs

Enter the public IP addresses of the servers that call the API, one per line. You can also enter a range in CIDR form, such as 203.0.113.0/24. Requests from any other address are refused with HTTP 403 and the error ip_not_allowed.

This is the strongest way to restrict an API key for server-to-server use, which is how most customers use IPzentra.

Option 2: allowed website domains

If you call the API from JavaScript in the browser, enter the domains of your website, such as example.com. Use *.example.com to cover every subdomain. The API checks the Origin header sent by the browser, and requests from other sites are refused with origin_not_allowed.

Browser code is visible to anyone, so a key used this way can still be copied. Restricting it to your domains stops it working on other websites.

Option 3: an expiry date

Set a date after which the key stops working. This suits keys for a contractor, a test or a short project. After that date, requests return key_expired.

Which way to restrict an API key

  • Your backend calls the API: use allowed server IPs.
  • Your web page calls the API directly: use allowed website domains.
  • Someone needs temporary access: create a separate key with an expiry date.

You can combine options, for example server IPs plus an expiry date. You can have up to three active keys, so give each system its own key and restrict each one to the place it runs.

Test after you restrict an API key

Send a request from an allowed server and check you get a normal result. Then, if you can, send one from somewhere else, such as your laptop, and confirm it returns 403. If your own server is refused, check its public IP address, which can differ from its internal address, for example behind a load balancer or NAT gateway.

If a key has already leaked

Revoke it from the dashboard, create a new key, restrict it and update your application. Revoked keys stop working almost immediately. Then review your usage chart for any traffic you do not recognise.

Learn more in our guide to your first API request, or see the API documentation for every error code. To restrict an API key in a way not covered here, contact support.

Common questions about key restrictions

Can I change restrictions later? Yes. Open Settings next to the key at any time. Changes take effect shortly, and the key itself stays the same, so you do not need to update your code.

What if my server IP changes? Add the new address before you switch servers, then remove the old one once the move is finished. That way requests never fail during the change.

Can I restrict an API key to a country? No. Restrictions are based on your server addresses, website domains and an expiry date. If you need something else, tell us through the contact page.

Do restrictions slow down requests? No. The checks happen in memory and add no noticeable time to a lookup.

How to restrict an API key to server IPs or website domains

Was this article helpful?

Related articles

Still need help?

Our team usually replies within one business day.

Open a support ticketContact us