API
This document only covers v2 of the Unkey API. The v1 API on Cloudflare Workers is deprecated and will be removed in the future. It was too hard to selfhost anyways.
Our API runs on AWS containers, in multiple regions behind a global load balancer to ensure high availability and low latency.
The source code is available on GitHub.
Quickstart
To get started, you need go1.24+ installed on your machine.
Configuration
The API server requires a json configuration file to be passed as an argument to the binary.
You can use ${SOME_NAME}
as placeholder in your config file and it will be replaced by the value of the environment variable SOME_NAME
.
The most up to date json schema can be found here: https://raw.githubusercontent.com/unkeyed/unkey/refs/heads/main/go/schema.json
Most IDEs support JSON schema validation if you put it in your config file.
You can check out our own configuration files on GitHub.
General Configuration
These settings define the fundamental properties of the server.
platform
string
The platform this server is running on ("aws", "gcp", ...).
Most metrics include this information to help with troubleshooting and monitoring.
image
string
The container image and version identifier for this instance.
httpPort
number
The HTTP port where the server will listen for incoming connections. Defaults to 7070.
region
string
Geographic region identifier where this server is deployed (e.g., "us-west-1")
Heartbeat Configuration
The API can send heartbeats to a destination to monitor its health.
heartbeat
object
Configuration for server health check reporting. Contains the following properties:
url
Requiredstring
Endpoint URL where heartbeat signals will be sent (e.g., "http://monitor.example.com/heartbeat")
interval
Requirednumber
Time between heartbeat signals in seconds (e.g., 30 for checking every half minute)
Cluster Configuration
Settings for cluster operation when running multiple server instances together.
cluster
object
Settings for multi-server cluster operations:
nodeId
string
Unique identifier for this node in the cluster (e.g., "node-1", "server-east-1")
If omitted, a random id will be generated.
advertiseAddr
string
Network address other nodes will use to contact this node (e.g., "10.0.0.1", "node1.example.com")
rpcPort
string
Port used for internal cluster communication via RPC. Defaults to "7071".
gossipPort
string
Port used for cluster membership and state dissemination. Defaults to "7072".
discovery
object
Configuration for how cluster nodes discover each other on startup.
Only one discovery method can be configured at a time.
static
object
Fixed list of cluster nodes for stable environments:
addrs
Requiredstring[]
List of node addresses to connect to (e.g., ["node1:7071", "node2:7071"])
redis
object
Redis-based dynamic discovery for flexible environments. All nodes will send heartbeats to the Redis server with their address.
url
Requiredstring
Redis connection string (e.g., "redis://redis.example.com:6379")
Logging and Monitoring
Configuration for observability and debugging capabilities.
logs
object
Logging configuration settings:
color
boolean
Enable colored output in log messages for better readability
Database Configuration
Database connection settings for the server's data storage.
database
Requiredobject
Database connection configuration:
primary
Requiredstring
Primary database connection string for read and write operations (e.g., "postgresql://user:pass@localhost:5432/dbname")
readonlyReplica
string
Optional read-only database replica for scaling read operations
ClickHouse Configuration
clickhouse
object
ClickHouse integration for metrics and logging:
url
Requiredstring
ClickHouse server connection string (e.g., "http://clickhouse:8123")
Last updated on