> For the complete documentation index, see [llms.txt](https://docs.goassay.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.goassay.ai/developers/zh/di-ceng-yuan-li/life-of-a-call.md).

# 一次付费调用的全过程

跟随一次付费工具调用，了解从发现、本地签名、结果检查到收款的过程。

一次付费调用有两个独立结果：智能体收到的结果，以及最终为它收取的资金。本页介绍启用付费调用并充入托管余额后，本地 `assay-mcp` 的处理流程。

## 工作原理

```mermaid
sequenceDiagram
    participant A as AI client
    participant L as Local assay-mcp
    participant S as Assay MCP server
    participant P as Provider and request verifier
    participant V as Assay result checks
    participant E as Escrow contract
    A->>L: Discover a tool and call it
    L->>S: Tool call
    S->>S: Check access, arguments and eligible providers
    S-->>L: Payment request for selected provider
    L->>L: Check guards and sign locally
    L->>S: Same call with signed payment
    S->>S: Validate payment and reserve funds
    S->>P: Mapped, signed provider request
    P->>P: Verify request before serving
    P-->>S: Result
    S->>V: Record result for checks
    S-->>L: Result and receipt, usually VERIFYING
    L-->>A: Result and receipt
    V->>V: Apply the tool's policy
    alt Refund or void
        V->>S: Release reservation, no collection
    else Settle the served call
        V->>S: Allow redemption
        S->>E: Submit signed payment
        E->>E: Move customer balance into payment hold
        alt Timely report upheld
            S->>E: Refund held payment to customer escrow
        else Hold ends without a blocking report
            S->>E: Collect held payment
            E-->>P: Provider share to payout wallet
        end
    end
```

## 一次调用的各个步骤

1. **发现工具。** 智能体读取工具列表，或搜索并阅读工具完整说明。发现结果提供输入结构和价格。URL 与智能体策略决定它能找到什么。
2. **选择提供方。** Assay 验证参数，按访问权限、提供方规则、契约兼容性和付款资格检查可用提供方。在这条付费流程中，它会提出一个提供方，但尚不调用端点。
3. **请求付款许可。** Assay 返回 `PAYMENT_REQUIRED`。请求标明提供方、金额、资产、网络、托管合约、调用身份和付款序号。对于这个未签名的报价，不会调用提供方，也不会预留资金。
4. **本地检查和签名。** `assay-mcp` 将请求与已转发调用、近期报价、内置付款配置、密钥权限和限额核对。它也会检查获准付费 URL、可选提供方限制和所需确认。然后用本地支付密钥签名，以相同幂等键重新发送同一次调用。
5. **预留资金并调用提供方。** Assay 将已签名付款与自行计算的调用核对。重试仍使用先前提出的提供方和契约版本。发出映射后的提供方请求前，先预留金额。普通提供方请求带有 Assay 请求签名；已保存的身份认证请求头会附加到其配置的源站。
6. **认证并处理。** 在签名保护配置下，提供方验证器会在处理函数运行前检查签名、请求体摘要、时间窗口和一次性随机数。提供方返回数据。Assay 对响应分类，并映射为工具承诺的结构。
7. **返回结果并检查。** 可用的映射数据结果会持久记录，供异步检查。初始收据通常为 `VERIFYING`：价格金额被暂扣，尚未最终收费。归因于提供方的输出结构违规可以立即退款。请求或系统错误会作废，不会视为数据质量失败。
8. **应用判定。** 启用执行的失败判定会释放预留，并记录提供方违规。误用的检查会使付款作废，但不记违规。允许结算的决定使已签名付款可以提交上链；合约将资金从客户余额移入付款暂扣。
9. **收款或退款。** 链上暂扣通常从兑付起持续一小时。符合条件的客户问题报告尚未关闭时，Assay 会等待收款；报告被认定成立且暂扣付款仍可退款时，会退款。否则，收款会支付提供方份额和平台费。请使用收据上的提交截止时间：保证可提交报告的窗口在允许收款之前结束。

## 影响集成的细节

| 情况                    | 含义                                  |
| --------------------- | ----------------------------------- |
| 检查期间已收到结果             | 你已获得数据，但最终收费尚未确定。请阅读收据状态。           |
| 已提供服务的调用标记为 `SETTLED` | 服务判定已完成。链上兑付和提供方收款仍可能待处理。           |
| 付款签名窗口到期前未能收款         | 已提供服务的调用可能成为欠款。结清前暂停付费调用；免费调用仍可使用。  |
| 网络超时                  | 不能证明提供方是否运行，也不能证明是否付款。请复用该逻辑操作的幂等键。 |
| 签名重试时提供方已不再合格         | Assay 会拒绝这笔付款，不会悄悄改为向其他提供方付款。       |

图中展示的是向签名保护提供方发出的已签名付费调用。免费调用和仅使用 API 密钥的端点采用不同流程。付款设置见[付费流程](/developers/zh/shi-yong-gong-ju-ru-men/how-paying-works.md)，不确定结果的处理见[重试与幂等](/developers/zh/shi-yong-gong-ju-jin-jie/retries-and-idempotency.md)，提供方身份认证见 [API 密钥还是签名](/developers/zh/shang-jia-ni-de-api-ru-men/api-key-or-signature.md)。

## 延伸阅读

* [访问策略](/developers/zh/shi-yong-gong-ju-jin-jie/access-policy.md)
* [支出限额](/developers/zh/shi-yong-gong-ju-ru-men/spending-limits.md)

## 下一步

* [调用如何被验证](/developers/zh/di-ceng-yuan-li/verification.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.goassay.ai/developers/zh/di-ceng-yuan-li/life-of-a-call.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
