Copied from upstream: openai/openai-cookbook#2140
Original author: @wilfredjonathanjames
Originally created: 2025-09-14
It's easy to find methods to count tokens in messages, but so far I've had no luck finding guidance on the additional token count incurred when attaching a structured output schema.
Pure JSON string encoding the schema gives roughly twice as many tokens as actual usage, sometimes more, sometimes less, so I'm clearly missing something important.
It's easy to find methods to count tokens in messages, but so far I've had no luck finding guidance on the additional token count incurred when attaching a structured output schema.
Pure JSON string encoding the schema gives roughly twice as many tokens as actual usage, sometimes more, sometimes less, so I'm clearly missing something important.