API key
Returns the label, spending limit, usage in the current window and remaining amount of the API key making the request.
Markdown/v1/keyReturns information about the key in the Authorization header, and only that key. A typical use is checking that a key has enough spending room left before you start a long batch job. All amounts are USD decimals.
Example
This example stops if less than 1 USD is left in the current window:
curl https://api.getlykia.com/v1/key \
-H "Authorization: Bearer $LYKIA_API_KEY"import os
import requests
response = requests.get(
"https://api.getlykia.com/v1/key",
headers={"Authorization": f"Bearer {os.environ['LYKIA_API_KEY']}"},
timeout=30,
)
response.raise_for_status()
key = response.json()["data"]
if key["limit_remaining"] is not None and key["limit_remaining"] < 1:
raise SystemExit(f"Key {key['label']} has less than $1 left in this window.")
print(key["label"], "used", key["usage"], "of", key["limit"])const response = await fetch("https://api.getlykia.com/v1/key", {
headers: { Authorization: `Bearer ${process.env.LYKIA_API_KEY}` },
});
if (!response.ok) {
throw new Error(`Lykia returned ${response.status}: ${await response.text()}`);
}
const { data: key } = await response.json();
if (key.limit_remaining !== null && key.limit_remaining < 1) {
throw new Error(`Key ${key.label} has less than $1 left in this window.`);
}
console.log(key.label, "used", key.usage, "of", key.limit);package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
func main() {
req, err := http.NewRequest(http.MethodGet, "https://api.getlykia.com/v1/key", nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("LYKIA_API_KEY"))
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
panic(fmt.Sprintf("Lykia returned %d: %s", resp.StatusCode, body))
}
var result struct {
Data struct {
Label string `json:"label"`
Limit *float64 `json:"limit"`
LimitReset string `json:"limit_reset"`
Usage float64 `json:"usage"`
LimitRemaining *float64 `json:"limit_remaining"`
} `json:"data"`
}
if err := json.Unmarshal(body, &result); err != nil {
panic(err)
}
key := result.Data
if key.LimitRemaining != nil && *key.LimitRemaining < 1 {
fmt.Printf("key %s has less than $1 left in this window\n", key.Label)
os.Exit(1)
}
fmt.Println(key.Label, "used", key.Usage, "reset:", key.LimitReset)
}{
"data": {
"label": "lyk-v1-ab12…ef90",
"limit": 50,
"limit_reset": "monthly",
"usage": 18.47172,
"limit_remaining": 31.52828,
"company": {
"id": "6b0472819bcb6b3a1239379b",
"name": "Acme Products"
},
"project": {
"id": "6b0472819bcb6b3a1239379d",
"name": "Support bot"
}
}
}Response
dataobjectlabelstringThe masked key, for example lyk-v1-ab12…ef90. The full key is never returned by any endpoint.
limitnumber | nullThe spending limit, or null for no limit.
limit_resetstringWhen the limit resets: none (a lifetime limit that never resets), daily, weekly or monthly. Windows start on UTC boundaries.
usagenumberWhat this key has spent in the current window.
limit_remainingnumber | nullWhat a new request can still use in the current window: the limit minus the window's usage minus what this key's requests in flight have reserved (0 once nothing is left), or null when there is no limit.
companyobjectThe company the key belongs to: id and name.
projectobjectThe project the key belongs to: id and name.