Skip to content

feat: implement full multi-category API per REQUIREMENTS.md - #3

Merged
whoabuddy merged 5 commits into
mainfrom
feat/migrate-stx402
Jan 12, 2026
Merged

whoabuddy merged 5 commits into
mainfrom
feat/migrate-stx402

Conversation

@whoabuddy

@whoabuddy whoabuddy commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Implements complete x402 pay-per-use API with 40+ endpoints
  • Adds Durable Objects for per-payer state (UsageDO, StorageDO)
  • Adds chanfana/Scalar API documentation at /docs
  • Supports STX, sBTC, and USDCx payments via x402 protocol

Endpoints

  • Inference: OpenRouter + Cloudflare AI (4 endpoints)
  • Stacks: address-convert, decode, profile, verify (6 endpoints)
  • Hashing: sha256, sha512, sha512-256, keccak256, hash160, ripemd160 (6 endpoints)
  • Storage: KV, Paste, DB, Sync, Queue, Memory (25 endpoints)

Test plan

  • Preview build deploys successfully
  • /docs shows Scalar API documentation
  • /health returns OK
  • Type check passes (npm run check)

🤖 Generated with Claude Code

whoabuddy and others added 2 commits January 12, 2026 11:53
Implements complete x402 pay-per-use API with 40+ endpoints across
multiple categories, Durable Objects for per-payer state, and
chanfana/Scalar documentation.

## Core Infrastructure
- Updated wrangler.jsonc with KV, AI, DO bindings
- Added chanfana, @stacks/encryption dependencies
- Comprehensive type definitions in types.ts
- Tiered pricing system (free, simple, ai, storage tiers, dynamic)
- x402 middleware with fixed and dynamic pricing support

## Services
- OpenRouter client with streaming support
- Hiro API client for Stacks blockchain data
- Tenero API client for market data
- Central pricing service

## Durable Objects
- UsageDO: Per-payer usage tracking with SQLite
- StorageDO: Per-payer storage (KV, paste, SQL, sync, queue, memory)

## Endpoints (40+ total)
- Inference: OpenRouter chat/models, Cloudflare AI chat/models
- Stacks: address-convert, decode-clarity, decode-transaction,
  profile, verify-message, verify-sip018
- Hashing: sha256, sha512, sha512-256, keccak256, hash160, ripemd160
- Storage KV: get, set, delete, list
- Storage Paste: create, get, delete
- Storage DB: query, execute, schema
- Storage Sync: lock, unlock, extend, status, list
- Storage Queue: push, pop, peek, status, clear
- Storage Memory: store, search, delete, list, clear

## Documentation
- Scalar API docs at /docs
- OpenAPI schema with all endpoints documented

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Copilot AI review requested due to automatic review settings January 12, 2026 18:57
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jan 12, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
x402-api-staging 0ed8401 Jan 12 2026, 11:12 PM

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a comprehensive x402 pay-per-use API with 40+ endpoints across multiple categories (Inference, Stacks, Hashing, Storage). It adds Durable Objects for per-payer state management, integrates chanfana/Scalar for API documentation, and supports STX, sBTC, and USDCx payment tokens.

Changes:

  • Adds UsageDO and StorageDO Durable Objects for per-payer usage tracking and isolated storage
  • Implements chanfana/Scalar OpenAPI documentation at /docs
  • Adds 40+ endpoints across 4 main categories with tiered pricing (free, simple, ai, storage tiers, and dynamic)
  • Integrates new services: Hiro API client, Tenero API client, pricing service
  • Restructures middleware to support both fixed and dynamic pricing models

Reviewed changes

