# API key

> Returns the label, spending limit, usage in the current window and remaining amount of the API key making the request.

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

Returns 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:

**Request**

cURL

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

Python

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

TypeScript

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

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

**Response (200)**

```json
{
  "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

- `data` (object)
  - `label` (string) — The masked key, for example `lyk-v1-ab12…ef90`. The full key is never returned by any endpoint.
  - `limit` (number | null) — The spending limit, or `null` for no limit.
  - `limit_reset` (string) — When the limit resets: `none` (a lifetime limit that never resets), `daily`, `weekly` or `monthly`. Windows start on UTC boundaries.
  - `usage` (number) — What this key has spent in the current window.
  - `limit_remaining` (number | null) — What 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.
  - `company` (object) — The company the key belongs to: `id` and `name`.
  - `project` (object) — The project the key belongs to: `id` and `name`.

> **Note:** Only spending paid with credits counts towards the limit, plus the list-price equivalent of requests made with your own provider keys (BYOK) if the API key is set up that way. Spending is counted when a request finishes; until then, Lykia holds each request's maximum cost against the limit, and `limit_remaining` already subtracts those holds. Spending therefore cannot go past the limit, and a request can fail with `402` before `limit_remaining` reaches zero when what is left cannot cover its prompt and a minimal completion. Limits and windows are covered in [Limits](https://www.getlykia.com/en/docs/guides/limits).
