> For the complete documentation index, see [llms.txt](https://klaralabs.gitbook.io/klara-labs-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://klaralabs.gitbook.io/klara-labs-docs/usage-tracking.md).

# Usage Tracking

```python
import requests
import sys

# Set your API key here
api_key = "YOUR_API_KEY"
api_url = "https://api.klaralabs.com/usage"
headers = {"X-API-Key": api_key, "Content-Type": "application/json"}

def check_usage():
    try:
        # Get usage information
        response = requests.get(f"{api_url}", headers=headers)
        
        if response.status_code == 200:
            usage = response.json()
            print("\n===== Klara Labs API Usage =====")
            print(f"🔑 API Key: Valid")
            print(f"📊 Total requests: {usage['total_requests']}")
            
            # Check if credits information is available
            if usage.get('credits_remaining') is not None:
                print(f"💰 Credits remaining: {usage['credits_remaining']}")
                # Calculate usage percentage if total credits are available
                if usage.get('total_credits') is not None:
                    used = usage['total_credits'] - usage['credits_remaining']
                    percentage = (used / usage['total_credits']) * 100
                    print(f"📈 Usage: {percentage:.1f}% ({used} of {usage['total_credits']})")
            
            # Print any plan information if available
            if usage.get('plan') is not None:
                print(f"📝 Current plan: {usage['plan']}")
                
            print("===============================")
            return True
        else:
            print(f"\n🔴 Error checking usage: {response.status_code}")
            print(response.text)
            return False
            
    except Exception as e:
        print(f"\n🔴 Error: {str(e)}")
        return False

if __name__ == "__main__":
    check_usage()
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://klaralabs.gitbook.io/klara-labs-docs/usage-tracking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
