---
title: 'Open AI pricing for developers'
disqus: hackmd
tags: Cathay
---
{%hackmd BJrTq20hE %}
GCP ACE Certification Preparation Note
===

# 計價分類 (與此案相關)
## Fine-tuing 微調
了解如何為您的應用程序定制模型。
通過提供以下內容,微調可讓您從 API 提供的模型中獲得更多收益:
1. 比即時設計更高質量的結果
1. 能夠訓練比提示中更多的例子
1. 由於更短的提示而節省了代幣
1. 更低的延遲請求
GPT-3 已經在來自開放互聯網的大量文本上進行了預訓練。當給出僅包含幾個示例的提示時,它通常可以憑直覺判斷出您要執行的任務並生成合理的完成。這通常稱為“小樣本學習”。
微調通過訓練比提示中更多的示例來改進小樣本學習,讓您在大量任務中取得更好的結果。對模型進行微調後,您將不再需要在提示中提供示例。這樣可以節省成本並實現更低延遲的請求。
在高層次上,微調涉及以下步驟:
1. 準備和上傳訓練數據
1. 訓練新的微調模型
1. 使用您的微調模型
## Embedding 嵌入
OpenAI 的文本嵌入衡量文本字符串的相關性。嵌入通常用於:
* 搜索(結果按與查詢字符串的相關性排序)
* 聚類(其中文本字符串按相似性分組)
* 推薦(推薦具有相關文本字符串的項目)
* 異常檢測(識別出相關性很小的異常值)
* 多樣性測量(分析相似性分佈)
* 分類(其中文本字符串按其最相似的標籤分類)
# Fine-tuning models Price

# Embedding models Price

# Token
Open AI的api是用Token(令牌)來做計費。
您可以將標記視為用於自然語言處理的單詞片段。對於英文文本,1 個標記大約為 4 個字符或 0.75 個單詞。作為參考,莎士比亞全集約有 900,000 字或 120 萬個令牌。
# Calculated for Completions
* Completions requests 根據 prompt 中傳送的令牌數量以及 API 返回的完整令牌數量進行計費。
* best_of 和 n 參數也會影響成本。因為這些參數每個 prompt 會生成多個完成,所以它們會將返回的令牌數量作為乘數。
* 您的請求可以使用 num_tokens(prompt) + max_tokens * max(n, best_of) 的令牌數量,這將以本頁頂部列出的每引擎費率進行計費。
* 在最簡單的情況下,如果您的 prompt 包含 10 個令牌,並且您從 davinci 引擎請求一個包含 90 個令牌的完成,您的請求將使用 100 個令牌,成本為 $0.002。
Completions requests are billed based on the number of tokens sent in your prompt plus the number of tokens in the completion(s) returned by the API.
The best_of and n parameters may also impact costs. Because these parameters generate multiple completions per prompt, they act as multipliers on the number of tokens returned.
Your request may use up to num_tokens(prompt) + 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 10 tokens and you request a single 90 token completion from the davinci engine, your request will use 100 tokens and will cost $0.002.
You can limit costs by reducing prompt length or maximum response length, limiting usage of best_of/n, adding appropriate stop sequences, or using engines with lower per-token costs.
# Calculated for Fine-tuning
* Fine-tuning的計費由兩個組成部分:訓練和使用。
* 訓練Fine-tuned模型時,使用的總令牌將根據我們的訓練費率進行計費。請注意,訓練令牌的數量取決於訓練數據集中的令牌數量和您選擇的訓練epochs的數量。默認的訓練epochs數為4。
* (您的訓練文件中的令牌數 * 訓練epochs數量) = 總訓練令牌
* 一旦Fine-tune模型,您將只為使用的令牌付費。發送到Fine-tuned模型的請求將按照我們的使用費率進行計費。
There are two components to fine-tuning pricing: training and usage.
When training a fine-tuned model, the total tokens used will be billed according to our training rates. Note that the number of training tokens depends on the number of tokens in your training dataset and your chosen number of training epochs. The default number of epochs is 4.
(Tokens in your training file * Number of training epochs) = Total training tokens
Once you fine-tune a model, you’ll be billed only for the tokens you use. Requests sent to fine-tuned models are billed at our usage rates.