Credits
Returns your company's credit balance, its total usage to date, and the amounts reserved for requests in flight and available for new ones, in USD.
Markdown/v1/creditsThe credit balance lives at company level, and every project in the company spends from it. Whichever project's key you call this endpoint with, it returns the company's balance and total usage. Amounts are USD decimals.
Example
curl https://api.getlykia.com/v1/credits \
-H "Authorization: Bearer $LYKIA_API_KEY"import os
import requests
response = requests.get(
"https://api.getlykia.com/v1/credits",
headers={"Authorization": f"Bearer {os.environ['LYKIA_API_KEY']}"},
timeout=30,
)
response.raise_for_status()
credits = response.json()["data"]
print("balance (USD):", credits["balance"])
print("total usage (USD):", credits["total_usage"])
print("reserved (USD):", credits["reserved"])
print("available (USD):", credits["available"])const response = await fetch("https://api.getlykia.com/v1/credits", {
headers: { Authorization: `Bearer ${process.env.LYKIA_API_KEY}` },
});
if (!response.ok) {
throw new Error(`Lykia returned ${response.status}: ${await response.text()}`);
}
const { data: credits } = await response.json();
console.log("balance (USD):", credits.balance);
console.log("total usage (USD):", credits.total_usage);
console.log("reserved (USD):", credits.reserved);
console.log("available (USD):", credits.available);package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
func main() {
req, err := http.NewRequest(http.MethodGet, "https://api.getlykia.com/v1/credits", 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 {
Balance float64 `json:"balance"`
TotalUsage float64 `json:"total_usage"`
Reserved float64 `json:"reserved"`
Available float64 `json:"available"`
} `json:"data"`
}
if err := json.Unmarshal(body, &result); err != nil {
panic(err)
}
fmt.Println("balance (USD):", result.Data.Balance)
fmt.Println("total usage (USD):", result.Data.TotalUsage)
fmt.Println("reserved (USD):", result.Data.Reserved)
fmt.Println("available (USD):", result.Data.Available)
}{
"data": {
"balance": 99.996675,
"total_usage": 0.003325,
"reserved": 0.16414,
"available": 99.832535,
"billing_mode": "prepaid"
}
}Response
dataobjectbalancenumberThe company's credit balance. The cost of a request is deducted when it finishes. Usage does not take the balance below zero (see How the balance goes down); a refund or payment dispute for credits that were already spent, or BYOK fees, can.
total_usagenumberEverything the company has spent from credits so far: the cost of requests paid with credits plus BYOK fees that have been deducted.
reservednumberThe amount set aside for requests in flight. Each request reserves the most it can cost before it is sent, and the reservation is released when it finishes. See Reservations.
availablenumberbalance minus reserved: what new requests can use. A paid request whose prompt and a minimal completion this amount cannot cover gets 402.
billing_modestringHow the company pays for usage. prepaid: requests are paid from this credit balance.
Topping up, the platform fee and what a request costs: Credits and billing.