# 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.

`GET https://api.getlykia.com/v1/credits`

The 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

**Request**

cURL

```bash
curl https://api.getlykia.com/v1/credits \
  -H "Authorization: Bearer $LYKIA_API_KEY"
```

Python

```python
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"])
```

TypeScript

```typescript
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);
```

Go

```go
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)
}
```

**Response (200)**

```json
{
  "data": {
    "balance": 99.996675,
    "total_usage": 0.003325,
    "reserved": 0.16414,
    "available": 99.832535,
    "billing_mode": "prepaid"
  }
}
```

## Response

- `data` (object)
  - `balance` (number) — The 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](https://www.getlykia.com/en/docs/guides/credits-and-billing#how-the-balance-goes-down)); a refund or payment dispute for credits that were already spent, or BYOK fees, can.
  - `total_usage` (number) — Everything the company has spent from credits so far: the cost of requests paid with credits plus BYOK fees that have been deducted.
  - `reserved` (number) — The 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](https://www.getlykia.com/en/docs/guides/credits-and-billing#reservations).
  - `available` (number) — `balance` minus `reserved`: what new requests can use. A paid request whose prompt and a minimal completion this amount cannot cover gets `402`.
  - `billing_mode` (string) — How the company pays for usage. `prepaid`: requests are paid from this credit balance.

> **Note:** `balance` is the remaining balance, not the total amount topped up so far. To see what a new request can draw on, read `available`.

Topping up, the platform fee and what a request costs: [Credits and billing](https://www.getlykia.com/en/docs/guides/credits-and-billing).
