x402 Pay
curl --request POST \
--url https://api.agentwallex.com/api/v1/x402/pay \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"agent_id": "agent_abc123",
"target_url": "https://paid-api.example.com/v1/data",
"session_id": "sess_xyz789",
"chain": "eip155:84532"
}
'import requests
url = "https://api.agentwallex.com/api/v1/x402/pay"
payload = {
"agent_id": "agent_abc123",
"target_url": "https://paid-api.example.com/v1/data",
"session_id": "sess_xyz789",
"chain": "eip155:84532"
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
agent_id: 'agent_abc123',
target_url: 'https://paid-api.example.com/v1/data',
session_id: 'sess_xyz789',
chain: 'eip155:84532'
})
};
fetch('https://api.agentwallex.com/api/v1/x402/pay', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.agentwallex.com/api/v1/x402/pay",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'agent_id' => 'agent_abc123',
'target_url' => 'https://paid-api.example.com/v1/data',
'session_id' => 'sess_xyz789',
'chain' => 'eip155:84532'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.agentwallex.com/api/v1/x402/pay"
payload := strings.NewReader("{\n \"agent_id\": \"agent_abc123\",\n \"target_url\": \"https://paid-api.example.com/v1/data\",\n \"session_id\": \"sess_xyz789\",\n \"chain\": \"eip155:84532\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.agentwallex.com/api/v1/x402/pay")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"agent_id\": \"agent_abc123\",\n \"target_url\": \"https://paid-api.example.com/v1/data\",\n \"session_id\": \"sess_xyz789\",\n \"chain\": \"eip155:84532\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.agentwallex.com/api/v1/x402/pay")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent_id\": \"agent_abc123\",\n \"target_url\": \"https://paid-api.example.com/v1/data\",\n \"session_id\": \"sess_xyz789\",\n \"chain\": \"eip155:84532\"\n}"
response = http.request(request)
puts response.read_body{
"ledger_id": "ldg_abc123",
"amount": "0.10",
"fee_amount": "0.002",
"fee_rate": "2.0",
"token": "USDC",
"chain": "eip155:84532",
"status": "completed",
"payment_signature": "base64_encoded_signature..."
}{
"code": "invalid_request",
"type": "invalid_request_error",
"message": "The request body is missing required fields."
}{
"code": "authentication_failed",
"type": "authentication_error",
"message": "The provided API key is invalid or expired."
}{
"code": "insufficient_permissions",
"type": "authorization_error",
"message": "You do not have permission to perform this action."
}{
"code": "rate_limit_exceeded",
"type": "rate_limit_error",
"message": "Too many requests. Please retry after a short delay."
}{
"code": "server_error",
"type": "internal_error",
"message": "An unexpected error occurred. Please try again later."
}x402
x402 Pay
為目標 URL 觸發 x402 付款協商。
POST
/
api
/
v1
/
x402
/
pay
x402 Pay
curl --request POST \
--url https://api.agentwallex.com/api/v1/x402/pay \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"agent_id": "agent_abc123",
"target_url": "https://paid-api.example.com/v1/data",
"session_id": "sess_xyz789",
"chain": "eip155:84532"
}
'import requests
url = "https://api.agentwallex.com/api/v1/x402/pay"
payload = {
"agent_id": "agent_abc123",
"target_url": "https://paid-api.example.com/v1/data",
"session_id": "sess_xyz789",
"chain": "eip155:84532"
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
agent_id: 'agent_abc123',
target_url: 'https://paid-api.example.com/v1/data',
session_id: 'sess_xyz789',
chain: 'eip155:84532'
})
};
fetch('https://api.agentwallex.com/api/v1/x402/pay', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.agentwallex.com/api/v1/x402/pay",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'agent_id' => 'agent_abc123',
'target_url' => 'https://paid-api.example.com/v1/data',
'session_id' => 'sess_xyz789',
'chain' => 'eip155:84532'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.agentwallex.com/api/v1/x402/pay"
payload := strings.NewReader("{\n \"agent_id\": \"agent_abc123\",\n \"target_url\": \"https://paid-api.example.com/v1/data\",\n \"session_id\": \"sess_xyz789\",\n \"chain\": \"eip155:84532\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.agentwallex.com/api/v1/x402/pay")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"agent_id\": \"agent_abc123\",\n \"target_url\": \"https://paid-api.example.com/v1/data\",\n \"session_id\": \"sess_xyz789\",\n \"chain\": \"eip155:84532\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.agentwallex.com/api/v1/x402/pay")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent_id\": \"agent_abc123\",\n \"target_url\": \"https://paid-api.example.com/v1/data\",\n \"session_id\": \"sess_xyz789\",\n \"chain\": \"eip155:84532\"\n}"
response = http.request(request)
puts response.read_body{
"ledger_id": "ldg_abc123",
"amount": "0.10",
"fee_amount": "0.002",
"fee_rate": "2.0",
"token": "USDC",
"chain": "eip155:84532",
"status": "completed",
"payment_signature": "base64_encoded_signature..."
}{
"code": "invalid_request",
"type": "invalid_request_error",
"message": "The request body is missing required fields."
}{
"code": "authentication_failed",
"type": "authentication_error",
"message": "The provided API key is invalid or expired."
}{
"code": "insufficient_permissions",
"type": "authorization_error",
"message": "You do not have permission to perform this action."
}{
"code": "rate_limit_exceeded",
"type": "rate_limit_error",
"message": "Too many requests. Please retry after a short delay."
}{
"code": "server_error",
"type": "internal_error",
"message": "An unexpected error occurred. Please try again later."
}為目標 URL 協商並完成一筆 x402 付款。AgentWallex 會評估代理的策略,透過 MPC 簽署付款,並回傳存取付費資源所需的付款資訊。
請求主體
string
必填
將資助付款的代理。
string
必填
要支付的 x402 啟用 URL(例如
https://paid-api.example.com/v1/data)。string
可選的工作階段 ID,從現有工作階段預算中扣除。請參閱 x402 Sessions。
string
用於付款結算的 CAIP-2 鏈識別碼(例如
eip155:84532)。若省略,則使用代理的預設區塊鏈。回應
顯示 回應欄位
顯示 回應欄位
範例
curl -X POST https://api.agentwallex.com/api/v1/x402/pay \
-H "X-API-Key: awx_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "agent_abc123",
"target_url": "https://paid-api.example.com/v1/data",
"session_id": "sess_xyz789",
"chain": "eip155:84532"
}'
const result = await aw.x402.pay({
agentId: "agent_abc123",
targetUrl: "https://paid-api.example.com/v1/data",
sessionId: "sess_xyz789",
chain: "eip155:84532",
});
result = await aw.x402.pay(
agent_id="agent_abc123",
target_url="https://paid-api.example.com/v1/data",
session_id="sess_xyz789",
chain="eip155:84532",
)
Response
{
"ledger_id": "ldg_abc123",
"amount": "0.10",
"fee_amount": "0.002",
"fee_rate": "2.0",
"token": "USDC",
"chain": "eip155:84532",
"status": "completed",
"payment_signature": "base64_encoded_signature..."
}
相關端點
| 端點 | 說明 |
|---|---|
POST /x402/check | 檢查 URL 是否支援 x402 付款協商 |
POST /x402/facilitator/verify | 驗證付款簽名(供服務供應商使用) |
POST /x402/facilitator/settle | 結算已驗證的付款(供服務供應商使用) |
GET /x402/facilitator/supported | 列出 x402 支援的區塊鏈 |
GET /x402/fees/tiers | 取得當前費率層級表 |
授權
ApiKeyAuthBearerAuth
API key authentication. Keys are prefixed with awx_.
主體
application/json
The agent whose wallet will fund the payment.
The x402-enabled URL to pay for (e.g., https://paid-api.example.com/v1/data).
Optional session ID to deduct from an existing session budget.
CAIP-2 chain identifier for payment settlement (e.g., eip155:84532). If omitted, the agent's default chain is used.
回應
Payment completed successfully.
Result of an x402 payment negotiation.
Internal ledger entry ID for this payment.
Payment amount.
Platform fee deducted.
Fee percentage applied (based on tiered pricing).
Token used for payment (e.g., USDC).
Chain used for settlement.
Payment status.
可用選項:
completed, pending, failed The PAYMENT-SIGNATURE value to include in the retry request to the target URL.
⌘I