DEV Community

mogee
mogee

Posted on

I Built an Open-Source Bridge That Turns Claude Code Into a REST API

Why I Built This

If you're already paying for Claude Code (Max plan), you have access to an incredibly powerful AI right in your terminal. I wanted to get more out of that subscription β€” use it from my web apps, Slack bots, CI pipelines, and Python scripts running on other machines.

Anthropic does have an official API, but it's pay-per-token β€” a separate cost. Since I'm already paying for a subscription, I figured: why not use what I've got?

There are some great open-source wrappers like coder/agentapi and claude-code-api, but they're designed for local use only. I needed something that works remotely too β€” without having to set up reverse proxies, TLS certificates, and authentication from scratch.

What It Does

claude-api-bridge lets you use your existing Claude Code subscription as a REST API, accessible from anywhere.

One command. That's it.

npx claude-api-bridge start
Enter fullscreen mode Exit fullscreen mode

And you get:

βœ…  Claude Code CLI detected
πŸš€  API server running on http://localhost:3456
πŸ”‘  Admin Token: cab-a1b2c3d4e5f6...
🌐  Public URL: https://random-words.trycloudflare.com
Enter fullscreen mode Exit fullscreen mode

Now you have a real HTTPS endpoint that you can call from any app, anywhere in the world.

How It Works

Your App (anywhere on the internet)
    β”‚
    β”‚ HTTPS
    β–Ό
Cloudflare Tunnel (automatic SSL, zero config)
    β”‚
    β–Ό
claude-api-bridge (your desktop)
    β”œβ”€ Token Authentication (SHA256)
    β”œβ”€ Request Queue
    └─ Claude Code CLI (your subscription)
Enter fullscreen mode Exit fullscreen mode

Your desktop becomes the API server. Claude Code runs locally using your existing subscription. Cloudflare Tunnel handles the networking β€” no port forwarding, no ngrok, no reverse proxy setup.

Key Features

Feature Details
πŸš€ One-command setup No config files, no environment variables
🌐 Remote access Cloudflare Tunnel with automatic HTTPS
πŸ”‘ Token management Create, revoke, expire. SHA256 hashed β€” never stored in plaintext
πŸ’¬ Session modes Stateless (fresh each time) or Stateful (conversation memory)
πŸ“Š Web dashboard Monitor at /dashboard
πŸ”’ Secure Rate limiting, CSP headers, execution timeout, output size limits
πŸ’Ύ Zero dependencies SQLite for storage β€” no Redis, no Postgres

Quick Example

Python

import requests, time

BASE = "https://your-url.trycloudflare.com"
TOKEN = "cab-your-token"
H = {"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"}

def ask(msg):
    r = requests.post(f"{BASE}/api/ask", json={"message": msg}, headers=H)
    rid = r.json()["requestId"]
    while True:
        p = requests.get(f"{BASE}/api/ask/{rid}", headers=H).json()
        if p["status"] == "completed": return p["response"]
        time.sleep(2)

print(ask("Write a function to check if a number is prime"))
Enter fullscreen mode Exit fullscreen mode

JavaScript

async function askClaude(message) {
  const res = await fetch(`${BASE_URL}/api/ask`, {
    method: "POST",
    headers: { Authorization: `Bearer ${TOKEN}`, "Content-Type": "application/json" },
    body: JSON.stringify({ message }),
  });
  const { requestId } = await res.json();

  while (true) {
    const poll = await fetch(`${BASE_URL}/api/ask/${requestId}`, {
      headers: { Authorization: `Bearer ${TOKEN}` },
    });
    const data = await poll.json();
    if (data.status === "completed") return data.response;
    await new Promise(r => setTimeout(r, 2000));
  }
}
Enter fullscreen mode Exit fullscreen mode

How It Compares

Feature claude-api-bridge coder/agentapi claude-code-api
Remote access (HTTPS) βœ… Built-in ❌ Local only ❌ Local only
Token management βœ… Full CRUD ❌ None ⚠️ Static keys
Token security βœ… SHA256 hash ❌ N/A ❌ Plaintext
Session persistence βœ… SQLite ❌ In-memory ⚠️ In-memory
Crash recovery βœ… Auto ❌ No ❌ No
Zero config βœ… One command βœ… One command ⚠️ Config needed

Limitations (Being Honest)

  • Your desktop must be running β€” Claude CLI executes on your machine
  • One request at a time β€” Claude CLI is single-threaded, requests are queued
  • Free tunnel URL changes on restart β€” use a Cloudflare account for a fixed domain
  • Response time varies β€” typically 10 seconds to 2 minutes depending on the task

Try It

npx claude-api-bridge start
Enter fullscreen mode Exit fullscreen mode

GitHub: github.com/smy383/claude-api-bridge
npm: npmjs.com/package/claude-api-bridge

Star ⭐ if you find it useful!


Built by the team behind ttapp β€” the mobile remote for Claude Code.

Top comments (0)