0

I am using openAI whisper to convert voice to text: https://platform.openai.com/docs/api-reference/audio/create

the json response is

{
 "text": "some text"
}

the response data return only one text field and has no other information

I want to know how much tokens I have used, how can I do that?

asked Mar 20, 2023 at 20:58

3 Answers 3

2

In case someone was to see the question now, it is now possible to track usage
There is a field usage in the json response that allows for example to write code like:

from openai import OpenAI
client = OpenAI()
audio_file = open("speech.mp3", "rb")
transcript = client.audio.transcriptions.create(
 model="whisper-1",
 file=audio_file
)
print (transcript.usage)

You will then get a UsageDuration object that has a seconds field So basically by doing math.ceil(transcript.usage.seconds / 60) * 0.006 you can get the cost of your transcription.

Pricing is available here

answered Jul 24, 2025 at 18:09
Sign up to request clarification or add additional context in comments.

Comments

1

There are no tokens for OpenAI Audio API endpoints. You pay per minute.

As stated on the official OpenAI website:

As of March 2023, using the OpenAI Whisper audio model, you pay 0ドル.006/minute (rounded to the nearest second).

Screenshot

Note: You can't get minute usage from the OpenAI response like you can get token usage when using other OpenAI API endpoints. You need to write code and get the audio duration manually.

answered Mar 21, 2023 at 9:34

8 Comments

no token, so it is free? I want to keep track of my users usage
No, it's not free. It costs 0ドル.006/minute.
so how can I keep track of my user usage?
The only option I see is that you track file length in minutes.
I know, but how can I obtain the minute (or token or whatever) from the response???
|
0

In NodeJS I did in this way:

 /**
 * Transcribe audio file
 * @param {string} outputFilePath
 * @returns {Promise<string>}
 */
 async transcribeAudio(outputFilePath) {
 const url = 'https://api.openai.com/v1/audio/transcriptions';
 const apiKey = process.env.OPENAI_API_KEY;
 const language = 'pt';
 const formData = new FormData();
 formData.append('file', createReadStream(path.resolve(outputFilePath)));
 formData.append('model', 'whisper-1');
 formData.append('response_format', 'verbose_json');
 formData.append('language', language);
 const headers = {'Authorization': `Bearer ${apiKey}`, ...formData.getHeaders()};
 return await new Promise((resolve, reject) => {
 const req = https.request(url, {method: 'POST', headers: headers}, (res) => {
 let data = '';
 res.on('data', (chunk) => {
 data += chunk;
 });
 res.on('end', () => {
 const response = JSON.parse(data);
 console.log(`transcribeAudio response: "${response.text}" - Seconds: ${response.duration}`);
 const segments = response && response.segments ? response.segments : [];
 const transcription = segments.map((segment) => segment.text).join('\n');
 resolve(transcription);
 });
 });
 req.on('error', (error) => {
 console.error('error on transcribe mp3 audio in openai whisper', error);
 reject(error);
 });
 formData.pipe(req);
 });
 }
answered Dec 23, 2023 at 7:41

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.