= os.getenv("FEWSATS_API_KEY")
k = Fewsats(api_key=k)
fs = os.getenv("FEWSATS_LOCAL_API_KEY")
k = Fewsats(api_key=k, base_url="http://localhost:8000")
fs
test_eq(fs.api_key, k)"Authorization"], f"Token {k}") test_eq(fs._httpx_client.headers[
client
Class
The Fewsats
class handles authentication and provides the foundation for our API interactions.
Fewsats
Fewsats (api_key:str=None, base_url:str='https://api.fewsats.com')
Initialize self. See help(type(self)) for accurate signature.
Type | Default | Details | |
---|---|---|---|
api_key | str | None | The API key for the Fewsats account |
base_url | str | https://api.fewsats.com | The Fewsats API base URL |
Methods
User & Billing Info
Fewsats.me
Fewsats.me ()
Retrieve the user’s info.
= fs.me()
r r.status_code, r.json()
(200,
{'name': 'Pol',
'last_name': 'Alvarez Vecino',
'email': 'pol@fewsats.com',
'id': 1,
'created_at': '2024-08-20T16:13:01.255Z',
'webhook_secret': 'whsec_Kgsdk1xApAOSBcpXViSMNp_MMCRwfNWngoxqotZMHUw',
'test_webhook_secret': 'whsec_Nk997GrUMG9rwEmlef7jlMCMfz2th3chUHtRBkcScIU',
'webhooks': [{'id': 4, 'url': 'https://example.com', 'is_test': False},
{'id': 8, 'url': 'https://example.com/webhook', 'is_test': False}],
'test_webhooks': [],
'require_billing_info': False})
Fewsats.billing_info
Fewsats.billing_info ()
Retrieve the user’s billing info.
= fs.billing_info()
billing_info billing_info.status_code, billing_info.json()
(200,
{'full_name': 'Test Name 2',
'company_name': '',
'vat_number': None,
'address': 'Fake Street 123',
'address_line2': '',
'city': 'Crystal City',
'state': '',
'postal_code': '3129',
'country': 'US',
'phone': None,
'email': 'pol@fewsats.com'})
Balance
Fewsats.balance
Fewsats.balance ()
Retrieve the balance of the user’s wallet. Amounts are always in USD cents.
= fs.balance()
r r.status_code, r.json()
(200, [{'id': 1, 'balance': 4394, 'currency': 'usd'}])
Payment Methods
Retrieve the user’s payment methods. Useful for checking which card will be used for purchases.
Fewsats.payment_methods
Fewsats.payment_methods ()
Retrieve the user’s payment methods, raises an exception for error status codes.
= fs.payment_methods()
r = r.json()
payment_methods r.status_code, payment_methods
(200,
[{'id': 1,
'last4': '4242',
'brand': 'visa',
'exp_month': 12,
'exp_year': 2034,
'is_default': False},
{'id': 4,
'last4': '4242',
'brand': 'Visa',
'exp_month': 12,
'exp_year': 2034,
'is_default': True}])
assert isinstance(payment_methods, list)
Preview a Purchase
Preview the resulting state of a purchase. Useful, for example, to check if a CC charge is needed or the purchase will use the balance.
= fs._preview_payment(amount="300") # 3.00 USD
r = r.json()
preview = preview r.status_code
Create offers
How to use the client to generate L402 offers
Fewsats.create_offers
Fewsats.create_offers (offers:List[Dict[str,Any]])
Create offers for L402 payment server
Type | Details | |
---|---|---|
offers | List | List of offer objects following OfferCreateV0 schema |
Returns | dict |
= [{
test_offers "id": "test_offer_2",
"amount": 1,
"currency": "usd" ,
"description": "Test offer",
"title": "Test Package",
"payment_methods": ["lightning", "credit_card"]
}]
= fs.create_offers(test_offers)
r = r.json()
l402_offers r.status_code, l402_offers
(200,
{'offers': [{'id': 'test_offer_2',
'amount': 1,
'currency': 'usd',
'description': 'Test offer',
'title': 'Test Package',
'payment_methods': ['lightning', 'credit_card'],
'type': 'one-off'}],
'payment_context_token': '6313116c-02e7-4631-adbf-60bdebfb3813',
'payment_request_url': 'http://localhost:8000/v0/l402/payment-request',
'version': '0.2.2',
'requires_billing_information': False})
Get Payment Details
Get payment details is a convenience method for buyers to retrieve the payment information like stripe checkout url, lightning invoice etc… It does not need to be used by vendors. We demonstrate it here to showcase how an offer generated by a vendor can be turned into actual payments details.
Fewsats.get_payment_details
Fewsats.get_payment_details (payment_request_url:str, offer_id:str, payment_method:str, payment_context_token:str)
Gets payment details for a specific offer. Use this as buyer when you want to make the payment manually.
Type | Details | |
---|---|---|
payment_request_url | str | The payment request URL |
offer_id | str | The offer ID |
payment_method | str | The payment method (lightning, credit_card, …) |
payment_context_token | str | The payment context token |
Returns | dict |
= fs.get_payment_details(l402_offers["payment_request_url"], l402_offers["offers"][0]["id"], "lightning", l402_offers["payment_context_token"])
r = r.json()
payment_details = payment_details["payment_request"]['lightning_invoice']
ln_invoice r.status_code, payment_details
(200,
{'expires_at': '2025-06-07T08:21:36.307064+00:00',
'offer_id': 'test_offer_2',
'payment_request': {'lightning_invoice': 'lnbc90n1p5y8mjapp59c04hdtct2dh0cfl0dact08z54r5s6668wupqyj4euww24qzg0jqdq523jhxapq2pskx6mpvajscqzpgxqrzpnrzjqwghf7zxvfkxq5a6sr65g0gdkv768p83mhsnt0msszapamzx2qvuxqqqqz99gpz55yqqqqqqqqqqqqqq9qrzjq25carzepgd4vqsyn44jrk85ezrpju92xyrk9apw4cdjh6yrwt5jgqqqqz99gpz55yqqqqqqqqqqqqqq9qsp5krldkefcmj5e5lgqr3tgkut39zj0cmweynyha73v5zduu8j84v0q9qxpqysgqz7zhunh3xcxgykhdu87hdy36du2kr7pyls9z6uz0jqac0sn3gym39g7s8gk6zdt75u04e42zjstptyxltwyfy7tlmkjh5px36m2deugp72qjup'},
'version': '0.2.2'})
Get Payment Status
Fewsats.get_payment_status
Fewsats.get_payment_status (payment_context_token:str)
Gets the status of a submitted payment. Vendors should use this to check if anyone has paid for their offer associated with the token.
Type | Details | |
---|---|---|
payment_context_token | str | The payment context token |
Returns | dict |
= fs.get_payment_status(l402_offers["payment_context_token"])
r r.status_code, r.json()
(200,
{'payment_context_token': '6313116c-02e7-4631-adbf-60bdebfb3813',
'status': 'pending',
'offer_id': None,
'paid_at': None,
'amount': None,
'currency': None})
Webhooks
Use this as a vendor to get notified when someone pays for your offer. Currently only 1 webhook is supported per user.
Fewsats.add_webhook
Fewsats.add_webhook (webhook_url:str)
Add a URL to the list of webhooks that will receive notifications when you receive a payment. The webhook will be triggered for every successful payment.
= fs.add_webhook("https://example.com")
r r, r.json()
(<Response [200 OK]>,
{'id': 4, 'url': 'https://example.com', 'is_test': False})
To verify and parse a webhook that comes from Fewsats you can use this utility
Fewsats.verify_webhook
Fewsats.verify_webhook (data:bytes, signature:str, webhook_secret:str)
Verify and parse a webhook that comes from Fewsats Args: data: bytes signature: str webhook_secret: str Returns: FewsatsWebhookEvent
FewsatsWebhookEvent
FewsatsWebhookEvent (offer_id:str, payment_context_token:str, amount:int, currency:str, status:str, timestamp:str)
= bytes(json.dumps({
data "offer_id": "offer-501040",
"payment_context_token": "a0b1caf3-3e3b-488f-ae9c-18d64f690894",
"amount": 812319,
"currency": "USD",
"status": "failed",
"timestamp": "2025-04-16T08:51:12Z"
=True, separators=(',', ':')), "utf-8")
}, sort_keys= "t=1744793472,v1=89a491b8f3f8e72b75896faa24cb1cfade27bea12bbdfe333759809b8a573ad3"
signature
= Fewsats.verify_webhook(data, signature, "whsec_bIi4m3by9sJ_KNfY5PFWb2YmAqm2WVAvwq5wGuphayE")
event event
FewsatsWebhookEvent(offer_id='offer-501040', payment_context_token='a0b1caf3-3e3b-488f-ae9c-18d64f690894', amount=812319, currency='USD', status='failed', timestamp='2025-04-16T08:51:12Z')
Pay Methods
Pay Lightning Invoice
Pay lightning invoice is a low-level method to manually pay for a lightning invoice.
Fewsats.pay_lightning
Fewsats.pay_lightning (invoice:str, amount:int, currency:str='usd', description:str='')
Pay for a lightning invoice directly.
Type | Default | Details | |
---|---|---|---|
invoice | str | lightning invoice | |
amount | int | amount in cents | |
currency | str | usd | currency |
description | str | description of the payment |
= fs.pay_lightning(invoice=ln_invoice,
r ="fewsats webhook trial", amount=1)
description= r.json()
lightning_payment r.status_code, lightning_payment
(200,
{'id': 'fb2b35e8-e435-42c0-903e-82e7585d9b76',
'created_at': '2025-06-07T07:46:38.320Z',
'status': 'success',
'payment_request_url': '',
'payment_context_token': '',
'invoice': 'lnbc90n1p5y8mjapp59c04hdtct2dh0cfl0dact08z54r5s6668wupqyj4euww24qzg0jqdq523jhxapq2pskx6mpvajscqzpgxqrzpnrzjqwghf7zxvfkxq5a6sr65g0gdkv768p83mhsnt0msszapamzx2qvuxqqqqz99gpz55yqqqqqqqqqqqqqq9qrzjq25carzepgd4vqsyn44jrk85ezrpju92xyrk9apw4cdjh6yrwt5jgqqqqz99gpz55yqqqqqqqqqqqqqq9qsp5krldkefcmj5e5lgqr3tgkut39zj0cmweynyha73v5zduu8j84v0q9qxpqysgqz7zhunh3xcxgykhdu87hdy36du2kr7pyls9z6uz0jqac0sn3gym39g7s8gk6zdt75u04e42zjstptyxltwyfy7tlmkjh5px36m2deugp72qjup',
'preimage': 'a636f6d854c8412e9ccf5adb558968044436bb1e899f1e116fca8e07dbb5d32d',
'amount': 1,
'currency': 'usd',
'payment_method': 'lightning',
'title': '',
'description': 'fewsats webhook trial',
'type': '',
'is_test': False})
= fs.pay_lightning(invoice='lnbc100n1p5qlv5dpp5r4jjrenyvlndnr59nx2fgk8azyeaaxzpeuy7putgm07wfnvt398qdqqcqzzsxqrrsssp54897npsmum0av3qqj6jyvl3sks4hlc67ugdyr8x85hla79u262uq9qxpqysgq3m9p2a8j7fy2pxeg5xuhyw4zwwp6md5egkez28afffmsch2l7clhw5922mxlr52gp48w0pdvnngytgj08kn4z8uv25pq7fc0mxhrs6qphe3c0k',
r ="fewsats webhook trial", amount=1)
description r.status_code, r.text
(400,
'{"detail": "An error occurred while paying the L402 invoice. Reason: The invoice has expired."}')
Paying L402 Offers
The pay method pays for a specific offer. The user is not required to fetch the payment details beforehand. It is asynchronous and returns the payment_id
and status
. Using the payment_id
we can check the status of the payment.
There are two versions of the pay offer. One accepts the L402 offers as a string, which is more convenient for text-based AI agents like LLMs. The other accepts either the L402Offers
custom class - supported by some libraries like Claudette - or a simple Dict
.
L402Offers
L402Offers (offers:List[__main__.Offer], payment_context_token:str, payment_request_url:str, version:str)
Represents the complete L402 offers schema
Offer
Offer (id:str, amount:int, currency:str, description:str, title:str, payment_methods:List[str]=None, type:str='one-off')
Represents a single L402 offer
= L402Offers.from_dict(l402_offers)
l402 l402
L402 Offers:
- Test Package (0.01 usd)
Payment URL: http://localhost:8000/v0/l402/payment-request
Context Token: 6313116c-02e7-4631-adbf-60bdebfb3813
# we make sure that invalid offers fail
= {
invalid_json 'offers': [{'id': 'test_offer_2', 'amount': 1}], # Missing fields
'payment_context_token': '60a8e027-8b8b-4ccf-b2b9-380ed0930283'
# Missing payment_request_url
}lambda: Offer(id="test", amount=1),
test_fail(="missing 3 required positional arguments: 'currency', 'description', and 'title'") contains
Pay L402 Offer
Fewsats.pay_offer
Fewsats.pay_offer (offer_id:str, l402_offer:__main__.L402Offers)
Pays an offer_id from the l402_offers. The l402_offer parameter must be a dictionary with this structure: { ‘offers’: [ { ‘id’: ‘test_offer_2’, # String identifier for the offer ‘amount’: 1, # USD cents ‘currency’: ‘usd’, # Currency code ‘description’: ‘Test offer’, # Text description ‘title’: ‘Test Package’ # Title of the package } ], ‘payment_context_token’: ‘token’, # Payment context token ‘payment_request_url’: ‘https://api.fewsats.com/v0/l402/payment-request’, # Payment URL ‘version’: ‘0.2.2’ # API version } Returns payment status response
Type | Details | |
---|---|---|
offer_id | str | the offer id to pay for |
l402_offer | L402Offers | a dictionary containing L402 offers |
Returns | dict | payment status response |
= l402.offers[0].id
offer_id = fs.pay_offer(offer_id, l402)
r = r.json()
payment_response r.status_code, payment_response
(200,
{'id': '0d73aed1-6823-4eca-97d4-384fa9430b13',
'created_at': '2025-06-07T07:46:42.106Z',
'status': 'success',
'payment_method': 'lightning'})
L402 Pay Offer with JSON string
This alternative method accepts a JSON string containing L402 offers. It should be used by systems that do not support custom classes in tool calling.
Fewsats.pay_offer_str
Fewsats.pay_offer_str (offer_id:str, l402_offer:str)
*Pays an offer_id from the l402_offers.
The l402_offer parameter must be a JSON string with this structure: { ‘offers’: [ { ‘id’: ‘test_offer_2’, # String identifier for the offer ‘amount’: 1, # Numeric cost value ‘currency’: ‘usd’, # Currency code ‘description’: ‘Test offer’, # Text description ‘title’: ‘Test Package’ # Title of the package } ], ‘payment_context_token’: ‘60a8e027-8b8b-4ccf-b2b9-380ed0930283’, # Payment context token ‘payment_request_url’: ‘https://api.fewsats.com/v0/l402/payment-request’, # Payment URL ‘version’: ‘0.2.2’ # API version }
Returns payment status response*
Type | Details | |
---|---|---|
offer_id | str | the offer id to pay for |
l402_offer | str | JSON string containing L402 offers |
Returns | dict | payment status response |
= fs.pay_offer_str(l402_offers["offers"][0]["id"], json.dumps(l402_offers))
r r.status_code, r.json()
(400,
{'detail': "Invalid payment request received. Payment context token '6313116c-02e7-4631-adbf-60bdebfb3813' already used"})
Pay Link
Fewsats.pay_link
Fewsats.pay_link (url:str, description:str, price:int, payment_method:str='credit_card', title:str='Purchase from URL')
*Creates a purchase record for an external URL.
Args: url: The URL to purchase from description: Description of the purchase price: Price in USD cents payment_method: Payment method to use (default: credit_card) title: Title of the purchase (default: “Purchase from URL”)
Returns: Payment status response containing information about the purchase*
Type | Default | Details | |
---|---|---|---|
url | str | URL to purchase from | |
description | str | Description of the purchase | |
price | int | Price in USD cents | |
payment_method | str | credit_card | Payment method (credit_card, lightning, etc.) |
title | str | Purchase from URL | Title of the purchase |
Returns | dict | payment status response |
= "https://www.amazon.com/Matter-Culture-Iain-M-Banks/dp/0316005371"
url = fs.pay_link(url, "Matter (Culture)", 629)
r r.status_code, r.text
(200,
'{"id": "cee2ded1-37c8-4832-b6f9-0be5d29e599b", "created_at": "2025-06-07T07:46:42.209Z", "status": "pending", "payment_method": "credit_card"}')
Payment Info
As a buyer, we can check the status of a payment as follows:
Fewsats.payment_info
Fewsats.payment_info (pid:str)
Retrieve the details of a payment.
Type | Details | |
---|---|---|
pid | str | purchase id |
= fs.payment_info(payment_response['id'])
r r.status_code, r.json()
(200,
{'id': '0d73aed1-6823-4eca-97d4-384fa9430b13',
'created_at': '2025-06-07T07:46:42.106Z',
'status': 'success',
'payment_request_url': '',
'payment_context_token': '6313116c-02e7-4631-adbf-60bdebfb3813',
'invoice': '',
'preimage': '',
'amount': 1,
'currency': 'usd',
'payment_method': 'lightning',
'title': 'Test Package',
'description': 'Test offer',
'type': 'one-off',
'is_test': False})
Pay X402 Offer
Fewsats.pay_x402_offer
Fewsats.pay_x402_offer (payload:Dict[str,Any], chain:str='base')
*Creates a payment from an x402 offer and returns a payment header to access the resource.
Args: payload: The x402 offer payload containing accepts, error, and x402Version chain: Blockchain chain to use (default: “base”)
Returns: Dictionary containing payment_header to use for subsequent requests*
Type | Default | Details | |
---|---|---|---|
payload | Dict | The x402 offer payload | |
chain | str | base | Blockchain chain to use |
Returns | dict |
= {
x402_offer "accepts": [
{"scheme": "exact",
"network": "base",
"maxAmountRequired": "1",
"resource": "https://proxy402.com/L27XYy_NCU",
"description": "Payment for GET https://proxy402.com/L27XYy_NCU",
"mimeType": "",
"payTo": "0xddb24Bd8A6Cb0f2d3eaBF7a828C0b4364668B963",
"maxTimeoutSeconds": 300,
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"extra": {
"name": "USD Coin",
"version": "2"
}
}
],"error": "X-PAYMENT header is required",
"x402Version": 1
}
= fs.pay_x402_offer(x402_offer, chain="base")
r r.status_code, r.json()
(200,
{'payment_header': 'eyJ4NDAyVmVyc2lvbiI6IDEsICJzY2hlbWUiOiAiZXhhY3QiLCAibmV0d29yayI6ICJiYXNlIiwgInBheWxvYWQiOiB7InNpZ25hdHVyZSI6ICIweDM3OGUxNmI4YzA2NDU5NmZiYmIwYTNkNDBjYzIzZDQ4ZjQ3YWI4ZjY1YjM4NDkwMzE1NmNjZDQ3NWM5YWEwNWQwOTMyNTgzNGFkNzcwNTEzMDM2Yjg0MDQ4ZmQ0NjE0ZWU3MTFmYTcyNGE0YjE1Yzk3MzlmNzUzNTc5NGNmNGQ1MWIiLCAiYXV0aG9yaXphdGlvbiI6IHsiZnJvbSI6ICIweDJGQjI3Yzg0Njk5MkNjODk1MDlENzQzNDhGOEQ2YmVjM2VkNmE3NDAiLCAidG8iOiAiMHhkZGIyNEJkOEE2Q2IwZjJkM2VhQkY3YTgyOEMwYjQzNjQ2NjhCOTYzIiwgInZhbHVlIjogIjEiLCAidmFsaWRBZnRlciI6ICIxNzQ5MjgyMzQzIiwgInZhbGlkQmVmb3JlIjogIjE3NDkyODI3MDMiLCAibm9uY2UiOiAiMHgxNDU4MmFkMzg4MmU3ZjY2MzJiOTE5NzY1MjQ1YjkwNmYyMmVkOWRmZTRjOGYxOWNlY2IyOTM5ODJiZGM5OGViIn19fQ=='})
"accepts"][0]["resource"], headers={"X-PAYMENT": r.json()["payment_header"]}) httpx.get(x402_offer[
<Response [402 Payment Required]>
Pay X402 Link
Fewsats.pay_x402_link
Fewsats.pay_x402_link (url:str, method:str='GET', body:Dict[str,Any]=None, headers:Dict[str,str]=None, chain:str='base')
*Creates a purchase from an external URL that requires x402 payment.
Args: url: The URL to purchase from method: HTTP method to use (default: “GET”) body: Optional request body headers: Optional request headers chain: Blockchain chain to use (default: “base”)
Returns: The response from the target URL after successful payment*
Type | Default | Details | |
---|---|---|---|
url | str | URL to purchase from | |
method | str | GET | HTTP method to use |
body | Dict | None | Optional request body |
headers | Dict | None | Optional request headers |
chain | str | base | Blockchain chain to use |
Returns | dict |
= "https://proxy402.com/KQzW9kfi3Z"
x402_link = fs.pay_x402_link(x402_link, chain="base-sepolia")
r r.status_code, r.json()
(400,
{'detail': '{"accepts":[{"scheme":"exact","network":"base-sepolia","maxAmountRequired":"1","resource":"https://proxy402.com/KQzW9kfi3Z","description":"Payment for GET https://proxy402.com/KQzW9kfi3Z","mimeType":"","payTo":"0xddb24Bd8A6Cb0f2d3eaBF7a828C0b4364668B963","maxTimeoutSeconds":300,"asset":"0x036CbD53842c5426634e7929541eC2318f3dCF7e","extra":{"name":"USDC","version":"2"}}],"error":"insufficient_funds","x402Version":1}'})
As tools
Fewsats.as_tools
Fewsats.as_tools ()
Return list of available tools for AI agents
wrap_with_response
wrap_with_response (method)
Wraps a method to return (status_code, text) instead of a Response object
get_response
get_response (r)
fs.as_tools()
[<function __main__.Fewsats.me()>,
<function __main__.Fewsats.balance()>,
<function __main__.Fewsats.payment_methods() -> List[Dict[str, Any]]>,
<function __main__.Fewsats.pay_offer_str(offer_id: str, l402_offer: str) -> dict>,
<function __main__.Fewsats.payment_info(pid: str)>]
Both the preview and purchase methods automatically use the default payment method if a charge is needed. This client provides a straightforward way to interact with the Fewsats API, making it easy for developers to integrate Fewsats functionality into their applications.
Agent Demo
We will use Claudette to demonstrate how to pay for content using the Fewsats API.
from claudette import Chat, models
= models[1]
model model
'claude-3-5-sonnet-20240620'
fs.balance().json()
[{'id': 1, 'balance': 4391, 'currency': 'usd'}]
# let's create a payable offer
= [{
test_offers "id": "test_offer_2",
"amount": 1,
"currency": "usd" ,
"description": "Test offer",
"title": "Test Package",
"payment_methods": ["lightning", "credit_card"]
}]
= fs.create_offers(test_offers).json() l402_offers
= Chat(model, sp='You are a helpful assistant that can pay offers.', tools=fs.as_tools())
chat = f"Could you pay the cheapest offer in {l402_offers}?"
pr = chat.toolloop(pr, trace_func=print)
r r
Message(id='msg_01KdaFDdJZ9dfd31pvS8LAs9', content=[TextBlock(text="Certainly! I'll analyze the offer information you've provided and pay for the cheapest offer. In this case, there's only one offer available, so that will be the one we'll pay for. Let's proceed with the payment using the `pay_offer_str` function.", type='text'), ToolUseBlock(id='toolu_01Acq5XLUhLBEJNXALXxDUM6', input={'offer_id': 'test_offer_2', 'l402_offer': '{"offers": [{"id": "test_offer_2", "amount": 1, "currency": "usd", "description": "Test offer", "title": "Test Package", "payment_methods": ["lightning", "credit_card"], "type": "one-off"}], "payment_context_token": "584b71d6-b022-4309-8be6-809e2d7041df", "payment_request_url": "http://localhost:8000/v0/l402/payment-request", "version": "0.2.2", "requires_billing_information": false}'}, name='pay_offer_str', type='tool_use')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 1043; Out: 278; Cache create: 0; Cache read: 0; Total: 1321)
Message(id='msg_01U7opTNJdzU3afvCgveygUg', content=[TextBlock(text="Great news! The payment for the offer has been successfully processed. Here's a summary of the transaction:\n\n1. Offer ID: test_offer_2\n2. Amount: 1 USD cent (0.01 USD)\n3. Title: Test Package\n4. Description: Test offer\n5. Payment ID: 0e22ebf3-951a-4d0f-b08a-f778950e21e0\n6. Payment Status: Success\n7. Payment Method: Lightning\n8. Transaction Date: June 7, 2025, at 07:46:51 UTC\n\nThe payment was completed successfully using the Lightning network. Is there anything else you would like to know about this transaction or any other assistance you need?", type='text')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 1403; Out: 168; Cache create: 0; Cache read: 0; Total: 1571)
Great news! The payment for the offer has been successfully processed. Here’s a summary of the transaction:
- Offer ID: test_offer_2
- Amount: 1 USD cent (0.01 USD)
- Title: Test Package
- Description: Test offer
- Payment ID: 0e22ebf3-951a-4d0f-b08a-f778950e21e0
- Payment Status: Success
- Payment Method: Lightning
- Transaction Date: June 7, 2025, at 07:46:51 UTC
The payment was completed successfully using the Lightning network. Is there anything else you would like to know about this transaction or any other assistance you need?
- id:
msg_01U7opTNJdzU3afvCgveygUg
- content:
[{'text': "Great news! The payment for the offer has been successfully processed. Here's a summary of the transaction:\n\n1. Offer ID: test_offer_2\n2. Amount: 1 USD cent (0.01 USD)\n3. Title: Test Package\n4. Description: Test offer\n5. Payment ID: 0e22ebf3-951a-4d0f-b08a-f778950e21e0\n6. Payment Status: Success\n7. Payment Method: Lightning\n8. Transaction Date: June 7, 2025, at 07:46:51 UTC\n\nThe payment was completed successfully using the Lightning network. Is there anything else you would like to know about this transaction or any other assistance you need?", 'type': 'text'}]
- model:
claude-3-5-sonnet-20240620
- role:
assistant
- stop_reason:
end_turn
- stop_sequence:
None
- type:
message
- usage:
{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 1403, 'output_tokens': 168, 'service_tier': 'standard'}
chat.h
[{'role': 'user',
'content': [{'type': 'text',
'text': "Could you pay the cheapest offer in {'offers': [{'id': 'test_offer_2', 'amount': 1, 'currency': 'usd', 'description': 'Test offer', 'title': 'Test Package', 'payment_methods': ['lightning', 'credit_card'], 'type': 'one-off'}], 'payment_context_token': '584b71d6-b022-4309-8be6-809e2d7041df', 'payment_request_url': 'http://localhost:8000/v0/l402/payment-request', 'version': '0.2.2', 'requires_billing_information': False}?"}]},
{'role': 'assistant',
'content': [TextBlock(text="Certainly! I'll analyze the offer information you've provided and pay for the cheapest offer. In this case, there's only one offer available, so that will be the one we'll pay for. Let's proceed with the payment using the `pay_offer_str` function.", type='text'),
ToolUseBlock(id='toolu_01Acq5XLUhLBEJNXALXxDUM6', input={'offer_id': 'test_offer_2', 'l402_offer': '{"offers": [{"id": "test_offer_2", "amount": 1, "currency": "usd", "description": "Test offer", "title": "Test Package", "payment_methods": ["lightning", "credit_card"], "type": "one-off"}], "payment_context_token": "584b71d6-b022-4309-8be6-809e2d7041df", "payment_request_url": "http://localhost:8000/v0/l402/payment-request", "version": "0.2.2", "requires_billing_information": false}'}, name='pay_offer_str', type='tool_use')]},
{'role': 'user',
'content': [{'type': 'tool_result',
'tool_use_id': 'toolu_01Acq5XLUhLBEJNXALXxDUM6',
'content': '(200, \'{"id": "0e22ebf3-951a-4d0f-b08a-f778950e21e0", "created_at": "2025-06-07T07:46:51.819Z", "status": "success", "payment_method": "lightning"}\')'}]},
{'role': 'assistant',
'content': [TextBlock(text="Great news! The payment for the offer has been successfully processed. Here's a summary of the transaction:\n\n1. Offer ID: test_offer_2\n2. Amount: 1 USD cent (0.01 USD)\n3. Title: Test Package\n4. Description: Test offer\n5. Payment ID: 0e22ebf3-951a-4d0f-b08a-f778950e21e0\n6. Payment Status: Success\n7. Payment Method: Lightning\n8. Transaction Date: June 7, 2025, at 07:46:51 UTC\n\nThe payment was completed successfully using the Lightning network. Is there anything else you would like to know about this transaction or any other assistance you need?", type='text')]}]