#Too many tokens being used
1 messages · Page 1 of 1 (latest)
Hi @north marsh. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, your understanding is correct. When using the chat models of OpenAI, such as gpt-3.5-turbo, each message passed to the API consumes the number of tokens in the content, role, and other fields, plus a few extra for behind-the-scenes formatting. This includes the system message, user message, and assistant message. Therefore, if your system message is around 1k tokens, it will be counted towards the total tokens used in each API call.
To reduce the number of tokens used, you could consider the following strategies:
-
Condense your system message: If possible, try to make your system message more concise without losing the necessary information. This could significantly reduce the number of tokens used in each API call.
-
Break the text into smaller pieces: If your conversation has too many tokens to fit within a model’s maximum limit, you might need to truncate, omit, or otherwise shrink your text until it fits. However, be aware that if a message is removed from the messages input, the model will lose all knowledge of it.
-
Use OpenAI’s tiktoken Python library: This library can help you see how many tokens are in a text string without making an API call, which could assist you in managing your token usage more effectively.
Remember, both input and output tokens count toward these quantities. For example, if your API call used 10 tokens in the message input and you received 20 tokens in the message output, you would be billed for 30 tokens.
For more information, you can refer to the following sources:
- OpenAI Community Post (https://community.openai.com/t/595970)
- OpenAI Platform Guide (https://platform.openai.com/docs/guides/text-generation)
- OpenAI Help Article (https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them#h_051eb08805)