LightYear
/Docs
DocsAPI ReferenceAPI Authentication

API Authentication

Learn how to authenticate with the LightYear API using Bearer tokens and manage your API keys.

beginner
5 min read
LightYear Docs Team
Updated April 24, 2026
apiauthenticationbearer-tokenapi-key

The LightYear API uses Bearer token authentication. All API requests must include your API key in the Authorization header.

Generate an API Key

  1. Log in to the control panel.
  2. Navigate to Account → API.
  3. Click Generate API Key.
  4. Enter a descriptive label (e.g., terraform-prod).
  5. Click Generate.
  6. Copy the API key — it is only shown once.

[!WARNING] Treat your API key like a password. Never commit it to version control or expose it in client-side code.

Authentication Header

Include your API key in every request:

>_BASH
$curl https://api.lightyear.host/v1/account \
$ -H "Authorization: Bearer YOUR_API_KEY"

Test Your API Key

>_BASH
$curl https://api.lightyear.host/v1/account \
$ -H "Authorization: Bearer YOUR_API_KEY"
OUTPUT
{
  "account": {
    "name": "John Doe",
    "email": "[email protected]",
    "balance": "25.00",
    "pending_charges": "1.23"
  }
}

Store API Keys Securely

>_BASH
$export LIGHTYEAR_API_KEY="YOUR_API_KEY"

Use in scripts:

>_BASH
$curl https://api.lightyear.host/v1/servers \
$ -H "Authorization: Bearer $LIGHTYEAR_API_KEY"

.env Files

INI
LIGHTYEAR_API_KEY=YOUR_API_KEY

Add .env to .gitignore:

>_BASH
$echo ".env" >> .gitignore

API Key Permissions

PermissionDescription
ReadList and view resources
WriteCreate, update, and delete resources
FullAll permissions including billing

Create read-only keys for monitoring tools and full-permission keys only for automation that needs to create/delete resources.

Revoke an API Key

  1. Navigate to Account → API.
  2. Find the key you want to revoke.
  3. Click Delete.

Revoked keys are immediately invalidated.

Was this article helpful?

Your cookie choices for this website

This site uses cookies and related technologies, as described in our privacy policy, for purposes that may include site operation, analytics, and enhanced user experience. You may choose to consent to our use of these technologies, or manage your own preferences. Cookie policy