azure-cost-calculator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAzure Cost Calculator
Azure成本计算器
Deterministic Azure cost estimation using the public Retail Prices API. Never guess prices — always query the live API via the scripts.
通过公开的Retail Prices API实现确定性Azure成本估算。绝不猜测价格——始终通过脚本查询实时API。
Workflow
工作流程
- Identify the resource type(s) the user wants to estimate
- Locate the service reference:
a. File search — search for files matching (e.g., "Cosmos DB" →
references/services/**/*<keyword>*.md) b. Category browse — if search returns 0 or ambiguous results, read the category index in references/shared.md and list the matching category directory c. Broad search — list or searchservices/**/cosmos*.mdto see all available files d. Discovery — if no file exists, usereferences/services/**/*.mdto find the service in the APIscripts/Explore-AzurePricing.ps1 - Read only the matching service file(s) for query parameters, cost formula, and the exact
serviceName - Run with the parameters from the service reference
scripts/Get-AzurePricing.ps1 - Present the estimate with breakdown: unit price, multiplier, monthly cost, assumptions
- 识别用户想要估算的资源类型
- 定位服务参考文档:
a. 文件搜索 — 搜索匹配的文件(例如,“Cosmos DB” →
references/services/**/*<keyword>*.md) b. 分类浏览 — 如果搜索返回0个结果或结果不明确,查看references/shared.md中的分类索引,并列出匹配的分类目录 c. 广泛搜索 — 列出或搜索services/**/cosmos*.md以查看所有可用文件 d. 发现模式 — 如果不存在对应文件,使用references/services/**/*.md在API中查找该服务scripts/Explore-AzurePricing.ps1 - 读取仅与查询参数、成本公式和精确相关的匹配服务文件
serviceName - 运行带有服务参考文档中参数的脚本
scripts/Get-AzurePricing.ps1 - 呈现包含明细的估算结果:单价、乘数、月度成本、假设条件
Reference Index (load on demand)
参考索引(按需加载)
| Condition | Read |
|---|---|
| Always (entry point) | references/shared.md — constants, category index, alias lookup |
| Query returned 0 results or wrong data | references/pitfalls.md — troubleshooting and traps |
| User asks about Reserved Instances or savings plans | references/reserved-instances.md |
| Non-USD currency or non-eastus region | references/regions-and-currencies.md |
| Category Index + file search both failed | references/service-routing.md — full 140+ service map |
| First time running scripts or unfamiliar with parameters | references/workflow.md — script parameters and output formats |
| 条件 | 读取文档 |
|---|---|
| 始终(入口点) | references/shared.md — 常量、分类索引、别名查找 |
| 查询返回0个结果或错误数据 | references/pitfalls.md — 故障排除与注意陷阱 |
| 用户询问预留实例或节省计划 | references/reserved-instances.md |
| 非USD货币或非eastus区域 | references/regions-and-currencies.md |
| 分类索引+文件搜索均失败 | references/service-routing.md — 包含140+服务的完整映射 |
| 首次运行脚本或不熟悉参数 | references/workflow.md — 脚本参数与输出格式 |
Critical Rules
关键规则
- Never guess prices — always run the script against the live API
- Filter values are case-sensitive — use exact values from the service reference file
- Infer currency and region from user context — if unspecified, ask the user or default to USD and eastus. The API supports all major currencies (USD, AUD, EUR, GBP, JPY, CAD, INR, etc.) via the parameter.
-Currency - State assumptions — always declare: region, OS, commitment type, instance count
- Ask before assuming — if a required parameter is ambiguous or missing (tier, SKU, quantity, currency, node count, traffic volume), stop and ask the user before proceeding. Do not silently pick a default. The only exceptions are constants defined in service reference files (e.g., mandatory default CU counts) — those are pre-approved defaults.
- Default output format is Json — do not use Summary (invisible to agents)
- Lazy-load service references — only read files from that are directly required by the user's query. Never bulk-read all service files. Use the file-search workflow (Step 2) to locate the specific file(s). If the user asks about App Service and SQL Database, search for each and read only those files — not the other 20+.
references/services/ - Use , not
pwsh -File— on Linux/macOS, bash strips OData quotes from inline commands. Always usepwsh -Command.pwsh -File scripts/Get-AzurePricing.ps1 ...
- 绝不猜测价格 — 始终通过实时API运行脚本获取价格
- 过滤值区分大小写 — 使用服务参考文件中的精确值
- 从用户上下文推断货币和区域 — 如果未指定,询问用户或默认使用USD和eastus。API通过参数支持所有主要货币(USD、AUD、EUR、GBP、JPY、CAD、INR等)。
-Currency - 声明假设条件 — 始终明确说明:区域、操作系统、承诺类型、实例数量
- 先询问再假设 — 如果必填参数不明确或缺失(层级、SKU、数量、货币、节点数、流量),在继续前停止并询问用户。不要默认选择值。唯一例外是服务参考文件中定义的常量(例如,强制默认CU数量)——这些是预先批准的默认值。
- 默认输出格式为Json — 不要使用Summary格式(Agent无法识别)
- 延迟加载服务参考文档 — 仅读取中与用户查询直接相关的文件。绝不批量读取所有服务文件。使用文件搜索工作流(步骤2)定位特定文件。如果用户询问App Service和SQL Database,分别搜索并仅读取这些文件——而非其他20多个文件。
references/services/ - 使用而非
pwsh -File— 在Linux/macOS上,bash会从内联命令中剥离OData引号。始终使用pwsh -Command。pwsh -File scripts/Get-AzurePricing.ps1 ...
Universal Traps
通用陷阱
These 4 traps apply to EVERY query — do not skip them:
- and all filter values are case-sensitive — always use exact values from the service reference file. Never guess from portal/docs names.
serviceName - Unfiltered queries return mixed SKU variants — without /
productNamefilters, results mix Spot, Low Priority, and OS variants. Always filter to the specific variant needed.skuName - Multi-meter resources need separate queries — many resources have multiple cost components (compute + storage, fixed + variable). Run one query per meter with .
-MeterName - output is invisible to agents — always use
Write-Host(the default). Never use-OutputFormat Jsonformat.Summary
这4个陷阱适用于所有查询——请勿忽略:
- 和所有过滤值区分大小写 — 始终使用服务参考文件中的精确值。绝不根据门户/文档名称猜测。
serviceName - 未过滤的查询会返回混合SKU变体 — 如果没有/
productName过滤,结果会混合Spot、低优先级和操作系统变体。始终过滤到所需的特定变体。skuName - 多计量资源需要单独查询 — 许多资源包含多个成本组件(计算+存储、固定+可变)。使用为每个计量项运行一次查询。
-MeterName - 输出对Agent不可见 — 始终使用
Write-Host(默认格式)。绝不使用Summary格式。-OutputFormat Json
Batch Estimation Mode
批量估算模式
When estimating 3 or more services, use these rules to reduce token consumption:
- Partial reads — read only lines 1–45 of each service file. These lines contain: YAML front matter, primary cost description, trap warning, and the first (most common) query pattern.
- Full read triggers — only read the full service file if:
- The partial read does not contain a usable query pattern
- The user requests a non-default tier, SKU, or configuration
- The service has complex multi-meter billing that needs the full meter table
- The query returns 0 or unexpected results
- Parallel queries — run calls in parallel where possible. Independent services have no query dependencies.
Get-AzurePricing.ps1 - Skip redundant references — do not re-read shared.md or pitfalls.md between services. Read them once at the start.
当估算3个或更多服务时,使用以下规则减少令牌消耗:
- 部分读取 — 仅读取每个服务文件的第1-45行。这些行包含:YAML前置内容、主要成本说明、陷阱警告和第一个(最常见的)查询模式。
- 触发完整读取的条件 — 仅在以下情况读取完整服务文件:
- 部分读取未包含可用的查询模式
- 用户请求非默认层级、SKU或配置
- 服务具有需要完整计量表的复杂多计量计费方式
- 查询返回0个或意外结果
- 并行查询 — 尽可能并行运行调用。独立服务之间没有查询依赖。
Get-AzurePricing.ps1 - 跳过冗余参考 — 在不同服务之间不要重复读取shared.md或pitfalls.md。在开始时读取一次即可。