#Costs (Tokens) calculation

1 messages · Page 1 of 1 (latest)

autumn furnace
#

Hello,
I have some problems with calculating the request cost on my backend. It's a little bit unclear to me how to calculate costs.

The returned token usage for requests is not separated for different types of input/output, possibly in the prompt and response

Let's say the user prompt is text with an image to gpt-5, and it also uses the image generation tool to generate/edit the image in the prompt (Forwards request to gpt-image).
The response in return has some texts and a new image.

Now, I want to know how to properly calculate token costs for the input {text + image} and the same for the output {text + image}

The problem is that response usage does not show them separately, so I have to calculate them manually. The question is whether the input/output tokens in the report are only for texts or images are also include?

In the documentation page of the gpt-5 it only says price input for the text, not for images, so the question is, are they free, or do I have to use the gpt-image input cost?

autumn furnace
#

This is the usage of this prompt "Generate an image of gray tabby cat hugging an otter with an orange scarf" to GPT-5 with the image generation tool:
ResponseUsage(input_tokens=3070, input_tokens_details=InputTokensDetails(cached_tokens=0), output_tokens=1517, output_tokens_details=OutputTokensDetails(reasoning_tokens=1088), total_tokens=4587)

tiny drum
#

As per above your cost will be $ 1.25 /M for 3070 input tokens (including image) and output is $10/M for Output + Reasoning Tokens (Both output and reasoning are charged at output rates). Hope this helps.

autumn furnace
# tiny drum As per above your cost will be $ 1.25 /M for 3070 input tokens (including image)...

Thank you for your reply, but I think this is still not correct compared to what I see in my usage report page.
The reasoning token you mentioned is already counted in output_tokens, so there's no need to sum up the output_tokens + reasoning_tokens

I did another test with a day without any requests to my API key, and this is the result:

Model: GPT-5
Prompt: Generate an image of gray tabby cat hugging an otter with an orange scarf
Image quality: low
Size:1024x1024 (square)
Backgroud:opaque

Response Usage : input_tokens=2056, output_tokens=1306, output_tokens_details=OutputTokensDetails(reasoning_tokens=896), total_tokens=3362

The cost of input is 0.00257 and the cost of the output is: 0.01306, total cost is: 0.01563

But what I see in my report usage is 0.03 and that's almost twice my calculation.

There's a catch here: I did a single request to the API, but it shows two requests in my usage report, another one for the GPT-Image model

So the details that do not exist in the API response usage are:
GPT-Image: input_tokens=218, output_tokens=272
The cost of input is 0.00109 and the cost of the output is 0.01088 total cost is 0.01197, almost the same as described in the GPT image doc page.

If we sum the gpt 5 cost with the gpt image cost, the result is 0.0276, which is very close to what I see in my usage report, 0.03