Skip to main content

Go

Add API key authentication to your Go application using the Unkey Go SDK. Verify keys on each request to protect your API endpoints.
1 min read

This guide shows how to add API key verification to your Go applications using the official Unkey Go SDK.

Prerequisites#

  • Go 1.21 or higher
  • An Unkey account (free at unkey.com)

1. Install the SDK#

2. Set up your Unkey credentials#

  1. Create a keyspace in the Unkey Dashboard
  2. Create a root key at Settings → Root Keys
  3. Copy your API ID (looks like api_xxxx)

Set your root key as an environment variable:

3. Create middleware#

Here's how to verify API keys with standard library net/http:

4. Run your server#

Test it with a valid API key:

Using with Gin#

If you're using the Gin framework:

Using with Echo#

For the Echo framework:

What's next?#