使用ChatGPT聊天究竟需要多少费用?

OpenAI在6月13日宣布了大规模的价格调整和升级,其中包括text-embedding-ada-002降价95%、GPT-3.5-turbo降价25%,以及GPT-4支持最高32K文本的能力。

OpenAI的官网上,详细说明了ChatGPT的价格计算方式。不过,其价格采用token计算,本文让我们来具体看看当前的实际费用。

官网聊天

在OpenAI的官方网页上,使用ChatGPT进行聊天是完全免费的,收费主要针对API用户,默认赠送5美元的额度。

大语言模型

计算方法

测试样本:

Multiple models, each with different capabilities and price points. Prices are per 1,000 tokens. You can think of tokens as pieces of words, where 1,000 tokens is about 750 words. This paragraph is 35 tokens.

官方样本文字中说明了,这段测试样本的长度为35个tokens。

ChatGPT使用Byte-Pair Encoding(BPE)算法作为tokenizer,以下是几种近似计算token值的方法:
1. Transformers
2. OpenAI tiktoken
3. 单词数 / 0.75

使用Transformers方法对测试样本进行tokens计算:
python
def get_transformers_tokens(text: str, encoding_name: str) -> int:
tokenizer = transformers.AutoTokenizer.from_pretrained(encoding_name)
tokens = tokenizer.tokenize(text)
num_tokens = len(tokens)
return num_tokens

得到tokens值为45。

使用tiktoken的方法对测试样本进行tokens计算:
python
def get_tiktoken_tokens(text: str, encoding_name: str) -> int:
encoding = tiktoken.get_encoding(encoding_name)
num_tokens = len(encoding.encode(text))
return num_tokens

得到tokens值也为45。

有趣的是,得出的值是45,和OpenAI官网中给出的35不同,但使用OpenAI官方计算器计算的结果也是45。

tokens的消耗至少受到以下三个因素的影响:
1. System Prompt:聊天的背景信息;
2. User Prompt:用户的提问;
3. AI’s Reply:ChatGPT的回答。

用以下样本为例,看下实际的费用:
markdown
How to calculate tokens for chatGPT?
To calculate the number of tokens for a text sequence in ChatGPT, you can follow these steps:

Tokenization: In ChatGPT, the text needs to be segmented into a sequence of words or subword units, called tokens. You can use a tokenizer to convert the text into tokens. The tokenizer used in ChatGPT is based on Byte-Pair Encoding (BPE) algorithm, which can convert the text into a decodable sequence of subword units.

Counting tokens: Once the text has been segmented into tokens, you can count the number of tokens. In ChatGPT, the number of tokens is equal to the number of tokens contained in the text. You can use the len() function to count the number of tokens.

Here is an example code that can calculate the number of ChatGPT tokens for a given text sequence:

Chat

| Model | Input | Output |
| — | — | — |
| 4K context | $0.0015 / 1K tokens | $0.002 / 1K tokens |
| 16K context | $0.003 / 1K tokens | $0.004 / 1K tokens |

将上面的样本内容和定价带入,可以计算出,5美元对应的对话次数是6887次。也就是说,账号自带的5美元额度,大约可以聊6到7千句英文对话(中文对话会有所出入)。

通过此方法可以计算其他收费项目的具体价格情况:

GPT-4

| Model | Input | Output |
| — | — | — |
| 8K context | $0.03 / 1K tokens | $0.06 / 1K tokens |
| 32K context | $0.06 / 1K tokens | $0.12 / 1K tokens |

InstructGPT

| Model | Price |
| — | — |
| Ada | $0.0004 / 1K tokens |
| Babbage | $0.0005 / 1K tokens |
| Curie | $0.0020 / 1K tokens |
| Davinci | $0.0200 / 1K tokens |

Fine-tuning models

| Model | Training | Usage |
| — | — | — |
| Ada | $0.0004 / 1K tokens | $0.0016 / 1K tokens |
| Babbage | $0.0006 / 1K tokens | $0.0024 / 1K tokens |
| Curie | $0.0030 / 1K tokens | $0.0120 / 1K tokens |
| Davinci | $0.0300 / 1K tokens | $0.1200 / 1K tokens |

Embedding models

| Model | Usage |
| — | — |
| Ada v2 | $0.0001 / 1K tokens |
| Ada v1 | $0.0040 / 1K tokens |
| Babbage v1 | $0.0050 / 1K tokens |
| Curie v1 | $0.0200 / 1K tokens |
| Davinci v1 | $0.2000 / 1K tokens |

其他模型

图像模型

| Resolution | Price |
| — | — |
| 1024×1024 | $0.020 / image |
| 512×512 | $0.018 / image |
| 256×256 | $0.016 / image |

音频模型

| Model | Usage |
| — | — |
| Whisper | $0.006 / minute |

总结

虽然OpenAI提供了token计算工具,但工具的计算值和官方网页中的说明不一致。使用API访问ChatGPT 3.5的话,账号自带的5美元额度大约可以聊6000多句对话。

👉 野卡 | 一分钟注册,轻松订阅海外线上服务

上一篇 2025年5月1日
下一篇 2025年5月2日

相关推荐