I’m trying to calculate the cost of my API calls when using oai reasoning models with streaming enabled. Where can I find the token usage information in the response? Should I disable streaming to get this data?
just found the solution, you can add the parameter:
"stream_options": {
"include_usage": True
}
eg:
data = {
"model": "o1-preview",
"messages": [{"role": "developer", "content": "hello"}],
"stream": True,
"stream_options": {
"include_usage": True
}
}
1 Like