T

Using TOON with ChatGPT API

Reduce your OpenAI API costs by 30-60% while making your prompts more structured and easier to maintain.

Why Use TOON with ChatGPT?

💰 Significant Cost Savings

ChatGPT pricing is per token. TOON format can reduce token usage by 30-60% compared to JSON, directly cutting your API costs.

📊 Better Structure

Tabular format makes it easier for GPT models to understand and extract data, improving response accuracy.

🔍 Cleaner Prompts

Less visual clutter from brackets and quotes makes your prompts easier to read and maintain.

⚡ Faster Responses

Fewer tokens mean faster processing and quicker responses from the API.

Real Example: Product Data

❌ Before (JSON)

{
  "products": [
    {
      "id": "P001",
      "name": "Laptop Pro",
      "price": 1299.99,
      "stock": 45,
      "category": "Electronics"
    },
    {
      "id": "P002",
      "name": "Wireless Mouse",
      "price": 29.99,
      "stock": 120,
      "category": "Accessories"
    },
    {
      "id": "P003",
      "name": "USB-C Cable",
      "price": 12.99,
      "stock": 300,
      "category": "Accessories"
    }
  ]
}

~475 characters | ~119 tokens

Cost per 1M calls: ~$1,190

✓ After (TOON)

products[3]{id,name,price,stock,category}:
  P001,Laptop Pro,1299.99,45,Electronics
  P002,Wireless Mouse,29.99,120,Accessories
  P003,USB-C Cable,12.99,300,Accessories

~165 characters | ~41 tokens

Cost per 1M calls: ~$410 (Save $780!)

Implementation Guide

Step 1: Install TOON Library

npm install @toon-format/toon

Step 2: Convert Your Data

import { encode } from '@toon-format/toon';

const productData = {
  products: [
    { id: "P001", name: "Laptop Pro", price: 1299.99 },
    { id: "P002", name: "Mouse", price: 29.99 }
  ]
};

const toonData = encode(productData);
console.log(toonData);
// Output: products[2]{id,name,price}:
//   P001,Laptop Pro,1299.99
//   P002,Mouse,29.99

Step 3: Use in ChatGPT Prompt

import OpenAI from 'openai';

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

const prompt = `Analyze these products and suggest pricing optimizations:

${toonData}

Provide recommendations for each product.`;

const completion = await openai.chat.completions.create({
  model: "gpt-4",
  messages: [{ role: "user", content: prompt }]
});

💡 Pro Tips

  • • Use TOON for data-heavy prompts (lists, tables, datasets)
  • • Keep natural language in regular text, convert only structured data
  • • Monitor your token usage with OpenAI's usage dashboard
  • • Test both formats to measure actual savings for your use case
  • • Combine TOON with prompt optimization techniques for maximum savings

Start Converting Today

Try our converter to see how much you can save on your ChatGPT API costs.

Convert to TOON