Skip to content
AITermsLab
–points–day streak

What's the difference between a public key and a secret key?

Many services give you two keys: a public key that's safe in code anyone can see, and a powerful secret key that must stay hidden on a server.

Last updated

In real life

Like a shop's letterbox and its safe: anyone can use the letterbox, but only staff should ever have the key to the safe.

Try it yourself

The demo gives you two keys from a made-up maps service. Put each one in the browser code, which every visitor can read, or in hidden server settings. Then view the page as a visitor: a secret key in the browser code can be copied by anyone.

Your made-up maps service gave you two keys. Where does each go?

  • Public key: public_7f3a91c2

    Can only show maps on your site

  • Secret key: secret_9c1e44b8d0

    Full control of your account and billing

Anything in browser code can be read by anyone who opens the page. Public keys are built for that. Secret keys must stay on the server.

Public and secret keys vs API key

An API key is any key a program uses to call a service. Many services split it in two: a limited public key for browsers, and a powerful secret key for servers.

What is an API key?

Common questions

Is a public key really safe to show?

Yes, if the service is set up so it can only do safe, limited things. This site's sign-up form uses a public key that can only add an email address, nothing else.

What if my secret key leaks?

Revoke it in the service's dashboard straight away, create a new one, and check what it was used for. Treat it like a lost house key: change the lock.

Where you will use this

Quick check: Public and secret keys

Question 1 of 3

Where can a public key safely go?

Where can a public key safely go?