# 由 openapi/scripts/generate.php 生成,请勿手改;补充写到 overrides/v3-agent-charges.yaml post: summary: 为一次提问扣费(幂等) tags: - agent-charges operationId: post_api_v3_agent_charges description: |- 一次提问开始前由 agent 服务调用。先扣今日赠送,不够再扣积分余额;合计不够返回 402 (`type` 为 quota-exceeded,扩展字段 `reason`:insufficient 积分不足 / ip_cap 游客同 IP 超上限, 另带 `cost`、`free_remaining`、`earned_balance`)。 账号口径与 `POST /v3/agent-traces` 相同:Bearer 是透传的终端用户 token, 无效或缺省按游客算,此时 `device_id` 必填。按 run_id 幂等:首次 201,重复 200。 服务端出错、回答没生成时,写研究过程那一步会自动退回。 实现:`V3\AgentChargeController@store` security: - { } - bearerAuth: [] requestBody: required: true content: application/json: schema: type: object properties: run_id: type: string description: 'AG-UI runId(uuid)' thread_id: type: string description: 'AG-UI threadId(uuid)。已经属于别的账号时 403,不扣费' deep: type: boolean description: 是否深度思考(价格不同) default: false device_id: type: string description: '设备匿名 id(uuid)。游客必填' client_ip: type: string description: '客户端 IP(runtime 写入)。游客必填,没有就 422;只对游客用于同 IP 上限' required: - run_id responses: 200: description: 成功 content: application/json: schema: type: object properties: data: type: object properties: run_id: type: string cost: type: integer charged_free: type: integer charged_earned: type: integer free_remaining: type: integer earned_balance: type: integer policy_version: type: integer 201: description: '首次扣费。响应体与 200 同形' content: application/json: schema: type: object properties: data: type: object properties: run_id: type: string cost: type: integer charged_free: type: integer charged_earned: type: integer free_remaining: type: integer earned_balance: type: integer policy_version: type: integer 401: $ref: '../../main.yaml#/components/responses/ProblemUnauthorized' 402: description: '额度不足或游客同 IP 超上限' content: application/problem+json: schema: $ref: '../../main.yaml#/components/schemas/ProblemDetails' 403: description: 'thread_id 已经属于别的账号' content: application/problem+json: schema: $ref: '../../main.yaml#/components/schemas/ProblemDetails' 422: $ref: '../../main.yaml#/components/responses/ProblemValidation'