使用 ChatGPT 聊天的费用分析

OpenAI 在 6 月 13 日进行了大规模降价和升级,text-embedding-ada-002 降价 95%,GPT-3.5-turbo 降价 25%,而 GPT-4 最高可支持 32K 文本。

在 OpenAI 的官网上,对 ChatGPT 的价格计算方式有详细的说明。其价格是以 token 来计算的,接下来我们将探讨当前的实际费用。

官网聊天

官方网页上聊天是免费的,收费项目主要针对 API 用户。API 用户默认赠送 5 美元额度。

大语言模型

计算方法

测试样本:
多个模型,各具不同能力和价格。价格以每 1,000 tokens 计算。可以将 tokens 理解为单词的片段,1,000 tokens 大约相当于 750 个单词。以下是官方样本文字的 token 长度说明:

ChatGPT 使用的 tokenizer 是 Byte-Pair Encoding (BPE) 算法,有几种方法可以近似计算 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:聊天的背景信息,告诉 ChatGPT 聊天的背景是什么,通常用户看不到。
  2. User Prompt:用户的提问。
  3. AI’s Reply:ChatGPT 的回答。

以以下样本为例,看看实际的费用:

python
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 美元额度大约可以进行 6000 多句英文对话(中文对话会有所出入)。

其他收费项目的具体价格情况

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 多句对话。

想深入理解 token 和分词,需要进一步学习相关概念。

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

(0)
上一篇 2025年7月29日
下一篇 2025年7月30日

相关推荐