How to track API usage and cost by API key?

My company will use different API key for different AI-enabled applications/features/engineering teams. We’d like to track usage and cost by API key. Is that a way to track API usage and cost by API keys?

It seems right now the usage tracking is by organization only.

It would be fine if we need to track it as middleware when hitting OpenAI API. Just want to make sure I am not missing a hidden feature.


Following, I am looking for the same information.

1 Like

I have the same requirement. There are multiple applications that are using the key and tracking usage per key would help identify utilization across apps.

I am looking for the same info. Did anyone get an answer?

Same question. #OpenAITEAM

Same need, same question.

What is the material benefit or use case of having different api keys per account if usage for each can’t be tracked?

I have the same need - see usage by API Key.

What we do is log a token identifier, and the response model name and tokens used, for each API request, into our log/metrics/tracing/observability system.
We then sum this up in a worksheet with a simple query.
Observe Inc has a simple OpenAI integration: What's New: OpenAI App!
However, you’ll still need to add instrumentation to your own code to log out the model/token counts, and write a query to parse that back in and sum it up.
(Observe is an enterprise software suite; there’s no free trial or open source version; if your volumes are low, doing the summary in Python or SQL or somesuch might be tractable as an alternative.)

Our application uses the stream response method, for which the client does not get token counts in the reply.

You can use the command req Get to

The result returned at the variable total_usage/100 is the cost of credit you have used from start_date to end_date