LessTokens Logo
Api Reference
Authentication

Documentation

Getting Started

  • Overview
  • Account Setup
  • First API Key
  • First Request
  • Understanding Metrics

API Reference

  • Overview
  • Authentication
  • Compressionnew
  • MCP Servernew
  • Errors

Integrations

  • Node.js / TypeScript
  • Python
  • cURL

Resources

  • Best Practices

Need help?

Join our community or contact support for assistance.

Contact Support →

Authentication

Learn how to authenticate your API requests using API keys. All requests must include a valid API key in the X-API-Key header.

Authentication Method

API Key Authentication

All API requests must include your API key in the X-API-Key header. This identifies your account and tracks your usage.

Example Request
curl -X POST https://lesstokens.hive-hub.ai/api/compress \
  -H "X-API-Key: lsk_live_1234567890abcdef..." \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Your text here"}'

API Key Format

LessToken API keys follow a specific format to identify the key type and environment:

lsk_test_...

Test Keys

For development and testing environments

Example:

lsk_test_1234567890abcdef1234567890abcdef
  • No charges applied
  • Rate limits apply
  • Full API access
  • Separate usage tracking
lsk_live_...

Live Keys

For production environments

Example:

lsk_live_1234567890abcdef1234567890abcdef
  • All requests billed
  • Higher rate limits
  • Production-ready
  • Real-time analytics

Never Expose Live Keys

Always use environment variables to store API keys. Never commit keys to version control or expose them in client-side code.

Making Authenticated Requests

Using cURL

terminal
curl -X POST https://lesstokens.hive-hub.ai/api/compress \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Your text to compress",
    "options": {
      "jsonMinify": true,
      "removeComments": true
    }
  }'

Using JavaScript/TypeScript

api-client.ts
import axios from 'axios';

const apiKey = process.env.LESSTOKEN_API_KEY;
const baseUrl = 'https://lesstokens.hive-hub.ai';

async function compressText(prompt: string) {
  const response = await axios.post(
    `${baseUrl}/compress`,
    {
      prompt,
      options: {
        jsonMinify: true,
        removeComments: true,
      },
    },
    {
      headers: {
        'X-API-Key': apiKey,
        'Content-Type': 'application/json',
      },
    }
  );

  return response.data;
}

Using Python

api_client.py
import os
import requests

api_key = os.getenv('LESSTOKEN_API_KEY')
base_url = 'https://lesstokens.hive-hub.ai'

def compress_text(prompt: str):
    response = requests.post(
        f'{base_url}/compress',
        headers={
            'X-API-Key': api_key,
            'Content-Type': 'application/json'
        },
        json={
            'prompt': prompt,
            'options': {
                'jsonMinify': True,
                'removeComments': True
            }
        }
    )
    
    return response.json()

Authentication Errors

401

Unauthorized

Missing or invalid API key

Common Causes:

  • No X-API-Key header provided
  • Invalid API key format
  • Revoked or expired API key
  • API key does not exist

Solution:

Verify your API key in the dashboard and ensure it's included in the X-API-Key header.

Example Response:

{
  "error": "Unauthorized",
  "message": "Invalid or missing API key",
  "code": "AUTHENTICATION_REQUIRED"
}
403

Forbidden

Valid key but insufficient permissions

Common Causes:

  • API key lacks required permissions
  • Rate limit exceeded
  • Account suspended
  • IP address not whitelisted

Solution:

Check your account status and rate limits in the dashboard. Contact support if needed.

Example Response:

{
  "error": "Forbidden",
  "message": "Rate limit exceeded",
  "code": "RATE_LIMIT_EXCEEDED"
}

Security Best Practices

Use Environment Variables

Store API keys in environment variables, never hardcode them in your source code.

Do:

  • ✓Use .env files for local development
  • ✓Configure secrets in your deployment platform
  • ✓Add .env to .gitignore

Don't:

  • ✗Commit API keys to version control
  • ✗Hardcode keys in source files
  • ✗Share keys in chat/email

Rotate Keys Regularly

Generate new API keys periodically and revoke old ones to minimize security risks.

Do:

  • ✓Rotate keys every 90 days
  • ✓Create new keys before revoking old ones
  • ✓Monitor key usage for anomalies

Don't:

  • ✗Use the same key for all environments
  • ✗Share keys across teams
  • ✗Ignore suspicious activity

Use Test Keys in Development

Always use test keys (lsk_test_) during development to avoid accidental charges.

Do:

  • ✓Use test keys in development/staging
  • ✓Switch to live keys only in production
  • ✓Document which keys are used where

Don't:

  • ✗Use live keys in development
  • ✗Mix test and live keys
  • ✗Test in production with live keys

Rate Limiting

API requests are rate-limited to ensure fair usage and system stability. Rate limits are applied per API key.

Free Tier

100 requests/hour

For testing and small projects

Pro Tier

1,000 requests/hour

For production applications

Enterprise

Custom limits

For high-volume usage

Rate Limit Headers

All API responses include rate limit headers: X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset.

Next Steps

Now that you understand authentication, explore the API endpoints: