Skip to content

feat(#24): add anthropic oauth client#25

Closed
manurgdev wants to merge 4 commits intoachetronic:masterfrom
manurgdev:feat/add-anthropic-oauth-client
Closed

feat(#24): add anthropic oauth client#25
manurgdev wants to merge 4 commits intoachetronic:masterfrom
manurgdev:feat/add-anthropic-oauth-client

Conversation

@manurgdev
Copy link
Copy Markdown

Summary

  • Fix: Anthropic backend was ignoring the url field, always sending requests to https://api.anthropic.com. Added BaseURL: backend.URL to the Anthropic backend constructor — this is required for CLIProxyAPI (or any Anthropic-compatible proxy) to work.
  • Feature: Integrate CLIProxyAPI so users with a Claude Max/Pro subscription can use Claude models without a separate API key.
  • DX: Add make docs / make docs-stop to 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 BaseURL from the backend config, so the url field 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 — Added cliproxyapi service and cliproxyapi_auth volume
  • docker/compose/cliproxyapi/config.yaml — Default proxy config (port 8317, auth-dir, API key sk-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 screen

Documentation

  • website/content/docs/backends.md — Added url field 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, added cliproxyapi_auth to data persistence table

Developer experience (Makefile)

  • make docs — Runs Hugo in a Docker container on port 1313 with live reload
  • make docs-stop — Stops the documentation container

Test plan

  • Run bash scripts/install.sh, select Docker Compose + cloud-only, enable CLIProxyAPI
  • Verify generated docker-compose.yaml has correct volume mount (/CLIProxyAPI/config.yaml)
  • Verify generated cliproxyapi/config.yaml includes auth-dir
  • Run docker compose stop cliproxyapi then docker compose run --rm --service-ports cliproxyapi /CLIProxyAPI/CLIProxyAPI --no-browser --claude-login — complete OAuth flow
  • Run docker compose up -d cliproxyapi — verify service starts with 1 auth entries
  • Create Anthropic backend with URL http://cliproxyapi:8317 — send a message to the agent and verify Claude responds
  • Verify make docs starts Hugo on http://localhost:1313

Comment thread scripts/install.sh Outdated
Comment thread website/content/docs/backends.md Outdated
Comment thread website/content/docs/backends.md Outdated
Comment on lines +71 to +123
### 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 >}}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread scripts/install.sh Outdated
if $WANT_CLIPROXYAPI; then
cls
echo
printf " $(badge " SETUP " "$BG_YELLOW" "$FG_BLACK") ${BOLD}Claude subscription proxy (CLIProxyAPI)${NC}\n"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not just for Claude, no, no, no hehe

@achetronic achetronic added the enhancement New feature or request label Mar 10, 2026
- 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.
@manurgdev manurgdev requested a review from achetronic March 12, 2026 15:59
@manurgdev
Copy link
Copy Markdown
Author

@achetronic I've added the proposed changes to the branch. Take a look when you can 🚀

@achetronic
Copy link
Copy Markdown
Owner

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?

  • I needed to set the proper settings section in config yaml to enable AdminUI
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: true

Moreover, 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-stopped

And 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? 🚀

@manurgdev
Copy link
Copy Markdown
Author

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."

@manurgdev manurgdev closed this Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants