Guides & Cookbooks

Step-by-Step Guides

Learn how to optimize LLM costs, build RAG systems, create multi-agent chats, and more.

Cost Optimization5 min read

How to Reduce LLM Cost by up to 78%

Step-by-step guide to cutting your LLM costs with verified savings

1. Identify High-Cost Operations

Find where you're spending the most tokens

// Analyze your token usage
const usage = await client.estimateTokens(prompt, { mode: "medium" });
console.log(`Current cost: ${usage.original_tokens} tokens`);

2. Apply Compression

Use balanced mode for optimal savings

const result = await client.optimize(prompt, {
  mode: "balanced",  // Best balance of savings and quality
  format: "auto"
});

3. Compress History

Reduce chat history token usage

const compressed = await client.compressHistory(
  messages,
  currentInput,
  { mode: "balanced" }
);

4. Monitor Savings

Track your cost reduction

console.log(`Saved ${result.tokensSaved} tokens`);
console.log(`Cost reduction: ${result.compression}%`);