Skip to content

Random API Key Generator - Secure, 8-128 Chars

A free, browser-based tool that generates cryptographically secure random API keys of 8 to 128 characters, using the Web Crypto API. No data leaves the browser.

API Key Generator

Keys are generated locally in your browser with the Web Crypto API (a CSPRNG), using unbiased rejection sampling. Nothing is sent to any server.
Loading calculator...
📚

Documentation

A random API key generator is a tool that creates a random string of letters and numbers for use as a password-like code between two computer programs. This one runs entirely inside the visitor's web browser. It lets the user pick a key length from 8 to 128 characters, with 32 characters set as the default.

What Is an API Key?

An API key is a string of characters that a program sends along with a request to prove it is allowed to use a service. A web server checks the key before it answers the request. Unlike a username and password, an API key usually identifies an application or a script, not a person.

Keys work best when no one can guess them. A generator that uses true randomness avoids the patterns that appear in keys typed by a person, such as repeated characters or short, memorable words.

How This Generator Works

The tool builds each key from a fixed set of 62 characters: the 26 uppercase letters A–Z, the 26 lowercase letters a–z, and the 10 digits 0–9. For a key of length n, it picks n characters from that set, one at a time.

Each character comes from the browser's Web Crypto API, specifically crypto.getRandomValues(). This is a cryptographically secure random number generator (CSPRNG), unlike JavaScript's Math.random(), which is predictable and unsuitable for security-sensitive values.

To pick a fair character from 62 options out of a random byte (256 possible values), the generator cannot simply use byte % 62. Because 256 does not divide evenly by 62, a plain modulo would make the first few characters in the set slightly more likely than the rest. The tool avoids this with rejection sampling: it discards any random byte that would cause that bias and draws a new one instead. Every character in the final key therefore has an equal, unbiased chance of appearing at each position.

How to Generate an API Key

  1. Enter a key length between 8 and 128 characters, or keep the default of 32.
  2. Click "Generate." The key appears in a text box, built entirely in the browser.
  3. Click "Copy" to copy the key to the clipboard. Some browsers ask for permission the first time.
  4. Click "Regenerate" to produce a new key with the same length, or "Reset" to return to the default length.

No key is sent to a server, logged, or stored. The generation happens with local JavaScript code, so a check of the browser's network activity during generation shows no outgoing requests.

How to Calculate the Number of Possible Keys

The number of different keys a given length can produce follows a simple formula:

Possible keys = (charset size) ^ (key length)

The charset size is always 62 for this tool. For the default length of 32:

Possible keys = 62³² ≈ 2.27 × 10⁵⁷

This number is also expressed as entropy, measured in bits, using the formula:

Entropy (bits) = key length × log₂(charset size)

For a 32-character key: 32 × log₂(62) ≈ 32 × 5.95 ≈ 190.5 bits.

Worked Example: Time to Try Every Key

Suppose an attacker could test one billion (10⁹) keys every second, an unrealistically fast rate for any real system. Trying every possible 32-character key would take:

2.27 × 10⁵⁷ ÷ 10⁹ = 2.27 × 10⁴⁸ seconds ≈ 7.2 × 10⁴⁰ years

For comparison, the universe is about 1.4 × 10¹⁰ years old. A brute-force search through every possible key is not a practical threat at this length. Shorter keys shrink this number fast: an 8-character key has only 62⁸ ≈ 2.18 × 10¹⁴ possible values, which a fast computer could search through in a matter of days.

Why Applications Use API Keys

API keys give a service a simple way to tell which application is making a request. This matters for a few reasons.

Authentication. A server can reject requests that arrive without a valid key, blocking most casual misuse.

Usage tracking. Because each client can hold a different key, a service can measure how much each one is using, and apply separate rate limits per key.

Revocation. A single compromised key can be turned off without affecting any other client, since each key is independent.

API keys are simpler to implement than OAuth 2.0, an authentication standard built around temporary, automatically renewed tokens. OAuth suits public-facing services that handle personal user data. API keys are common for internal tools, scripts, and service-to-service calls, where a long-lived credential is acceptable.

Security Practices for API Keys

A few practices reduce the risk of a leaked key:

  • Do not store keys in source code. Version control history is hard to erase, and public repositories are scanned constantly for exposed credentials. Store keys in environment variables or a secrets manager instead.
  • Rotate keys periodically. Replacing a key every few months limits how long a leaked key stays useful to an attacker.
  • Grant the minimum access a key needs. A key that only reads data should not also be able to write or delete it.
  • Watch for unusual activity, such as a sudden spike in requests from one key.

Limitations

This tool does not keep a record of keys it has generated, so it cannot guarantee that a key has never been produced before. The chance of two random 32-character keys matching is about 1 in 2.27 × 10⁵⁷, which is close enough to zero for ordinary use, but systems that need an absolute guarantee of uniqueness, such as database primary keys, should check new values against existing ones on a server.

The character set is fixed at uppercase letters, lowercase letters, and digits. It does not include symbols such as ! or -, which keeps keys safe to paste into most URLs, headers, and configuration files without escaping.

Frequently Asked Questions

What is an API key generator?

It is a tool that produces random strings for use as authentication credentials between software applications. This one creates keys of 8 to 128 characters, drawn from 62 possible characters, using the browser's cryptographically secure random number generator.

Is a key from this tool secure enough for production use?

The randomness itself is cryptographically secure. Overall security also depends on how the key is stored and transmitted afterward: never commit it to source control, always send it over HTTPS, and rotate it on a regular schedule.

What length should I choose?

The default of 32 characters gives about 2.27 × 10⁵⁷ possible combinations, far more than any realistic brute-force attempt could search. Shorter keys, such as 16 characters, may suit low-risk internal tools. Very long keys add little extra protection but are harder to store and paste.

Can I set a custom length?

Yes. The length field accepts any whole number from 8 to 128. The character set itself (A–Z, a–z, 0–9) stays fixed.

Does the tool store or transmit the keys it generates?

No. Every key is generated with local JavaScript in the browser. Nothing is sent to a server, logged, or saved.

What is the difference between an API key and an OAuth token?

An API key is a long-lived credential that stays valid until someone revokes it. An OAuth token expires automatically after a set time and can be refreshed without direct user involvement. OAuth fits public services handling personal data; API keys fit simpler, internal, or development use.

Which browsers does this tool support?

Any modern browser with the Web Crypto API works: Chrome 60 and later, Firefox 55 and later, Safari 10 and later, Edge 79 and later, and Opera 47 and later.