{"article":{"title":"Cost attribution","breadcrumb":["Billing","Cost attribution"],"body":"**What this solves**: Lets you see \"where this money went\" and break spend down by customer, product line, task, and stage.\n\nAttribution isn't a bill-download feature. It's finer-grained than an API bill, recording each model call separately by key, model, business label, and task stage.\n\n### To see spend by business line, the call must carry labels\n\nIf you want to see cost by customer, product line, task, or stage, you need to **have your engineering team include** fields like `usage_label`, `task_id`, and `stage_code` in the request body. Tare records them on this call and **strips** them before forwarding upstream, so the provider never sees them.\n\n> [!WARNING]\n> **This is an action item: without labels, you can never break it down afterward.** If you can't change the call code for now, there are only two alternatives:\n>\n> 1. Have your engineering team add the business labels to the request body;\n> 2. Split into different Child keys by customer, business line, or environment.\n>\n> With neither labels nor separate keys, there's no reliable way to break historical spend back down by business line.\n\n### Before reading reports, tell the two numbers apart\n\nThe console can break spend down by model, by key, by product line, and by time. Before reading a report, tell these two numbers apart:\n\n| Field | Meaning |\n|---|---|\n| Charged | The amount the platform charges you, including the governance fee |\n| Attributed spend | How much this call actually cost **you**, including the BYOK upstream cost |\n\nTo measure the cost of a single feature, use **Attributed spend**.\n\n> [!NOTE]\n> Charged includes the governance fee. It is not the upstream token charge. Attributed spend includes what the provider bills you directly. Do not add the two together.\n\n![Two numbers to tell apart before reading a report: Charged and Attributed spend](diagram:en-attribution-two-numbers)\n\n### Details\n\n#### How to add attribution fields\n\nAttach these fields **in the request body**; Tare records them on this call and **strips** them before forwarding, so the provider never sees them:\n\n![The life of an attribution field: it comes in with the call and is stripped before forwarding](diagram:en-attribution-label-flow)\n\n```json\n{\n  \"model\": \"GLM 5.1\",\n  \"messages\": [ ... ],\n\n  \"task_id\": 4821,\n  \"task_type\": \"issue-fix\",\n  \"stage_code\": \"plan\",\n  \"action_code\": \"draft-patch\",\n  \"attempt_no\": 2,\n  \"usage_label\": \"acme-corp\",\n  \"available_tool_count\": 12,\n  \"available_tool_choice_mode\": \"auto\"\n}\n```\n\n> [!TIP]\n> Stripping is necessary: the official OpenAI endpoint **returns 400 for unknown body parameters**. A BYOK channel pointing at `api.openai.com` would fail on every call because of this, and the error message has no visible relation to \"one extra label was passed\".\n\n> [!NOTE]\n> `models` and `provider` (see [Routing](routing)) are also stripped, but they're **not** attribution labels: they decide which model and which channel answers this call, and aren't recorded against this call.\n\n#### Charged and Attributed spend\n\n- **Charged**: the amount the platform charges you, including the governance fee.\n- **Attributed spend**: how much this call cost **you**, including the part the provider charges you directly. Use this value to measure the cost of a single feature.\n\nCharged includes the governance fee. It is not the upstream token charge. Attributed spend includes what the provider bills you directly. Do not add the two together.\n\n#### Retries and idle tool calls\n\nThe spend on retries, and on \"tools were provided but never called once\", is counted separately. These two are usually a small share; once their share rises, they're the lowest-cost improvements in the whole table.\n\n#### Upstream Costs\n\nConsole → **Upstream Costs** shows what you paid your own upstream accounts for BYOK calls. Only calls with a known upstream price appear, so the total is a lower bound. For a provisioning key it shows the combined upstream cost of the child keys it issued.\n\n#### The console's own read endpoints\n\n> [!NOTE]\n> The following are the console pages' own **logged-in session endpoints**, not part of the key-authenticated reconciliation API. For automated reconciliation, use the [Reconciliation API](integration-api).\n\nThe Analytics page (`GET /v1/analytics`) puts usage, per-model share, and success rate together in one endpoint; these three come from the same batch of numbers.\n\nIts time series accepts a `granularity` (minute / half-hour / hour / day) and can plot spend, request count, tokens, success rate, or average latency; the detail table groups by model, channel, key, or stage, and the console page itself toggles among these five metrics and four groupings. The model-share chart keeps only the 6 models with the most requests and folds the rest into `Other`; an account that ran thirty models sees the ones that truly dominate, not thirty thin lines squeezed together indistinguishably.\n\n`/usage` (with `query`, `message`, `daily-chart`, `live`, `cost-series` endpoints) provides the data used by the console charts and the \"in-flight calls\" live view; `POST /usage/realtime/ticket` is the WebSocket handshake ticket for that live view, **expiring after a single use**.\n\n### Next steps\n\n- Want to figure out which costs land on you: read [Billing rules](billing).\n- Want to reconcile by period: read [Statements and invoices](statements).\n- Want to pull data programmatically: read [Reconciliation API](integration-api).\n"},"diagrams":{"en-attribution-two-numbers":"<svg viewBox=\"0 0 708 284\" width=\"708\" role=\"img\" xmlns=\"http://www.w3.org/2000/svg\">\n  <title>Two numbers to separate before reading a report: Charged and Attributed spend</title>\n  <desc>Charged is what the platform charges you, including the governance fee. Attributed spend is what this call actually cost you, including the BYOK upstream cost. Do not add the two together. Use Attributed spend to measure the cost of one feature.</desc>\n  <style>\n    text { font-family: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', system-ui, sans-serif; }\n  </style>\n\n  <!-- 浅色画布 -->\n  <rect x=\"0\" y=\"0\" width=\"708\" height=\"284\" fill=\"#ffffff\"/>\n\n  <!-- 版式算术：\n       两列并排，宽 318、间距 28，于是 22..340 / 368..686。\n       两列同高 72（12px 一行 + 10px 两行），顶边 60、底边 132。\n       下方一条横贯整行的差额说明，22..686（宽 664），顶边 160、底边 214。\n       内容左右边界 22..686，中心 354；viewBox 宽 = 664 + 两侧各 22 = 708。\n       高度 = 脚注末行基线 259 + 下伸 2.5 + 22px 边距 = 283.5，取整 284。 -->\n\n  <text x=\"354\" y=\"34\" font-size=\"16\" fill=\"#1e293b\" text-anchor=\"middle\">Charged and Attributed spend, kept apart</text>\n\n  <!-- 左列：平台收你的钱 → 粉（要掏出去的那笔）。基线 60+23 / +41 / +56。 -->\n  <rect x=\"22\" y=\"60\" width=\"318\" height=\"72\" rx=\"6\" fill=\"#fce7f3\" stroke=\"#ec4899\"/>\n  <text x=\"181\" y=\"83\" font-size=\"12\" fill=\"#9d174d\" text-anchor=\"middle\">Charged</text>\n  <text x=\"181\" y=\"101\" font-size=\"10\" fill=\"#9d174d\" text-anchor=\"middle\">What the platform charges you</text>\n  <text x=\"181\" y=\"116\" font-size=\"10\" fill=\"#9d174d\" text-anchor=\"middle\">Governance fee, not upstream tokens</text>\n\n  <!-- 右列：真实花掉的钱 → 绿（该用它）。 -->\n  <rect x=\"368\" y=\"60\" width=\"318\" height=\"72\" rx=\"6\" fill=\"#d1fae5\" stroke=\"#22c55e\"/>\n  <text x=\"527\" y=\"83\" font-size=\"12\" fill=\"#166534\" text-anchor=\"middle\">Attributed spend</text>\n  <text x=\"527\" y=\"101\" font-size=\"10\" fill=\"#166534\" text-anchor=\"middle\">What this call actually cost you</text>\n  <text x=\"527\" y=\"116\" font-size=\"10\" fill=\"#166534\" text-anchor=\"middle\">Includes the provider's direct bill</text>\n\n  <!-- 差额说明：两列的差就是自有渠道那段，横贯整行避免它看起来只属于某一列。 -->\n  <rect x=\"22\" y=\"160\" width=\"664\" height=\"54\" rx=\"6\" fill=\"#dbeafe\" stroke=\"#3b82f6\"/>\n  <text x=\"354\" y=\"182\" font-size=\"12\" fill=\"#1e40af\" text-anchor=\"middle\">On your own channel, you pay the provider for upstream cost</text>\n  <text x=\"354\" y=\"200\" font-size=\"10\" fill=\"#1e40af\" text-anchor=\"middle\">Charged includes the governance fee. Attributed spend includes upstream cost. Do not add them.</text>\n\n  <!-- 脚注 -->\n  <text x=\"354\" y=\"244\" font-size=\"10\" fill=\"#64748b\" text-anchor=\"middle\">To measure one feature, use Attributed spend. That is what the call actually cost you.</text>\n  <text x=\"354\" y=\"259\" font-size=\"10\" fill=\"#64748b\" text-anchor=\"middle\">Retry spend, and spend on tools that were offered but never called, are counted on their own.</text>\n</svg>\n","en-attribution-label-flow":"<svg viewBox=\"0 0 700 430\" width=\"700\" role=\"img\" xmlns=\"http://www.w3.org/2000/svg\">\n  <title>Attribution fields come in, then get stripped</title>\n  <desc>Attribution fields arrive on the request body, are recorded on the call, and are stripped before the forward so the provider never sees them. Official OpenAI returns 400 for unknown body fields. Video generation does not read usage_label.</desc>\n  <style>\n    text { font-family: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', system-ui, sans-serif; }\n  </style>\n  <defs>\n    <marker id=\"arrow\" markerWidth=\"8\" markerHeight=\"8\" refX=\"2\" refY=\"4\" orient=\"auto\" markerUnits=\"userSpaceOnUse\">\n      <path d=\"M0,0 L8,4 L0,8 L2,4 z\" fill=\"#64748b\"/>\n    </marker>\n  </defs>\n\n  <!-- 浅色画布 -->\n  <rect x=\"0\" y=\"0\" width=\"700\" height=\"430\" fill=\"#ffffff\"/>\n\n  <!-- 版式算术：\n       四段全宽横条，22..678（宽 656），高 54（12px 一行 + 10px 一行），\n       顶边 60 / 142 / 224 / 306，底边 114 / 196 / 278 / 360，段间 28。\n       三段连线全竖直落在内容中心 350，起点 = 上条底边 + 5，终点 = 下条顶边 - 11，留 12px 可见线。\n       内容左右边界 22..678，中心 350；viewBox 宽 = 656 + 两侧各 22 = 700。\n       高度 = 脚注末行基线 405 + 下伸 2.5 + 22px 边距 = 429.5，取整 430。 -->\n\n  <text x=\"350\" y=\"34\" font-size=\"16\" fill=\"#1e293b\" text-anchor=\"middle\">Attribution fields come in, then get stripped</text>\n\n  <path d=\"M350,119 L 350,131\" fill=\"none\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#arrow)\"/>\n  <path d=\"M350,201 L 350,213\" fill=\"none\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#arrow)\"/>\n  <path d=\"M350,283 L 350,295\" fill=\"none\" stroke=\"#64748b\" stroke-width=\"1.5\" marker-end=\"url(#arrow)\"/>\n\n  <rect x=\"22\" y=\"60\" width=\"656\" height=\"54\" rx=\"6\" fill=\"#dbeafe\" stroke=\"#3b82f6\"/>\n  <text x=\"350\" y=\"82\" font-size=\"12\" fill=\"#1e40af\" text-anchor=\"middle\">Your body carries attribution fields</text>\n  <text x=\"350\" y=\"100\" font-size=\"10\" fill=\"#1e40af\" text-anchor=\"middle\">usage_label · task_id · stage_code · action_code · attempt_no</text>\n\n  <rect x=\"22\" y=\"142\" width=\"656\" height=\"54\" rx=\"6\" fill=\"#fef3c7\" stroke=\"#f59e0b\"/>\n  <text x=\"350\" y=\"164\" font-size=\"12\" fill=\"#b45309\" text-anchor=\"middle\">Tare records them on this call</text>\n  <text x=\"350\" y=\"182\" font-size=\"10\" fill=\"#b45309\" text-anchor=\"middle\">Split by key, model, label, and stage. Without labels you cannot split it later.</text>\n\n  <rect x=\"22\" y=\"224\" width=\"656\" height=\"54\" rx=\"6\" fill=\"#fce7f3\" stroke=\"#ec4899\"/>\n  <text x=\"350\" y=\"246\" font-size=\"12\" fill=\"#9d174d\" text-anchor=\"middle\">Stripped as a batch before the forward</text>\n  <text x=\"350\" y=\"264\" font-size=\"10\" fill=\"#9d174d\" text-anchor=\"middle\">Leave them in and it fails: official OpenAI returns 400 for unknown fields</text>\n\n  <rect x=\"22\" y=\"306\" width=\"656\" height=\"54\" rx=\"6\" fill=\"#d1fae5\" stroke=\"#22c55e\"/>\n  <text x=\"350\" y=\"328\" font-size=\"12\" fill=\"#166534\" text-anchor=\"middle\">Upstream gets the body with the labels removed</text>\n  <text x=\"350\" y=\"346\" font-size=\"10\" fill=\"#166534\" text-anchor=\"middle\">Other fields are translated or passed through. This step does not normalize them.</text>\n\n  <!-- 脚注 -->\n  <text x=\"350\" y=\"390\" font-size=\"10\" fill=\"#64748b\" text-anchor=\"middle\">Why strip: a BYOK channel to api.openai.com would fail every call, and the error would not name the label.</text>\n  <text x=\"350\" y=\"405\" font-size=\"10\" fill=\"#64748b\" text-anchor=\"middle\">models and provider are stripped too, and they are not labels. Video ignores usage_label and keeps no history.</text>\n</svg>\n"}}