- AgentCore CLI
-
에이전트가 결제 기능이 구성된 상태로 배포된 경우 결제 컨텍스트로 에이전트를 호출하면 x402 인터셉터가 결제 처리를 자동으로 처리합니다.
agentcore invoke \
--prompt "Access the premium endpoint at https://example-x402-merchant.com/paid-api" \
--payment-instrument-id <INSTRUMENT_ID> \
--auto-session \
--payment-user-id user@example.com
명시적 세션을 자동 생성하는 대신 사용하려면:
agentcore invoke \
--prompt "Access the premium endpoint at https://example-x402-merchant.com/paid-api" \
--payment-instrument-id <INSTRUMENT_ID> \
--payment-session-id <SESSION_ID> \
--payment-user-id user@example.com
배포된 에이전트의 x402 플러그인은 HTTP 402 응답을 가로채고,를 호출하고ProcessPayment, 증거로 요청을 재시도합니다. AgentCore CLI v0.19.0 이상이 필요합니다.
- AgentCore SDK
-
PaymentManager 클래스를 사용하여 에이전트 프레임워크 내에서 결제 헤더를 수동으로 생성합니다.
import uuid
from bedrock_agentcore.payments import PaymentManager
manager = PaymentManager(
payment_manager_arn=mgr["paymentManagerArn"],
region_name="us-west-2"
)
# When you receive a 402 response, generate payment proof
payment_required_request = {
"statusCode": 402,
"headers": payment_required["headers"],
"body": payment_required["body"],
}
payment_proof_headers = manager.generate_payment_header(
user_id="test-user-123",
payment_instrument_id=instrument["paymentInstrumentId"],
payment_session_id=session["paymentSessionId"],
payment_required_request=payment_required_request,
client_token=str(uuid.uuid4()),
)
payment_proof_headers 에는 결제 증명 헤더가 포함되어 있습니다. 유료 엔드포인트에 대한 요청을 재시도할 때이 헤더를 포함합니다. 입력을 더 잘 제어PaymentManager하려면의 process_payment 메서드를 호출할 수도 있습니다.
- AWS CLI
-
aws bedrock-agentcore process-payment \
--payment-manager-arn "arn:aws:bedrock-agentcore:us-west-2:123456789012:payment-manager/my-manager" \
--payment-session-id "payment-session-abc123" \
--payment-instrument-id "payment-instrument-xyz789" \
--payment-type "CRYPTO_X402" \
--payment-input '{
"cryptoX402": {
"version": "2",
"payload": {
"scheme": "exact",
"network": "eip155:84532",
"amount": "100000",
"asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
"payTo": "0x99935f281d3ED1E804bF1413b76E0B03e1fed4F9",
"maxTimeoutSeconds": 300,
"extra": {"name": "USDC", "version": "2"}
}
}
}' \
--client-token "$(uuidgen)" \
--region us-west-2
- AWS SDK
-
전체 x402 페이로드로 process_payment 직접를 호출합니다.
import uuid
payment = dp_client.process_payment(
userId="test-user-123",
paymentManagerArn=PAYMENT_MANAGER_ARN,
paymentSessionId=SESSION_ID,
paymentInstrumentId=INSTRUMENT_ID,
paymentType="CRYPTO_X402",
paymentInput={
"cryptoX402": {
"version": "2",
"payload": {
"scheme": "exact",
"network": "eip155:84532",
"amount": "100000",
"asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
"payTo": "0x99935f281d3ED1E804bF1413b76E0B03e1fed4F9",
"maxTimeoutSeconds": 300,
"extra": {"name": "USDC", "version": "2"},
},
}
},
clientToken=str(uuid.uuid4()),
)
응답:
{
"processPaymentId": "12345678-1234-1234-1234-123456789012",
"paymentManagerArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:payment-manager/my-manager-a1b2c3d4e5",
"paymentSessionId": "payment-session-abc123def4567",
"paymentInstrumentId": "payment-instrument-xyz789abc1234",
"paymentType": "CRYPTO_X402",
"status": "PROOF_GENERATED",
"paymentOutput": {
"cryptoX402": {
"version": "2",
"payload": {
"...signed transaction proof..."
}
}
},
"createdAt": "2025-07-15T10:35:00Z",
"updatedAt": "2025-07-15T10:35:02Z"
}
status의는 트랜잭션이 서명되었고 암호화 증명이에 포함되어 있음을 PROOF_GENERATED 나타냅니다paymentOutput.
- Strands SDK
-
AgentCore 결제 플러그인은 Strands Agents에 대한 자동 결제 처리를 제공합니다. 에이전트가 HTTP 402 응답을 자동으로 처리할 수 있도록 x402 Payment Required 프로토콜을 지원합니다.
설치:
pip install 'bedrock-agentcore[strands-agents]'
플러그인을 구성하고 사용합니다.
from strands import Agent
from strands_tools import http_request
from bedrock_agentcore.payments.integrations.config import AgentCorePaymentsPluginConfig
from bedrock_agentcore.payments.integrations.strands.plugin import AgentCorePaymentsPlugin
# Configure the plugin
config = AgentCorePaymentsPluginConfig(
payment_manager_arn="arn:aws:bedrock-agentcore:us-west-2:123456789012:payment-manager/pm-abc123",
user_id="test-user-123",
payment_instrument_id="payment-instrument-XJU4RSQP9VO0ler",
payment_session_id="payment-session-xuzrnUCd7RT725G",
region="us-west-2",
)
# Create the plugin
plugin = AgentCorePaymentsPlugin(config=config)
# Create agent with the plugin
agent = Agent(
system_prompt="You are a helpful assistant that can access paid APIs.",
tools=[http_request],
plugins=[plugin],
)
# Use the agent -- 402 responses are automatically handled
agent("access https://drvd12nxpcyd5.cloudfront.net/market-recap")
AgentCore 결제 플러그인은 x402 결제 요청을 자동으로 가로채고, 결제를 처리하고, 에이전트에 대한 결제 증명으로 요청을 재시도합니다.
- LangGraph
-
AgentCore 결제 미들웨어는 LangGraph 에이전트를 위한 자동 결제 처리를 제공합니다. 에이전트가 HTTP 402 응답을 자동으로 처리할 수 있도록 x402 Payment Required 프로토콜을 지원합니다.
설치:
pip install 'bedrock-agentcore[langgraph]'
미들웨어를 구성하고 사용합니다.
from langchain.agents import create_agent
from bedrock_agentcore.payments.integrations.langgraph import (
AgentCorePaymentsConfig,
AgentCorePaymentsMiddleware,
)
config = AgentCorePaymentsConfig(
payment_manager_arn="arn:aws:bedrock-agentcore:us-west-2:123456789012:payment-manager/pm-abc123",
user_id="test-user-123",
payment_instrument_id="payment-instrument-XJU4RSQP9VO0ler",
region="us-west-2",
auto_session=True,
)
payments = AgentCorePaymentsMiddleware(config)
agent = create_agent(
model="us.anthropic.claude-sonnet-4-20250514-v1:0",
tools=[],
middleware=[payments],
)
result = agent.invoke({"messages": [{"role": "user", "content": "access https://drvd12nxpcyd5.cloudfront.net/market-recap"}]})
print(result)
AgentCore 결제 미들웨어는 x402 결제 요청을 자동으로 가로채고, 결제를 처리하고, 에이전트에 대한 결제 증명으로 요청을 재시도합니다.