Azure 部署名不是 OpenAI model id:usage 仍按部署背后的型号
Azure OpenAI 的 model 参数是部署名,不是公开 API 的型号 id。usage 仍拆成输入 / 输出 / 缓存三列;乘数用部署背后那只型号的官方价,不要用部署字符串去对公开价表。
本页不发起请求;不收 Key;中转 curl 不在本站。
← 计费示例 · 计费路径 · 官方 usage 文档
输入usage.prompt_tokens
输出usage.completion_tokens
缓存usage.prompt_tokens_details.cached_tokens
model (deployment name) · Azure 的 model 字段是部署名。公开 API 的 gpt-6-astra 之类 id 不能直接当部署名用。
import { AzureOpenAI } from "openai";
// Azure OpenAI: the "model" argument is the DEPLOYMENT NAME.
// It is not the public OpenAI model id (e.g. gpt-6-astra).
// Usage still maps to 输入 / 输出 / 缓存. Multiply by the model behind the deployment.
// Keys from env only. Never paste a key.
const client = new AzureOpenAI({
endpoint: process.env.AZURE_OPENAI_ENDPOINT,
apiKey: process.env.AZURE_OPENAI_API_KEY,
apiVersion: process.env.AZURE_OPENAI_API_VERSION,
});
const completion = await client.chat.completions.create({
model: process.env.AZURE_OPENAI_DEPLOYMENT,
messages: [{ role: "user", content: "Reply with one word: ok" }],
});
const usage = completion.usage ?? {};
const input = usage.prompt_tokens ?? 0; // 输入
const output = usage.completion_tokens ?? 0; // 输出
const cached = usage.prompt_tokens_details?.cached_tokens ?? 0; // 缓存
console.log("deployment", process.env.AZURE_OPENAI_DEPLOYMENT);
console.log("returned_model", completion.model);
console.log("输入", input);
console.log("输出", output);
console.log("缓存", cached);
| 字段 | 对上列 | 说明 |
|---|---|---|
usage.prompt_tokens | 输入 | 与公开 Chat Completions 同一列。乘数看部署背后的型号,不是部署名本身。 |
usage.completion_tokens | 输出 | 输出列。对账乘该部署所指向型号的「输出」$/M。 |
usage.prompt_tokens_details.cached_tokens | 缓存 | 有命中才非 0。缺 details 记 0。不要用部署名去猜缓存折扣。 |
model (deployment name) | — | Azure 的 model 字段是部署名。公开 API 的 gpt-6-astra 之类 id 不能直接当部署名用。 |