<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/agentcore-payments-middleware-for-langchain-agents-jkmdvl41d" -->

---
title: AgentCore Payments middleware for LangChain agents
description: AWS's AgentCore Payments now ships as LangChain middleware, letting LangChain agents autonomously pay for paid APIs using the x402 protocol with session-level...
canonical: https://daily.dev/posts/agentcore-payments-middleware-for-langchain-agents-jkmdvl41d
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: AgentCore Payments middleware for LangChain agents | daily.dev
og:description: AWS's AgentCore Payments now ships as LangChain middleware, letting LangChain agents autonomously pay for paid APIs using the x402 protocol with session-level...
og:url: https://daily.dev/posts/agentcore-payments-middleware-for-langchain-agents-jkmdvl41d
og:image: https://api.daily.dev/og/posts/JkMDVL41D.png
og:image:alt: AgentCore Payments middleware for LangChain agents
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# AgentCore Payments middleware for LangChain agents

**[LangChain](https://daily.dev/sources/langchain)** · 10 min read · 1 upvotes · 0 comments

## Summary

AWS's AgentCore Payments now ships as LangChain middleware, letting LangChain agents autonomously pay for paid APIs using the x402 protocol with session-level deterministic spending budgets enforced at an infrastructure layer rather than in prompts. The middleware detects HTTP 402 responses, validates the payment against a configured budget, signs it via AgentCore PaymentManager, and retries the request. LangSmith tracing captures the full context around each payment (the task, reasoning, and budget) for governance and audit, and the post covers using single-step, full-turn, and online evals to test agent spending behavior before and after deployment, plus setup instructions including a required strands-agents dependency quirk.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.langchain.com/blog/langchain-agentcore-payments>

## Questions this post answers

### How do I let a LangChain agent pay for a paywalled API automatically?

Add AgentCorePaymentsMiddleware to the agent's middleware list with an AgentCorePaymentsConfig specifying a payment_manager_arn, user_id, payment_instrument_id, and region. When a tool call hits an endpoint returning HTTP 402, the middleware validates the price against a session budget, signs the payment through AgentCore PaymentManager, and retries the request with payment proof, all without changing the agent's own logic.

_Developers wiring payment guardrails into agents can compare middleware approaches like this on daily.dev._

### How can I enforce a spending limit on an autonomous agent's payments?

Set a session budget such as auto_session_budget in the AgentCorePaymentsConfig; the middleware checks every payment request against that ceiling before signing anything. If a charge would exceed the limit, the request is rejected and no payment is signed, and the refusal appears in the agent trace so you can confirm the limit actually held.

_Anyone building spend controls into autonomous agents can track patterns like this on daily.dev._

### What is the x402 protocol and why does it matter for AI agents making payments?

x402 is an HTTP-native micropayment protocol created by Coinbase in May 2025, now stewarded by the Linux Foundation, that lets an agent hit a paid endpoint, receive a price, pay in stablecoins, and get content within a single HTTP request-response cycle. It matters because stablecoin micropayments settle in seconds at fractions of a cent, making per-call pricing viable where card-processing fees make cent-level API charges impossible.

_Teams evaluating agent payment protocols can follow developments like x402 on daily.dev._

## Similar posts on daily.dev

- [Cloudflare and AWS Embed x402 Agent Payments at the Edge](https://daily.dev/posts/cloudflare-and-aws-embed-x402-agent-payments-at-the-edge-vmwjvbzct) · InfoQ · 0 upvotes · 0 comments
- [foojay – a place for friends of OpenJDK](https://daily.dev/posts/foojay-a-place-for-friends-of-openjdk-khskkgtmg) · Foojay.io · 1 upvotes · 0 comments
- [AI agents can browse the web. Now they need a way to pay for it.](https://daily.dev/posts/ai-agents-can-browse-the-web-now-they-need-a-way-to-pay-for-it--xu9muwtef) · The Next Web · 1 upvotes · 0 comments

---

Tags: [#ai-agents](https://daily.dev/tags/ai-agents), [#langchain](https://daily.dev/tags/langchain), [#langsmith](https://daily.dev/tags/langsmith)

[View this post on daily.dev](https://daily.dev/posts/agentcore-payments-middleware-for-langchain-agents-jkmdvl41d)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"AgentCore Payments middleware for LangChain agents","url":"https://daily.dev/posts/agentcore-payments-middleware-for-langchain-agents-jkmdvl41d","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/agentcore-payments-middleware-for-langchain-agents-jkmdvl41d"},"datePublished":"2026-08-17T14:51:16.594Z","dateModified":"2026-09-14T06:18:46.936Z","description":"AWS's AgentCore Payments now ships as LangChain middleware, letting LangChain agents autonomously pay for paid APIs using the x402 protocol with session-level...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/ba674c95201828b6a04b9e9411b3cf01?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/ba674c95201828b6a04b9e9411b3cf01?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"LangChain","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"LangChain","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/0f4f2629e0724a849823f8cd0d913e13","url":"https://daily.dev/sources/langchain"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/agentcore-payments-middleware-for-langchain-agents-jkmdvl41d","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ai-agents,langchain,langsmith","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"LangChain","item":"https://daily.dev/sources/langchain"},{"@type":"ListItem","position":3,"name":"AgentCore Payments middleware for LangChain agents"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/agentcore-payments-middleware-for-langchain-agents-jkmdvl41d#faq","mainEntity":[{"@type":"Question","name":"How do I let a LangChain agent pay for a paywalled API automatically?","acceptedAnswer":{"@type":"Answer","text":"Add AgentCorePaymentsMiddleware to the agent's middleware list with an AgentCorePaymentsConfig specifying a payment_manager_arn, user_id, payment_instrument_id, and region. When a tool call hits an endpoint returning HTTP 402, the middleware validates the price against a session budget, signs the payment through AgentCore PaymentManager, and retries the request with payment proof, all without changing the agent's own logic. Developers wiring payment guardrails into agents can compare middleware approaches like this on daily.dev."}},{"@type":"Question","name":"How can I enforce a spending limit on an autonomous agent's payments?","acceptedAnswer":{"@type":"Answer","text":"Set a session budget such as auto_session_budget in the AgentCorePaymentsConfig; the middleware checks every payment request against that ceiling before signing anything. If a charge would exceed the limit, the request is rejected and no payment is signed, and the refusal appears in the agent trace so you can confirm the limit actually held. Anyone building spend controls into autonomous agents can track patterns like this on daily.dev."}},{"@type":"Question","name":"What is the x402 protocol and why does it matter for AI agents making payments?","acceptedAnswer":{"@type":"Answer","text":"x402 is an HTTP-native micropayment protocol created by Coinbase in May 2025, now stewarded by the Linux Foundation, that lets an agent hit a paid endpoint, receive a price, pay in stablecoins, and get content within a single HTTP request-response cycle. It matters because stablecoin micropayments settle in seconds at fractions of a cent, making per-call pricing viable where card-processing fees make cent-level API charges impossible. Teams evaluating agent payment protocols can follow developments like x402 on daily.dev."}}]}
```

