Using JSON for data output from large language models can be significantly more expensive than using CSV due to token costs associated with formatting. Pretty-printed JSON, for instance, can cost 2.6 times more than CSV for the same data, primarily due to indentation and repeated key names. While renaming keys to shorter aliases can reduce costs, it impacts readability. For bulk data extraction tasks, especially with short records, switching to CSV or Tab-Separated Values (TSV) can lead to substantial savings on API calls, though JSON remains preferable for single object outputs or when specific tool-calling features mandate its use. AI
IMPACT Switching from JSON to CSV for bulk data output can significantly reduce LLM API costs, especially for short records.
RANK_REASON The item analyzes the cost implications of using different data formats with LLMs, rather than announcing a new model or product.
- CSV
- csv.DictWriter
- generative pre-trained transformer
- JSON
- json.dumps
- json.loads
- o200k_base
- OpenAI
- tiktoken
AI-generated summary · Google Gemini · from 1 sources. How we write summaries →