LANGUAGE MODELS FOR AGENTS

LLM x402 接入文档

免费发现模型与价格。调用前签署本次费用上限,接收模型回复,最后按实际 token 消耗量结算。

授权上限清晰,按实际消耗结算。

报价根据本次请求的输入估算与最大输出预算计算。最终按实际输入、缓存与输出 token 及本次报价费率计费,适用每次最低收费。

签名确定本次最高付款金额。生成结束后执行结算交易时才实际转账。流式调用先逐步返回文本,最终用量确定后结算;非流式调用完成结算后返回完整回复。

目录价格已是最终计费单价,无需再次打折。新报价使用当前价,已签报价按原报价处理。

查看模型价格 →

1. 发现模型

curl https://api.koinelix.com/v1/models

选择模型 id 及 supported_protocols 中的接口。价格包括 input、cached_input、output,以及适用的 cache_write / long_context 费率。单价单位为 USD / 百万 tokens,按同数值 USDC 结算。

2. 获取本次报价

Chat Completions 的输出上限仅使用 max_completion_tokens;省略时使用服务默认值。传入 max_tokens 或 max_output_tokens 返回 HTTP 400。

curl -i https://api.koinelix.com/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: <unique-request-id>' \
  -d '{
  "model": "<model-id>",
  "messages": [
    {
      "role": "user",
      "content": "Explain your capabilities in two sentences."
    }
  ],
  "max_completion_tokens": 256,
  "stream": false
}'

# HTTP 402 + PAYMENT-REQUIRED: sign the quoted upto limit, then resend.
# Use an id from GET /v1/models.

3. 授权并调用

下载参考客户端 v1.0.0 · EIP-1193 · 无外部依赖 →

解析 PAYMENT-REQUIRED,核对 x402 版本、upto 方案、网络、资产、可信收款方、有效期和金额预算。按需完成 Permit2 代币额度授权,再签署本次调用授权。携带 PAYMENT-SIGNATURE,使用相同正文、路径、Idempotency-Key 与认证身份重发请求。

Permit2 代币额度与单次签名上限分别管理。单次签名约束本次付款,实际结算金额来自最终账单。

4. 接收回复并核查结算

在调用端保存回复。流式或响应中断时,使用原付款凭证查询原调用。处理中采用有界退避;付款状态未知时通过恢复核查原付款,再决定同一任务的后续操作。

POST <original endpoint>
Content-Type: application/json
PAYMENT-SIGNATURE: <original proof>
Idempotency-Key: <original key>
X-Koinelix-Recover-Only: true

<identical original request body>

从恢复结果读取 execution、usage、payment、delivery、amount 和 tx_hash。payment=settled 表示平台已核验结算。请求变更时重新报价;未执行的报价过期后,先核查原调用,再获取新报价。

给 Agent 一个接入入口

Read https://koinelix.com/agents.md and discover models at https://api.koinelix.com/v1/models.
Choose a model and supported protocol for my task.
Catalog pricing already contains final billable rates; do not apply another discount. Billing uses actual usage at the quoted rates, subject to minimum_charge_usdc. New quotes use current rates; signed quotes keep their quoted rates.
For Chat Completions, use only max_completion_tokens for the output limit; max_tokens and max_output_tokens are rejected with HTTP 400.
Use x402 v2 upto / Permit2. Check the quoted network, asset, trusted payee and my spending budget before signing.
Preserve the exact request body, path, identity, idempotency key and payment proof.
Receive the response and settle by actual token usage.
For pending or unknown outcomes, recover the original call with X-Koinelix-Recover-Only: true and the original authorization; query with bounded backoff.
Confirm payment=settled and the transaction receipt before treating payment as complete.

发现入口:/agents.md · /llms.txt · /openapi.json · /.well-known/x402