In this video, you priced every turn of Ravi’s thirty-message practice session and watched each request send more input than the one before. In the video’s run, the session cost four times what its first turn suggested.
Key Points
- A long session of similar messages. Ravi’s session in the club’s data has thirty messages. He takes a table, orders, chats with the waiter, and pays. Each message is a sentence or two, about as long as the others.
- Price each turn from its usage. The script from the last lesson gets three additions. It imports
costInCents()fromcost.js, which comes with the starting project. That function estimates a call’s cost in cents from its usage, at your model’s full input and output prices. It counts the turns. After each reply, it prints the turn’s input tokens and cost and adds the cost to a total. It leaves out the replies and prints one line per turn. - The input climbs every turn. In the video’s run, turn 1 sent 162 input tokens for 0.007 cents, and turn 30 sent 4,206 for 0.046 cents.
- The cost climbs more slowly. The input grew about 26 times but the cost under 7 times, because each turn also pays for its reply, which costs more per token and stays about the same size. Your numbers will differ with your provider and its prices, but your input tokens will climb the same way. Your cents may jump around more, as the OpenAI run below shows.
- A turn doesn’t cost only its new message. If every turn cost what the first one did, the session would come to 30 × 0.007 = 0.21 cents. In this run, it came to 0.84 cents, four times that. Its first fifteen turns came to about 0.27 cents, so twice the turns cost about three times as much. As sessions get longer, the bill grows faster than the number of turns.
- Every request carries the whole history. Turn 1’s request carries the instructions and Ravi’s first message. Turn 2’s carries the same, plus the partner’s first reply and Ravi’s second message. Every turn adds two messages, the last reply and the new one, and sends everything before them again. By turn 30, the request carries 59 messages. The provider processes all of them as input, and you pay for every one.
- Discounts don’t stop the growth. Some providers bill input they’ve already seen at a lower price, on their own or when the request asks for it.
costInCents()prices every input token at the full rate, so its figures are estimates, and the provider switches below show where each provider reports cached input. But every turn still sends it all. - The context window is a ceiling. Each model accepts only so many tokens in one request, its context window, and the reply has to fit in it too. It’s far larger than this session, but one that keeps going would eventually fill it.
Every turn sends the whole history as input, so the input grows with the conversation, and over a session, the cost grows with it. To keep both the cost and the size in check, the partner needs a limit.