# The Minekube API

> The Minekube API is one HTTP API for every network - the registry of keys, networks, labels and status, accounts, trust rules, versions and deployments, and every network as an OpenID Connect issuer - a Cloudflare Worker with Durable Objects at api.minekube.com, or on your own machine.

> **Preview: Connect in the Minekube plugin:**
> This page describes networks in the Minekube plugin, the next generation of Connect. Today's Connect plugin and its `<endpoint>.play.minekube.net` addresses are described in the [Connect docs](https://minekube.com/guide/) and keep working. [Networks in the Minekube plugin](https://minekube.com/guide/networks/) compares the two.

The Minekube API is one API for every network. Relays, connectors and the `mk` CLI all call it, and it is not in the path of a player's bytes. Minekube runs it at `api.minekube.com`, during the preview at `api.staging.minekube.com`; `mk api` runs the same code on your machine, and you can [host it yourself](https://minekube.com/guide/networks/self-host).

Its areas are paths under one host: a network's instances, its versions and deployments, accounts, and identity, with each network's issuer under `/n/<network>`.

## The registry

The part of the API that knows who is who is the registry. It says which key belongs to which [network](https://minekube.com/guide/networks/concepts/network) and what labels and status each [instance](https://minekube.com/guide/networks/concepts/instance) has. Around it, the API keeps which [account](https://minekube.com/guide/networks/concepts/account) owns a network and which version runs on which instances.

## What it holds

| What | Kept in |
| --- | --- |
| Every key and the network it belongs to, pending claim codes, invites and the relays | One directory object |
| A network's instances with their labels, load and home relay, its owner, trust rules, versions and deployments | One object per network |
| Accounts, login codes and sessions | One accounts object |
| The bundles of every version, by their hash | Object storage, readable only by the network's members |

The API is a Cloudflare Worker, and each of these objects is a Durable Object. The directory and the network objects are the registry. A request goes from the Worker to exactly one object; no object calls another in a player's path.

## Who may ask what

The API answers every caller according to who it is, and nobody shows a static token.

- **Instances** sign each request with their key, and see only their own network.
- **Relays** show a short-lived token from an issuer the API's operators trust, and may look up routes.
- **Accounts** show their session's access token, and manage the networks they own.
- **Admins** show a short-lived token from a trusted issuer, and manage every network. On Minekube's API, that is Minekube; on an API you [host yourself](https://minekube.com/guide/networks/self-host), it is you.
- **Anyone** may read a network's OpenID Connect discovery document and key set.

## Why one API, and why on Cloudflare

Identity and the network boundary must have one answer that every relay and instance agrees on. An API that every part trusts gives that answer. Durable Objects hold each network's state in one place with transactions, keep the control channels of idle instances open at almost no cost, and need no servers of Minekube's own.

When the API is unreachable, relays serve joins from the answers they cached, and every instance keeps running the bundles it already has.

## One schema for every language

What the API says to connectors and relays is declared once, as an Effect Schema. The Rust types of the connector and relay are generated from it, and CI fails if the two drift apart. The HTTP API is declared once too, and `mk` calls it through a client derived from that declaration.

## What the API is not

- **Not a relay.** It never carries player traffic.
- **Not a policy engine.** It knows who is in which network and what labels they have. What a network does with that is the network's code.

## Built and planned

The API is built, runs on staging, and can run on your own Cloudflare account or locally in workerd. Production at `api.minekube.com`, for networks at `g.minekube.net`, comes next. Planned: tokens for players, a signing key of each network's own, and hostnames and custom domains per network.

## Related

- [Connector, relay and API](https://minekube.com/guide/networks/connectivity#the-minekube-api-on-cloudflare): the API in depth.
- [Self-host the Minekube API and relay](https://minekube.com/guide/networks/self-host): run your own.
