The OpenAI Pricing Documentation seems a bit ambiguous:
Requests are billed based on the number of input tokens sent plus the number of tokens in the output(s) returned by the API.
Your request may use up to
num_tokens(input) + [max_tokens * max(n, best_of)]
tokens, which will be billed at the per-engine rates outlined at the top of this page.In the simplest case, if your prompt contains 200 tokens and you request a single 900 token completion from the gpt-3.5-turbo-1106 API, your request will use 1100 tokens and will cost
[(200 * 0.001) + (900 * 0.002)] / 1000 = $0.002
.
The “returned by the API” part suggests it is based on the actual tokens returned, regardless of how many I requested (I’m assuming the amount you request is determined by max_length). However, in their example, they say you “request a single 900 token completion” and then go on to use the 900 number in the calculations, seemingly implying that if you requested 900 you get charged for those 900.
So, if I send an API request with max_length set to 900, but the actual completion only contains 450 tokens, then (ignoring input tokens) am I charged for the 900 tokens in the request or the 450 in the response?