LessTokens Logo
Getting Started
First Request

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 →

Make Your First Request

Step-by-step guide to sending your first compression request to the LessToken API and understanding the response.

Before You Begin

Make sure you have the following ready:

API Key Created

You need an active API key to authenticate requests

Terminal or HTTP Client

Use cURL, Postman, or your preferred HTTP client

Basic Request

Here's the simplest compression request you can make:

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": "Large language models are powerful but expensive. This API helps reduce costs by compressing prompts intelligently while maintaining semantic meaning and context."
  }'

Replace YOUR_API_KEY

Don't forget to replace YOUR_API_KEY with your actual API key from the dashboard.

Understanding the Response

A successful request returns a JSON response with the compressed text and detailed metrics:

Response (200 OK)
{
  "compressedPrompt": "LLMs powerful but expensive. API reduces costs by compressing prompts intelligently while maintaining semantic meaning & context.",
  "originalTokens": 28,
  "compressedTokens": 19,
  "compressionRatio": 0.32,
  "savingsPercentage": 32.14,
  "processingTimeMs": 45,
  "id": "req_abc123xyz",
  "timestamp": "2025-01-18T14:30:00Z"
}

Original Tokens

28

Input token count

Compressed Tokens

19

Output token count

Tokens Saved

9

Reduction achieved

Savings

32.14%

Compression ratio

Request with Options

You can customize compression behavior with options:

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 here with    extra    spaces and newlines\n\n\n",
    "options": {
      "jsonMinify": true,
      "removeComments": true,
      "compressArrays": false,
      "maxTimeMs": 5000
    }
  }'

Available Options

jsonMinifyboolean

Minify JSON content in the prompt

Default: false

removeCommentsboolean

Remove code comments from prompts

Default: true

compressArraysboolean

Compress large array structures

Default: false

maxTimeMsnumber

Maximum processing time in milliseconds

Default: 10000

Common Errors

401

Unauthorized

Missing or invalid API key. Check that your X-API-Key header is correct.

Solution: Verify your API key in the dashboard and ensure it's not revoked.

400

Bad Request

Invalid request body or missing required fields.

Solution: Ensure the 'prompt' field is present and is a string.

429

Too Many Requests

You've exceeded your rate limit.

Solution: Wait a moment before retrying or upgrade your plan for higher limits.

500

Internal Server Error

Something went wrong on our end.

Solution: Retry the request. If the issue persists, contact support.

Testing Tips

Start Small

Test with short prompts first to understand the compression behavior

Try Different Texts

Test with various content types: code, prose, JSON, etc.

Monitor Metrics

Pay attention to compression ratios and processing times

Next Steps

Great! You've made your first request. Now learn how to integrate this into your applications: