# Token Optimization for Assistants API - Excesive token count

**URL:** <https://community.openai.com/t/token-optimization-for-assistants-api-excesive-token-count/599764>\
**Category:** API\
**Tags:** gpt-4, assistants, assistants-api\
**Created:** [January 24, 2024, 11:29am UTC](https://community.openai.com/t/token-optimization-for-assistants-api-excesive-token-count/599764 "2024-01-24T11:29:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marintudela](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/marintudela/32/448369_2.png) [@marintudela](https://community.openai.com/u/marintudela)\
**Post date:** [January 24, 2024, 11:29am UTC](https://community.openai.com/t/token-optimization-for-assistants-api-excesive-token-count/599764/1 "2024-01-24T11:29:33Z")

</div>

Hello,

I am currently utilizing the OpenAI API for sending messages to assistants and have encountered an issue with token usage. Each call I make seems to consume approximately 4000 tokens, which is perplexing considering my messages are about 50 tokens and the responses are typically around 200 tokens. I have lengthy instructions set up for the assistant, and I am wondering if this is impacting the token consumption.

To give you a better understanding, here’s the process I follow with my code:

1. Check for an existing thread ID to do the job; if not present, create a new thread.
2. I determine the assistant ID with an static id in my code.
3. I generate the input with around 200-400 tokens.
4. Add a message to the thread.
5. Execute the thread (Run command).
6. Check the status of the run.
7. Retrieve the steps of the run.
8. Finally, when is “completed”, I obtain the thread messages to view the response, ensuring to handle cases where the response might not be immediately available or if there’s an error.

My specific question is: How can I optimize token usage when interacting with OpenAI’s API, especially considering the length of my instructions? I tried to put fewer token in the instructions and I don´t get the same responses, but they bill less tokens. Is there a way to prevent these long instructions from increasing the token cost per call? I would like to understand if the instructions are being billed in every call, contributing to high token usage and how to avoid to be billed in every call for the training.

Any advice or shared experiences, particularly from those who have dealt with similar situations or have in-depth knowledge of OpenAI’s token billing system, would be greatly appreciated.

Thank you in advance for your assistance.

---

<div class="post-metadata">

**Author:** ![Diet](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/diet/32/562749_2.png) [@Diet](https://community.openai.com/u/Diet)\
**Post date:** [January 24, 2024, 12:26pm UTC](https://community.openai.com/t/token-optimization-for-assistants-api-excesive-token-count/599764/2 "2024-01-24T12:26:05Z")

</div>

Hi! Welcome to the forums!

> [@marintudela](#):
>
> I have lengthy instructions set up for the assistant, and I am wondering if this is impacting the token consumption.

Your instructions absolutely eat your tokens. Retrievals eat your tokens, a continuation of the thread eats your tokens. Actions eat tokens. Everything eats tokens. Om nom nom.

It’s my personal opinion that if you want to be cost conscious, assistants aren’t the best option out there.

Here’s a good post that summarizes it well:

> [@Assistants API pricing details per message](https://community.openai.com/t/assistants-api-pricing-details-per-message/476530/66):
>
> Yes, you are going to be charged unseen and unknown amounts. OpenAI went out of their way to return no token usage and no report of the internal language used calling functions, and then combined that with a new usage page that removes the prior by-the-minute token usage. You write an “instruction” to guide the AI. Is that wrapped in hundreds of tokens telling the AI what it can and cannot do with a “user” instruction provided there, like custom instructions in ChatGPT? You upload a file. Does…

---

<div class="post-metadata">

**Author:** ![jorgeintegrait](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/jorgeintegrait/32/159095_2.png) [@jorgeintegrait](https://community.openai.com/u/jorgeintegrait)\
**Post date:** [May 24, 2024, 5:45pm UTC](https://community.openai.com/t/token-optimization-for-assistants-api-excesive-token-count/599764/3 "2024-05-24T17:45:57Z")

</div>

With v2 of the API some of this has improved, we do now have prompt and completion token counts in at the run, and step levels.

Additionally, we can set maximum tokens per thread. Not a perfect solution, as it’s not like it auto-truncates, it just stops.

The recommendation for a production application would still be a custom RAG system, but assistants API is slowly getting there. It’ll probably be a good choice once it comes out of beta
