betterclaude-workers  by AkideLiu

Intelligent Claude API gateway

Created 3 months ago
253 stars

Top 99.3% on SourcePulse

GitHubView on GitHub
Project Summary

Summary

BetterClaude Gateway is an intelligent API proxy for Claude, built on Cloudflare Workers. It addresses the problem of corrupted message histories caused by orphaned tool_result blocks, which lead to 400 errors. By automatically cleaning these errors, it ensures seamless interaction with Claude's tool-calling capabilities, benefiting developers integrating AI agents.

How It Works

The gateway employs a proactive cleanup strategy, scanning messages for orphaned tool_result blocks before forwarding requests to the Claude API. If errors persist, it falls back to a reactive cleanup mechanism, parsing API responses to identify and remove remaining problematic blocks. This dual approach ensures robust error handling and maintains conversation integrity, preventing API failures due to malformed message histories.

Quick Start & Requirements

  • Installation: Requires Node.js (v20+) and the Wrangler CLI. Clone the repository and run npm install.
  • Prerequisites: A Cloudflare account and a configured domain with a Cloudflare zone are necessary for deployment.
  • Configuration: Update wrangler.jsonc with your worker name, domain routes, and zone name.
  • Deployment: Use npm run deploy to deploy the worker.
  • Development: Run npm run dev for a local development server.
  • Documentation: Usage involves prefixing your Claude API endpoint with the gateway URL: https://<YOUR_DOMAIN>/claude/<TARGET_HOST>/v1/messages.

Highlighted Details

  • Auto Error Fix: Automatically detects and removes orphaned tool_result blocks that cause 400 errors.
  • Proactive & Reactive Cleanup: Employs both pre-API call scanning and post-error parsing for robust error mitigation.
  • Smart Retry: Implements a fallback mechanism for persistent cleanup issues.
  • Transparent Proxy: Preserves all original headers and client information.
  • Edge Computing: Leverages Cloudflare Workers for low-latency, worldwide API proxying.

Maintenance & Community

No specific details regarding maintainers, sponsorships, or community channels (like Discord/Slack) are provided in the README.

Licensing & Compatibility

The project is licensed under the MIT license. This permissive license generally allows for broad compatibility, including commercial use and integration into closed-source applications, without significant restrictions.

Limitations & Caveats

The proxy's effectiveness relies on the stability and error reporting format of the underlying Claude API. While it handles known orphaned tool_result errors, unforeseen API changes or other error types might require updates. The project is deployed as a Cloudflare Worker, necessitating adherence to Cloudflare's platform limitations and usage policies.

Health Check
Last Commit

3 months ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
0
Star History
33 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.