feat(#24): add anthropic oauth client#25
feat(#24): add anthropic oauth client#25manurgdev wants to merge 4 commits intoachetronic:masterfrom
Conversation
| ### Using your Claude subscription (CLIProxyAPI) | ||
|
|
||
| If you have a Claude Max or Pro subscription, you can use your existing account instead of paying separately for API access. This works through [CLIProxyAPI](https://github.com/router-for-me/CLIProxyAPI), a local proxy that translates your subscription's OAuth credentials into a standard Anthropic API. | ||
|
|
||
| #### 1. Create the backend | ||
|
|
||
| In the Admin UI, create an `anthropic` backend pointing at CLIProxyAPI: | ||
|
|
||
| | Field | Value | | ||
| |-------|-------| | ||
| | Name | `Claude (Subscription)` | | ||
| | Type | `anthropic` | | ||
| | URL | `http://cliproxyapi:8317` (Docker) or `http://localhost:8317` (local) | | ||
| | API Key | `sk-magec-local` | | ||
|
|
||
| {{< callout type="warning" >}} | ||
| The **URL** field is required. Without it, Magec sends requests to the default Anthropic API (`https://api.anthropic.com`) and authentication will fail. | ||
| {{< /callout >}} | ||
|
|
||
| #### 2. Log in with your Claude account | ||
|
|
||
| The login command starts a temporary OAuth callback server, so you must **stop the running CLIProxyAPI service first** to free its ports: | ||
|
|
||
| ```bash | ||
| # Docker — stop, login, restart | ||
| docker compose stop cliproxyapi | ||
| docker compose run --rm --service-ports cliproxyapi /CLIProxyAPI/CLIProxyAPI --no-browser --claude-login | ||
| docker compose up -d cliproxyapi | ||
|
|
||
| # Binary | ||
| cliproxyapi --claude-login | ||
| ``` | ||
|
|
||
| The command prints a URL like `https://claude.ai/oauth/authorize?...` — open it in your browser and authorize. After the OAuth callback completes, you'll see a success message. Your credentials are stored in the `cliproxyapi_auth` volume and persist across restarts. | ||
|
|
||
| #### 3. Verify | ||
|
|
||
| ```bash | ||
| curl http://localhost:8317/v1/models \ | ||
| -H "X-Api-Key: sk-magec-local" \ | ||
| -H "anthropic-version: 2023-06-01" | ||
| ``` | ||
|
|
||
| If you see a list of Claude models, CLIProxyAPI is working. You can now assign the backend to any agent. | ||
|
|
||
| {{< callout type="info" >}} | ||
| The interactive installer can set up CLIProxyAPI automatically. See [CLIProxyAPI on GitHub](https://github.com/router-for-me/CLIProxyAPI) for full configuration options. | ||
| {{< /callout >}} | ||
|
|
||
| {{< callout type="info" >}} | ||
| CLIProxyAPI is a third-party project not affiliated with Anthropic. It uses your existing Claude subscription — you're responsible for ensuring your usage complies with Anthropic's terms of service. | ||
| {{< /callout >}} | ||
|
|
There was a problem hiding this comment.
I think it's better to open a new docs section in the sidebar with several special use cases like this, and may be document for OpenAI at the same time? IMO this will keep the docs clearer for everyone
| if $WANT_CLIPROXYAPI; then | ||
| cls | ||
| echo | ||
| printf " $(badge " SETUP " "$BG_YELLOW" "$FG_BLACK") ${BOLD}Claude subscription proxy (CLIProxyAPI)${NC}\n" |
There was a problem hiding this comment.
Not just for Claude, no, no, no hehe
- Introduced a new guide on using a subscription proxy, detailing setup and usage. - Updated multiple documentation pages to include links to the new guide in the sidebar. - Added the new guide to the sitemap for better discoverability.
|
@achetronic I've added the proposed changes to the branch. Take a look when you can 🚀 |
|
Hely @manurgdev I have tested the flow IMHO it needs some improvements for a good UX, let me explain. I followed the instructions and I wasn't able to make it work right out of the box, because even when the proxy is launched, there was not an easy way to get the credentials. After that, I basically launched the admin UI of the proxy, entered, performed a login flow and everything worked, so what was the change?
host: "0.0.0.0"
port: 8317
auth-dir: "/CLIProxyAPI/auth"
api-keys:
- "sk-magec-local"
# THIS ONE ------------------------------------------------------------
remote-management:
secret-key: "$2a$10$cYOahAqOquFXKfxhRgJum.jk0rZr.Hzi5zBjgcShjPcTYPFCTwI2m"
allow-remote: trueMoreover, for the callback to work, needed to expose the proxy to the entire network: cliproxyapi:
image: eceasy/cli-proxy-api:latest
network_mode: host # <<<<<<<<<<<<<<<<<<<<<<<<<<<<< THIS
volumes:
- ./cliproxyapi/config.yaml:/CLIProxyAPI/config.yaml
- cliproxyapi_auth:/CLIProxyAPI/auth
restart: unless-stoppedAnd then, just enter in the admin UI and perform the login flow. So I think we should make it ready for the user to understand it easier or support the flows on our own in the API if we can not find a super easy way to use it :) According to my own preferences, i would keep it separated for legal reasons, but if we are going to use this proxy, we need not only document the process better but make it work just out of the box. Are you willing to re-try this PR with that in mind? 🚀 |
|
I think that, given the recent changes being implemented by various providers, it doesn't make much sense to continue using a proxy; instead, Magec should focus on using legitimate API keys from providers that offer this service. I'm closing the PR and the issue as "not applicable." |
Summary
urlfield, always sending requests tohttps://api.anthropic.com. AddedBaseURL: backend.URLto the Anthropic backend constructor — this is required for CLIProxyAPI (or any Anthropic-compatible proxy) to work.make docs/make docs-stopto run the documentation site via Docker (no local Hugo install needed).Changes
Bug fix (
server/agent/agent.go)The Anthropic backend constructor was not passing
BaseURLfrom the backend config, so theurlfield configured in the Admin UI was silently ignored. All requests went to the default Anthropic API regardless of what URL was set. This one-line fix is the critical change that makes CLIProxyAPI (and any custom Anthropic endpoint) work.CLIProxyAPI integration
docker/compose/docker-compose.yaml— Addedcliproxyapiservice andcliproxyapi_authvolumedocker/compose/cliproxyapi/config.yaml— Default proxy config (port 8317,auth-dir, API keysk-magec-local)scripts/install.sh— Full wizard integration: prompts user to enable CLIProxyAPI, generates config, preconfigures backend and default agent, shows login instructions on the success screenDocumentation
website/content/docs/backends.md— Addedurlfield to Anthropic backend table; new CLIProxyAPI section with step-by-step setup (create backend → login → verify)website/content/docs/install-compose-local.md— Added CLIProxyAPI to the services table, new "Claude subscription" section, addedcliproxyapi_authto data persistence tableDeveloper experience (
Makefile)make docs— Runs Hugo in a Docker container on port 1313 with live reloadmake docs-stop— Stops the documentation containerTest plan
bash scripts/install.sh, select Docker Compose + cloud-only, enable CLIProxyAPIdocker-compose.yamlhas correct volume mount (/CLIProxyAPI/config.yaml)cliproxyapi/config.yamlincludesauth-dirdocker compose stop cliproxyapithendocker compose run --rm --service-ports cliproxyapi /CLIProxyAPI/CLIProxyAPI --no-browser --claude-login— complete OAuth flowdocker compose up -d cliproxyapi— verify service starts with1 auth entrieshttp://cliproxyapi:8317— send a message to the agent and verify Claude respondsmake docsstarts Hugo on http://localhost:1313