Skip to content

Commit 8b31fe0

Browse files
committed
return X-budget header for x402scan to recognise and support POST for /acp-budget
1 parent 377a6d9 commit 8b31fe0

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

examples/python/clients/httpx/extensible.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def main():
3434
budget = "$0.01" # ⭐ Your budget
3535
print(f"Making request to {endpoint_path} with budget: {budget}")
3636

37-
response = await client.get(
37+
response = await client.post(
3838
endpoint_path,
3939
headers={"X-Budget": budget} # ⭐ Dynamic pricing
4040
)

examples/python/servers/fastapi/main.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dotenv import load_dotenv
55
from fastapi import FastAPI, Request
66
from x402.fastapi.middleware import require_payment
7-
from x402.types import EIP712Domain, TokenAmount, TokenAsset
7+
from x402.types import EIP712Domain, TokenAmount, TokenAsset, HTTPInputSchema
88
from cdp.auth import generate_jwt, JwtOptions
99

1010
# Configure logging
@@ -114,6 +114,17 @@ async def dynamic_price_middleware(request: Request, call_next):
114114
facilitator_config=facilitator_config,
115115
description=f"acp job budget ({budget})",
116116
mime_type="application/json",
117+
# ⭐ Define input schema for x402scan registration
118+
input_schema=HTTPInputSchema(
119+
header_fields={
120+
"X-Budget": {
121+
"type": "string",
122+
"required": False,
123+
"description": "Optional budget amount in USD (e.g., $0.01). If not provided, defaults to $0.001",
124+
"example": "$0.01"
125+
}
126+
}
127+
),
117128
)
118129

119130
return await payment_middleware(request, call_next)
@@ -144,15 +155,20 @@ async def health_check():
144155
return {"status": "ok"}
145156

146157

147-
@app.get("/acp-budget")
148-
async def acp_budget() -> Dict[str, Any]:
158+
@app.api_route("/acp-budget", methods=["GET", "POST"])
159+
async def acp_budget(request: Request) -> Dict[str, Any]:
160+
"""
161+
Handle both GET and POST requests for ACP budget payment.
162+
x402scan may use either method depending on the request.
163+
"""
149164
return {
150165
"message": "pay acp job budget",
151166
"token": "acp job payment token",
152167
"protocol": "x402",
153168
"utility": "none",
154169
"vibes": "acp early adopter",
155-
"advice": "not financial advice"
170+
"advice": "not financial advice",
171+
"method": request.method # Show which method was used
156172
}
157173

158174

0 commit comments

Comments
 (0)