Skip to content

Vercel AI SDK v6 x402 Example #60

@ponderingdemocritus

Description

@ponderingdemocritus

Vercel AI SDK v6 x402 Example

Summary

  • Build a reference example showcasing how to expose an x402-enabled endpoint using @lucid-agents/agent-kit together with Vercel AI SDK v6.
  • Demonstrate end-to-end request flow from a Vercel AI SDK client to a paid agent route running in our stack.

Problem Statement

We have no documented guidance on integrating the latest Vercel AI SDK (v6) with our x402 payments flow. Developers who rely on Vercel's edge runtime struggle to wire up the correct headers, streaming behavior, and payment handling when calling our agent endpoints.

Requirements

  • Target Vercel AI SDK v6 APIs (server and client) and highlight any setup differences from earlier versions.
  • Expose an x402-protected endpoint using @lucid-agents/agent-kit that validates payment headers and streams responses.
  • Include example client code (edge function or serverless handler) that invokes the endpoint with the proper x402 headers and handles payment challenges.
  • Document environment variable management for wallet keys, facilitator URL, price configuration, and trust settings.
  • Emphasize edge compatibility (e.g., using fetch, streaming, runtime constraints) and note any limitations.

Proposed Scope & Tasks

  • Add a new example directory (e.g. packages/agent-kit/examples/vercel-aisdk-x402/).
  • Implement an agent entrypoint that enforces x402 pricing and streams responses compatible with Vercel AI SDK v6 expectations.
  • Provide Vercel-side sample code (API route or serverless function) showing how to call the agent endpoint with x402 headers, including payment negotiation.
  • Write a README walking through setup, environment configuration, local testing, and Vercel deployment steps.
  • Update documentation to call out any SDK v6 breaking changes relevant to x402 usage (e.g., new event handlers or streaming APIs).
  • Verify the flow by simulating a full payment cycle, confirming the client receives gated access after successful payment.

Acceptance Criteria

  • Running the documented sample results in a working x402-protected agent endpoint consumed via Vercel AI SDK v6 client code.
  • Documentation clearly explains how to configure payments, handle streaming responses, and troubleshoot common integration issues.
  • Example adheres to repository tooling (TypeScript strict mode, Bun, lint clean) and is structured as a reusable template for other Vercel integrations.
  • README includes warnings about managing private keys and guidance for testing against facilitators in non-production environments.

Additional Context

  • Reference existing paywall logic in packages/agent-kit/src/paywall.ts for best practices when enforcing x402 requirements.
  • Consider whether the create-agent-kit CLI should expose an option for generating Vercel-ready scaffolds; capture follow-up tasks if needed.
  • Coordinate timelines with any ongoing x402 facilitator updates to ensure compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions