Skip to content

defyma/cline-proxy

Repository files navigation

Cline Proxy for 9router

A lightweight proxy for using the Cline API with 9router via a custom Anthropic-compatible or OpenAI-compatible provider.

Problems Solved

  • Cline's API defaults to streaming when stream is not provided.
  • Some OpenAI-compatible clients expect a regular JSON response when stream is absent.
  • 9router works better with Anthropic-compatible providers when using multiple API keys on a single custom provider.
  • Some upstream SSE events can be empty or carry no choices, which can trigger errors like Provider returned no completion choices for this model.

Endpoints

  • POST /v1/chat/completions
  • POST /v1/messages
  • GET /v1/models
  • GET /health

Run Locally

npm start

Default local URL:

http://localhost:8787/v1

9router Configuration

Recommended: use a custom Anthropic-compatible provider in 9router.

Anthropic-compatible:

  • Base URL: http://HOST:8787/v1
  • API key: your Cline API key
  • Model: the Cline model ID, e.g. xiaomi/mimo-v2.5 or deepseek/deepseek-v4-flash
  • Messages endpoint: 9router will automatically append /messages

OpenAI-compatible is also available:

  • Base URL: http://HOST:8787/v1
  • API key: your Cline API key
  • Model: the model ID
  • Chat completions endpoint: /chat/completions

The proxy forwards the API key and model field from 9router to Cline. For OpenAI-compatible, it reads Authorization: Bearer .... For Anthropic-compatible, it reads x-api-key or Authorization: Bearer ....

If 9router runs in a separate container, do not use localhost unless the proxy is in the same container. Use the host IP, Docker service name, or the proxy's public domain.

Environment Variables

All variables are optional. Defaults are sufficient for most deployments.

PORT=8787
CLINE_BASE_URL=https://api.cline.bot/api/v1
REQUEST_TIMEOUT_MS=120000

Manual Testing

Non-streaming:

curl -s http://localhost:8787/v1/chat/completions \
  -H 'authorization: Bearer YOUR_CLINE_API_KEY' \
  -H 'content-type: application/json' \
  -d '{
    "model": "MODEL_ID",
    "messages": [{"role":"user","content":"Hello"}]
  }'

Streaming:

curl -N http://localhost:8787/v1/chat/completions \
  -H 'authorization: Bearer YOUR_CLINE_API_KEY' \
  -H 'content-type: application/json' \
  -d '{
    "model": "MODEL_ID",
    "stream": true,
    "messages": [{"role":"user","content":"Hello"}]
  }'

Anthropic-compatible non-streaming:

curl -s http://localhost:8787/v1/messages \
  -H 'x-api-key: YOUR_CLINE_API_KEY' \
  -H 'anthropic-version: 2023-06-01' \
  -H 'content-type: application/json' \
  -d '{
    "model": "MODEL_ID",
    "max_tokens": 128,
    "messages": [{"role":"user","content":"Hello"}]
  }'

Docker

docker build -t cline-proxy .
docker run --rm -p 8787:8787 cline-proxy

Docker Compose Deploy

Clone the repo:

git clone https://github.com/defyma/cline-proxy.git
cd cline-proxy

Copy and edit the env file:

cp .env.example .env
# edit .env as needed

Start:

docker compose pull
docker compose up -d

Compose uses image:

ghcr.io/defyma/cline-proxy:latest

GitHub Actions CI/CD

This repository uses GitHub Actions to build and push the Docker image to the GitHub Container Registry (GHCR).

The pipeline produces the following tags:

  • ghcr.io/defyma/cline-proxy:latest — on push to main
  • ghcr.io/defyma/cline-proxy:main — branch tag
  • ghcr.io/defyma/cline-proxy:v1.0.0 — on git tag
  • ghcr.io/defyma/cline-proxy:sha-<short> — per commit

To pull the image manually:

docker pull ghcr.io/defyma/cline-proxy:latest

About

Lightweight proxy for using Cline API via Anthropic-compatible or OpenAI-compatible provider

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors