Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
e6ca1c9
feat: Add support for OpenRouter's reasoning/thinking parameters in r…
elusznik Nov 20, 2025
cf1c03f
feat: Implement streaming support for AI reasoning/thinking blocks.
elusznik Nov 20, 2025
9c4654f
feat: Add documentation for OpenRouter reasoning support, including b…
elusznik Nov 21, 2025
a5a5c55
chore: update package.json to add build script and wrangler as devDep…
elusznik Nov 21, 2025
dbad934
feat: dynamically track and report usage tokens in OpenAI to Anthropi…
elusznik Nov 21, 2025
88dab93
refactor: rename project from y-router to open-claude-router
elusznik Nov 21, 2025
398163c
feat: Add overwrite of the model and API key on the fly, leraving the…
elusznik Nov 22, 2025
98e86c3
docs: enhance installation guide, add project acknowledgments, and cl…
elusznik Nov 22, 2025
a9494ff
feat: Add scripts and documentation for running the router in detache…
elusznik Nov 22, 2025
b194047
docs: Update git clone URL in README.
elusznik Nov 22, 2025
2a652a6
feat: Introduce automated scripts for detached router operation and C…
elusznik Nov 22, 2025
0929831
docs: improve README formatting by removing duplicate heading and add…
elusznik Nov 22, 2025
b4f2467
docs: improve README.md readability
elusznik Nov 22, 2025
251b5c6
feat: Introduce optional model override for configuration patching an…
elusznik Nov 22, 2025
f5a9e3d
chore: ignore router log and pid files by adding them to .gitignore
elusznik Nov 22, 2025
8e329b1
chore: Ignore the `.serena/` directory.
elusznik Nov 22, 2025
6c48d0d
feat: Implement token counting endpoint, add model data to models.jso…
elusznik Nov 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ coverage
.docker
Dockerfile
docker-compose.yml
.dockerignore
.dockerignore
.wrangler
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,7 @@ dist

.dev.vars
.wrangler/
.router.log
.router.pid
.serena/
.gemini/
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /app

RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*

RUN npm install -g wrangler
RUN npm install -g wrangler@4

COPY package*.json ./

Expand All @@ -14,4 +14,7 @@ COPY . .

EXPOSE 8787

RUN chown -R node:node /app
USER node

CMD ["npm", "run", "dev", "--", "--ip", "0.0.0.0"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright 2025 y-router Authors
Copyright 2025 open-claude-router Authors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
241 changes: 59 additions & 182 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,242 +1,119 @@
# y-router
# open-claude-router

A Cloudflare Worker that translates between Anthropic's Claude API and OpenAI-compatible APIs, enabling you to use Claude Code with OpenRouter and other OpenAI-compatible providers.

> **Note:** This worker is suitable for testing models other than Anthropic. For Anthropic models (especially for intensive usage exceeding $200), consider using [claude-relay-service](https://github.com/Wei-Shaw/claude-relay-service) for better value.
## Features

## Quick Usage
- **Local-First**: Designed to run locally on your machine for maximum privacy and control.
- **Model Override**: Force specific models (like Grok, Gemini, etc.) via environment variables without changing Claude Code settings.
- **API Key Override**: Use a separate OpenRouter API key for the router while keeping your Anthropic key in Claude Code settings.
- **Reasoning Support**: Full support for OpenRouter's reasoning capabilities (e.g., DeepSeek R1).

### One-line Install (Recommended)
```bash
bash -c "$(curl -fsSL https://cc.yovy.app/install.sh)"
```
## Quick Start (Local)

This script will automatically:
- Install Node.js (if needed)
- Install Claude Code
- Configure your environment with OpenRouter or Moonshot
- Set up all necessary environment variables
### 1. Installation

### Manual Setup

**Step 1:** Install Claude Code
```bash
npm install -g @anthropic-ai/claude-code
```

**Step 2:** Get OpenRouter API key from [openrouter.ai](https://openrouter.ai)

**Step 3:** Configure environment variables in your shell config (`~/.bashrc` or `~/.zshrc`):

```bash
# For quick testing, you can use our shared instance. For daily use, deploy your own instance for better reliability.
export ANTHROPIC_BASE_URL="https://cc.yovy.app"
export ANTHROPIC_API_KEY="your-openrouter-api-key"
export ANTHROPIC_CUSTOM_HEADERS="x-api-key: $ANTHROPIC_API_KEY"
```
# Clone the repository
git clone https://github.com/elusznik/open-claude-router.git
cd open-claude-router

**Optional:** Configure specific models (browse models at [openrouter.ai/models](https://openrouter.ai/models)):
```bash
export ANTHROPIC_MODEL="moonshotai/kimi-k2"
export ANTHROPIC_SMALL_FAST_MODEL="google/gemini-2.5-flash"
# Install dependencies
npm install
```

**Step 4:** Reload your shell and run Claude Code:
```bash
source ~/.bashrc
claude
```
### 2. Configuration

That's it! Claude Code will now use OpenRouter's models through y-router.
Create a `.dev.vars` file in the project root to store your secrets. This file is ignored by Git.

### Multiple Configurations
```ini
# .dev.vars

To maintain multiple Claude Code configurations for different providers or models, use shell aliases:
# Force the router to use this model regardless of what Claude Code requests
MODEL_OVERRIDE="x-ai/grok-4.1-fast"

```bash
# Example aliases for different configurations
alias c1='ANTHROPIC_BASE_URL="https://cc.yovy.app" ANTHROPIC_API_KEY="your-openrouter-key" ANTHROPIC_CUSTOM_HEADERS="x-api-key: $ANTHROPIC_API_KEY" ANTHROPIC_MODEL="moonshotai/kimi-k2" ANTHROPIC_SMALL_FAST_MODEL="google/gemini-2.5-flash" claude'
alias c2='ANTHROPIC_BASE_URL="https://api.moonshot.ai/anthropic/" ANTHROPIC_API_KEY="your-moonshot-key" ANTHROPIC_CUSTOM_HEADERS="x-api-key: $ANTHROPIC_API_KEY" ANTHROPIC_MODEL="kimi-k2-0711-preview" ANTHROPIC_SMALL_FAST_MODEL="moonshot-v1-8k" claude'
# Your OpenRouter API Key
OPENROUTER_API_KEY="sk-or-..."
```

Add these aliases to your shell config file (`~/.bashrc` or `~/.zshrc`), then use `c1` or `c2` to switch between configurations.
### 3. Run the Router

## GitHub Actions Usage
We recommend using the **detached mode scripts**, which automatically configure Claude Code for you.

To use Claude Code in GitHub Actions workflows, add the environment variable to your workflow:
**Start Router & Patch Config:**

```yaml
env:
ANTHROPIC_BASE_URL: ${{ secrets.ANTHROPIC_BASE_URL }}
```bash
./start-detached.sh
```

Set `ANTHROPIC_BASE_URL` to `https://cc.yovy.app` in your repository secrets.

Example workflows:
- [Interactive Claude Code](.github/workflows/claude.yml) - Responds to @claude mentions
- [Automated Code Review](.github/workflows/claude-code-review.yml) - Automatic PR reviews

## What it does

y-router acts as a translation layer that:
- Accepts requests in Anthropic's API format (`/v1/messages`)
- Converts them to OpenAI's chat completions format
- Forwards to OpenRouter (or any OpenAI-compatible API)
- Translates the response back to Anthropic's format
- Supports both streaming and non-streaming responses

## Perfect for Claude Code + OpenRouter

This allows you to use [Claude Code](https://claude.ai/code) with OpenRouter's vast selection of models by:
1. Pointing Claude Code to your y-router deployment
2. Using your OpenRouter API key
3. Accessing Claude models available on OpenRouter through Claude Code's interface

## Setup

### Option 1: Docker Deployment (Recommended for Local)

1. **Clone and start with Docker:**
```bash
git clone <repo>
cd y-router
docker-compose up -d
```

2. **Configure Claude Code:**
- Set API endpoint to `http://localhost:8787`
- Use your OpenRouter API key
- Enjoy access to Claude models via OpenRouter!

### Option 2: Cloudflare Workers Deployment
This script will:

1. **Clone and deploy:**
```bash
git clone <repo>
cd y-router
npm install -g wrangler
wrangler deploy
```
1. Backup your existing `~/.claude/settings.json`.
2. Update Claude Code to use the local router (`http://localhost:8787`).
3. Start the router in the background.

2. **Set environment variables:**
```bash
# Optional: defaults to https://openrouter.ai/api/v1
wrangler secret put OPENROUTER_BASE_URL
```

3. **Configure Claude Code:**
- Set API endpoint to your deployed Worker URL
- Use your OpenRouter API key
- Enjoy access to Claude models via OpenRouter!

## Environment Variables

- `OPENROUTER_BASE_URL` (optional): Base URL for the target API. Defaults to `https://openrouter.ai/api/v1`

## API Usage

Send requests to `/v1/messages` using Anthropic's format:
**Stop Router & Restore Config:**

```bash
curl -X POST https://cc.yovy.app/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: your-openrouter-key" \
-d '{
"model": "claude-sonnet-4-20250514",
"messages": [{"role": "user", "content": "Hello, Claude"}],
"max_tokens": 100
}'
./stop-router.sh
```

## Development
> [!IMPORTANT]
> You **MUST** use `./stop-router.sh` to stop the router. This script restores your original `settings.json` (Anthropic defaults). If you just kill the process, your Claude Code configuration will remain pointed at localhost.

### Local Development (Wrangler)
### Alternative: Manual Run

```bash
npm run dev # Start development server
npm run deploy # Deploy to Cloudflare Workers
npm run dev
```

### Docker Deployment
The router will start at `http://localhost:8787`.

For easier deployment and development, you can use Docker:
### 4. Configure Claude Code

#### Quick Start with Docker Compose
Point Claude Code to your local router. You can leave your Anthropic API key as is (it will be ignored if `OPENROUTER_API_KEY` is set in `.dev.vars`).

```bash
# Clone the repository
git clone <repo>
cd y-router
# Set the base URL to your local router
export ANTHROPIC_BASE_URL="http://localhost:8787"

# Start with Docker Compose
docker-compose up -d
# (Optional) Set a dummy key if you haven't set one yet
export ANTHROPIC_API_KEY="sk-dummy-key"

# The service will be available at http://localhost:8787
# Run Claude Code
claude
```

#### Manual Docker Build

```bash
# Build the Docker image
docker build -t y-router .

# Run the container
docker run -d -p 8787:8787 \
-e OPENROUTER_BASE_URL=https://openrouter.ai/api/v1 \
y-router
```
## Advanced Configuration

#### Environment Configuration
### Model Override

Create a `.env` file or set environment variables:
You can force the router to use a specific model by setting `MODEL_OVERRIDE` in `.dev.vars`. This is useful because it allows you to keep `claude-3-5-sonnet` in your Claude Code settings (ensuring compatibility) while actually using a different model backend.

```bash
# Optional: Base URL for the target API (defaults to https://openrouter.ai/api/v1)
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
```
### API Key Override

#### Docker Compose Commands
Set `OPENROUTER_API_KEY` in `.dev.vars` to use a specific key for OpenRouter requests. This allows you to keep your actual Anthropic key in your global settings if you switch back and forth.

```bash
docker-compose up -d # Start services in background
docker-compose down # Stop and remove containers
docker-compose logs # View logs
docker-compose ps # Check service status
docker-compose restart # Restart services
```
## Development

#### Health Check
### Docker Support

The Docker setup includes a health check that verifies the service is responding:
You can also run the router using Docker:

```bash
# Check if the service is healthy
curl http://localhost:8787/

# Check Docker health status
docker-compose ps
docker-compose up -d
```

Make sure to map your `.dev.vars` or set environment variables in `docker-compose.yml`.

## Thanks

Special thanks to these projects that inspired y-router:
Special thanks to these projects that inspired open-claude-router:

- [y-router](https://github.com/yovy-app/y-router)
- [claude-code-router](https://github.com/musistudio/claude-code-router)
- [claude-code-proxy](https://github.com/kiyo-e/claude-code-proxy)

## Disclaimer

**Important Legal Notice:**

- **Third-party Tool**: y-router is an independent, unofficial tool and is not affiliated with, endorsed by, or supported by Anthropic PBC, OpenAI, or OpenRouter
- **Service Terms**: Users are responsible for ensuring compliance with the Terms of Service of all involved parties (Anthropic, OpenRouter, and any other API providers)
- **API Key Responsibility**: Users must use their own valid API keys and are solely responsible for any usage, costs, or violations associated with those keys
- **No Warranty**: This software is provided "as is" without any warranties. The authors are not responsible for any damages, service interruptions, or legal issues arising from its use
- **Data Privacy**: While y-router does not intentionally store user data, users should review the privacy policies of all connected services
- **Compliance**: Users are responsible for ensuring their use complies with applicable laws and regulations in their jurisdiction
- **Commercial Use**: Any commercial use should be carefully evaluated against relevant terms of service and licensing requirements

**Use at your own risk and discretion.**

## License

MIT
Loading