Skip to content

feat(templates): add Chat x402 template with Echo Credits / USDC payment switcher (closes #610)#807

Open
D3CC wants to merge 2 commits into
Merit-Systems:masterfrom
D3CC:feat/chat-x402-1778676183
Open

feat(templates): add Chat x402 template with Echo Credits / USDC payment switcher (closes #610)#807
D3CC wants to merge 2 commits into
Merit-Systems:masterfrom
D3CC:feat/chat-x402-1778676183

Conversation

@D3CC
Copy link
Copy Markdown

@D3CC D3CC commented May 13, 2026

Description

Add Chat x402 template as requested in #610.

Reuses the existing AI elements from next-chat template and merges the x402 payment flow as specified by @rsproule.

What's included:

Auth/Payment Switcher:

  • AuthSwitcher component allowing users to choose between Echo Credits and USDC (x402)
  • Clean toggle UI consistent with Echo's design system
  • Payment method passed to API route via request body

Chat Component (chat-x402.tsx):

  • Reuses AI elements from next-chat template (Message, PromptInput, Loader)
  • Integrated x402 payment error handling (HTTP 402)
  • Payment-required UI feedback when funds are insufficient
  • Dark mode support with Tailwind dark: classes

API Route (chat-x402/route.ts):

  • x402 payment verification via @merit-systems/echo-aix402
  • HTTP 402 response with payment headers when USDC payment is required
  • Echo-billed AI providers for both payment methods
  • Standard x402 headers: x402-payment-required, x402-accept, x402-amount, x402-network

Implementation Notes

  • Built following rsproule's guidance: "reuse the existing one as much as possible. And merge the login flow from the sora template"
  • Reuses Message, MessageContent, PromptInput, PromptInputTextarea, PromptInputSubmit, Loader from next-chat AI elements
  • Echo SDK handles billing automatically for Echo Credits method
  • x402 protocol handles USDC payment verification

Files

  • templates/chat-x402/src/app/_components/chat-x402.tsx — Chat component with auth switcher
  • templates/chat-x402/src/app/api/chat-x402/route.ts — API route with x402 payment handling

Closes #610

D3CC added 2 commits May 13, 2026 20:43
Add templates/chat-x402/ with:
- Chat component reusing AI elements from next-chat
- Echo Credits / USDC (x402) payment auth switcher
- HTTP 402 error handling for payment failures

Closes Merit-Systems#610
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 13, 2026

@D3CC is attempting to deploy a commit to the Merit Systems Team on Vercel.

A member of the Team first needs to authorize it.

@D3CC D3CC mentioned this pull request May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat x402 template

1 participant