Assistant API response messages + token count

In assistant APIs:

  1. Are the API responses or bot messages auto appended to the threads or we have to do it?

  2. How do I get the input and output token count for these API responses like I used to get in completions?

Thanks.

  1. Assistant responses should automatically appear in that thread, you can confirm this with:
    messages = client.beta.threads.messages.list(thread.id)
  2. I believe the ThreadMessage will have the text value, but not sure it has a token attribute. Maybe check the run or thread object?
1 Like

Thank you for that.

OpenAI mentioned that they are planning on adding the token count feature soon

1 Like

I don’t think it’s always as simple as “get the last message from the thread”. The messages may appear in sequence. For example, one run can have 2 back-to-back messages from the API if asking it to leverage Code Interpreter to do some data operations on a file. You may have to be operating/checking on the Run itself.

That’s a good point, in which case you can check out the Run Steps:
https://platform.openai.com/docs/api-reference/runs/getRunStep

As this topic has an accepted solution, closing topic.