Home >Backend Development >Golang >Making Beautiful API Keys
Summary: In order to improve the developer experience, AgentStation created the uuidkey
package to encode UUIDs into beautiful and easy-to-read API keys. This package supports UUIDv7 and can decode keys for database sorting and indexing.
Question:
API keys are an important part of a user’s first interaction with AgentStation products. We want keys to be beautiful and easy to use, but there seems to be a lack of standards in the industry. As a developer-focused startup, we invest time and effort into finding the ideal solution.
Most API keys suck:
We have the following requirements for API keys:
However, most API keys lack aesthetics and are often inconsistently formatted random characters that are difficult to read, sort, and identify. We want API keys to be aesthetically pleasing and symmetrical like the good things in life.
IDs we rejected:
Too random, easy to guess, ugly in appearance...all unsatisfactory.
Our solution:
Due to the lack of aesthetics (symmetry) of existing solutions, we created our own approach:
Result:
<code>key, _ := uuidkey.Encode("d1756360-5da0-40df-9926-a76abff5601d") fmt.Println(key) // Output: 38QARV0-1ET0G6Z-2CJD9VA-2ZZAR0X</code>
Our key:
Why choose UUIDv7?
In addition to the advantages of timestamps, UUIDv7 will receive native support in Postgres v18. While it's currently possible to generate UUIDv7 server-side using extensions, native Postgres support would definitely perform better and work well with uuidkey.Encode()
.
In our implementation we currently generate keys at the application layer and store them as UUIDs for sorting and indexing. Once Postgres v18 is released, we will switch to Postgres builds to reduce load on the application layer and achieve better performance.
Why choose Crockford Base32?
We chose Crockford Base32 encoding because it:
Why use dash?
Dash keys are "blocky" and symmetrical. If you gray out the individual characters, they look almost like a barcode. We think this makes it easy to quickly read part of a key to identify it.
The dash does remove the convenient double-click copy functionality, but we think this is a worthwhile trade-off for readability. We don't want users copying and pasting them everywhere, in fact we want them to be handled with care. Ideally, users would only copy a key once when generating it in our dashboard - so we added a copy button to the UI to solve this problem.
uuidkey package:
We open sourced these design choices at github.com/agentstation/uuidkey. If you agree with our aesthetics, reasoning, and symmetry, and would like to have your own beautiful API key, feel free to try our open source project.
uuidkey
The core of the package is to encode a UUID into a readable key format via the Base32-Crockford codec and decode it back to a UUID.
Encoding:
The code snippet has been given in the original text and will not be repeated here.
Decoding:
The code snippet has been given in the original text and will not be repeated here.
The package is designed to work with any UUID that follows the official UUID specification (RFC 4122), but we specifically test and maintain compatibility with the two most popular UUID Go generators:
Installation is easy:
<code>key, _ := uuidkey.Encode("d1756360-5da0-40df-9926-a76abff5601d") fmt.Println(key) // Output: 38QARV0-1ET0G6Z-2CJD9VA-2ZZAR0X</code>
Basic usage:
<code>go get github.com/agentstation/uuidkey</code>
We strive to keep overhead to a minimum:
Performance benchmark test data has been given in the original text and will not be repeated here.
Contribute to uuidkey:
We are committed to maintaining uuidkey
as a reliable open source tool because we use it in production - contributions welcome!
If you find it useful or have suggestions for improvements, we'd love to hear from you in our GitHub issues or Discord community.
Prior technology and the shoulders of giants:
After we released the project, we found a few projects with similar implementations, but still did not meet our criteria for encoding and decoding UUIDs using Go.
Summary:
At AgentStation, we are building a platform that allows AI agents to have their own virtual workstation to run browsers, attend meetings, and execute code. As we scale to thousands of workstations, having sortable, high-performance keys is a practical infrastructure.
But we also believe that developers appreciate the beauty of symmetry as much as we do, even in API keys.
We hope you find uuidkey
both practical and beautiful.
The footnotes have been given in the original text and will not be repeated here.
The above is the detailed content of Making Beautiful API Keys. For more information, please follow other related articles on the PHP Chinese website!