Copilot reviewed 66 out of 67 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
wrangler.jsonc Updated DO bindings (UsageDO, StorageDO), added KV namespaces, AI binding
src/types.ts Extensive type additions for pricing, x402 context, OpenRouter, Stacks profiles
src/services/pricing.ts New centralized pricing service with model pricing and tier configuration
src/services/hiro.ts New Hiro API client for Stacks blockchain data
src/services/tenero.ts New Tenero API client for market data
src/services/openrouter.ts Refactored to use shared types and centralized pricing
src/middleware/x402.ts Enhanced to support fixed tiers and dynamic pricing with middleware factory
src/index.ts Complete restructure using chanfana for OpenAPI docs and route organization
src/endpoints/* 40+ new endpoint implementations across categories
src/durable-objects/* UsageDO and StorageDO implementations with SQLite
package.json Added dependencies: chanfana, @stacks/encryption, qrcode, zod

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/endpoints/stacks/verify-sip018.ts Resolved
Comment thread src/index.ts Resolved
whoabuddy and others added 3 commits January 12, 2026 13:14
- Remove unused imports (bufferCV, x402 middleware functions)
- Add real KV namespace IDs for METRICS and STORAGE
- Make LOGS service binding optional (commented out)
- Update .env.example with all required configuration

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add explicit bindings per environment (durable_objects, kv_namespaces, ai)
- Cloudflare bindings are NOT inherited by environments
- Create separate KV namespaces for staging vs production
- Update package.json scripts for environment-based deploys
- Add workers_dev: false for deployed environments

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Simplify README to point to /docs for API details
- Update CLAUDE.md status from "Expanding" to "Implemented"
- Fix project structure to match actual file layout
- Add storage_write_large pricing tier

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@whoabuddy
whoabuddy merged commit 93e8175 into main Jan 12, 2026
@whoabuddy
whoabuddy deleted the feat/migrate-stx402 branch January 12, 2026 23:12
whoabuddy added a commit that referenced this pull request Feb 17, 2026
Update /x402.json route handler to extract baseUrl from request URL
and pass to generateX402Manifest(). This enables building full resource
URLs (e.g., "https://x402.aibtc.dev/path") instead of relative paths.

Changes:
- Extract baseUrl from c.req.url origin
- Pass baseUrl, serviceName, serviceUrl to generator
- Update import from generateX402Schema to generateX402Manifest
- Rename variable from schema to manifest for clarity

Fixes issue #3 from quest tracking (resource object format).

Related to #40

Co-Authored-By: Claude Opus 4.6 <[email protected]>
whoabuddy added a commit that referenced this pull request Feb 17, 2026
* feat(x402): implement V2 manifest types and generator

Rewrite x402 discovery manifest to comply with V2 protocol spec:

- Add V2-compliant types: V2PaymentRequirements, V2ManifestEntry, V2Manifest
- Replace X402Entry/X402Schema with per-endpoint grouped structure
- Rename generateX402Schema() to generateX402Manifest()
- Use CAIP-2 network format ("stacks:1" / "stacks:2147483648")
- Change maxAmountRequired to amount per V2 spec
- Add baseUrl to GeneratorConfig for full resource URLs
- Group accepts by endpoint instead of flat token array
- Include service metadata wrapper
- Add Bazaar extensions per endpoint
- Add lastUpdated timestamp
- Retain X402InputSchema/X402OutputSchema for Bazaar compatibility

Fixes issues #1-2 from quest tracking:
1. Invalid network format (now CAIP-2)
2. Missing amount field (now uses amount instead of maxAmountRequired)

Related to #40

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* feat(x402): update route handler to pass baseUrl

Update /x402.json route handler to extract baseUrl from request URL
and pass to generateX402Manifest(). This enables building full resource
URLs (e.g., "https://x402.aibtc.dev/path") instead of relative paths.

Changes:
- Extract baseUrl from c.req.url origin
- Pass baseUrl, serviceName, serviceUrl to generator
- Update import from generateX402Schema to generateX402Manifest
- Rename variable from schema to manifest for clarity

Fixes issue #3 from quest tracking (resource object format).

Related to #40

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix(x402): correct V2 manifest resource and Bazaar extension structure

Changes resource field from string to ResourceInfo object (with url, description, mimeType)
and fixes Bazaar extension nesting to match V2 protocol spec. Resolves x402lint validation
warnings for MISSING_RESOURCE and INVALID_BAZAAR_* fields.

- Add ResourceInfo interface matching x402-stacks V2 types
- Update V2ManifestEntry to use ResourceInfo object for resource field
- Fix Bazaar extension type to use inner structure (BazaarExtension["bazaar"])
- Extract .bazaar property when building extensions (matches middleware pattern)
- Add description and mimeType to each manifest entry resource

Validation results:
- x402lint: ✓ Valid (v2) with zero errors
- Remaining warnings: UNKNOWN_NETWORK/ASSET (expected for Stacks testnet)

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* refactor(x402): simplify V2 manifest generator

Remove dead legacy types, unused imports, unreachable guards, and
unnecessary config indirection. Behavior unchanged.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
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.

2 participants