If you find this project helpful, please consider giving it a star ⭐️!
This Cloudflare Worker provides a backend service to manage access to Claude AI using a pool of session keys (SKs). It allows users to obtain a Claude login URL by either requesting a specific account or a random available account. It also includes administrative endpoints to add or remove email-SK pairs from the pool.
This is the easiest way to get started. This path uses a graphical user interface for the entire process.
Click the "Deploy with Cloudflare" button at the top of this page. The Cloudflare dashboard will open and guide you through creating a copy of this repository and deploying the Worker.
After deployment, you need to configure the necessary secrets and variables for your Worker to function correctly.
- In your Cloudflare Dashboard, navigate to Workers & Pages and select your newly deployed application.
- Go to the Settings tab, then click on Variables.
- Set the Admin Password (Secret):
- Under Environment Variables, click Add variable.
- Enter the variable name:
ADMIN_PASSWORD
. - Enter your desired password in the value field.
- From the Type dropdown, select Secret.
- Click Save and deploy to apply the changes immediately, or Save to apply them on the next deployment.
- Set other Secrets/Variables as needed: Repeat the process for other variables:
TOKEN_EXPIRES_IN
(optional): The default token expiration time in seconds. For example,86400
for 24 hours. If not set, tokens will not expire by default.BASE_URL
: The base URL for your Claude instance.
Note
To modify an existing variable, simply find it in the list, click Edit, enter the new value, and click Save.
Your Worker is deployed, but its KV (database) is empty. You need to add your accounts. The easiest way is to use the new batch API endpoint.
-
Prepare your data: Copy the content of
initial-sk-map.json.example
and fill it with your actual email and SK pairs.{ "[email protected]": "sk-abc...", "[email protected]": "sk-def..." }
-
Construct the API request body: Transform your data into the format required by the batch API.
{ "admin_password": "YOUR_ADMIN_PASSWORD", "actions": [ { "action": "add", "email": "[email protected]", "sk": "sk-abc..." }, { "action": "add", "email": "[email protected]", "sk": "sk-def..." } ] }
-
Send the request: You can use any API tool (like Postman, Insomnia) or the
curl
command to send this data to your Worker. ReplaceYOUR_WORKER_URL
with your actual Worker's URL.curl -X POST https://YOUR_WORKER_URL/api/admin/batch \ -H "Content-Type: application/json" \ -d '{ "admin_password": "YOUR_ADMIN_PASSWORD", "actions": [ { "action": "add", "email": "[email protected]", "sk": "sk-abc..." }, { "action": "add", "email": "[email protected]", "sk": "sk-def..." } ] }'
You are all set! Your Worker is now fully configured and ready to use.
Warning
Deploying the project via the 'Deploy to Cloudflare' button or other GUI methods may automatically create an API token. This token is not automatically deleted when the project is removed. If needed, you can manually manage or delete it from your API Tokens page.
This section is for users who are comfortable with the command line and want more control over the setup process.
This method uses a Node.js script to guide you through the deployment.
- Prerequisites:
- Git, Node.js, and npm must be installed.
- Log in to Cloudflare with the CLI:
npx wrangler login
.
- Clone the repository:
git clone https://github.com/f14XuanLv/fuclaude-pool-manager.git cd fuclaude-pool-manager
- Install dependencies:
npm install npm install prompts --save-dev
- Run the deployment script:
The script will guide you through naming the Worker, creating the KV Namespace, and setting secrets.
node deploy-worker.mjs
This is the fully manual approach for advanced users.
-
Prerequisites:
- Cloudflare account.
wrangler
CLI installed and configured (npx wrangler login
).- Node.js and npm/yarn.
-
Configuration (
wrangler.jsonc
): Manually editwrangler.jsonc
to set your Worker's name and add the KV namespace binding after creating it. -
Create KV Namespace:
# Create production KV npx wrangler kv namespace create "CLAUDE_KV" # Create preview KV for local development npx wrangler kv namespace create "CLAUDE_KV" --preview
Wrangler will prompt you to add the output to your
wrangler.jsonc
. -
Set Secrets:
npx wrangler secret put ADMIN_PASSWORD
-
Deploy:
npx wrangler deploy
-
Initialize KV Data (CLI Method): You can use the
wrangler kv
command to directly upload your initial data map.# Ensure initial-sk-map.json is populated with your data npx wrangler kv key put "EMAIL_TO_SK_MAP" --path ./initial-sk-map.json --binding CLAUDE_KV --remote
All API endpoints are relative to the Worker's deployed URL.
- Purpose: Retrieves a sorted list of email addresses that have associated SKs and can be used for login.
- HTTP Method:
GET
- URL Path:
/api/emails
- Purpose: Obtains a temporary login URL for Claude AI.
- HTTP Method:
POST
- URL Path:
/api/login
- Request Body:
{"mode": "specific" | "random", "email"?: "...", "unique_name"?: "...", "expires_in"?: number}
expires_in
(optional, number): The desired token expiration time in seconds.- Behavior: The effective expiration time is capped by the
TOKEN_EXPIRES_IN
environment variable. If you request a duration longer than the allowed maximum, it will be automatically reduced to the maximum, and the API response will include awarning
field. IfTOKEN_EXPIRES_IN
is not set or is0
, there is no upper limit.
- Success Response:
{"login_url": "...", "warning"?: "..."}
- Returns a
login_url
on success. - Returns an optional
warning
if theexpires_in
was adjusted.
- Returns a
Admin endpoints require an admin_password
for authentication.
- Purpose: Obtains a temporary login URL for Claude AI, bypassing user-facing expiration limits.
- HTTP Method:
POST
- URL Path:
/api/admin/login
- Request Body:
{"admin_password": "...", "mode": "specific" | "random", "email"?: "...", "unique_name"?: "...", "expires_in"?: number}
expires_in
(optional, number): The desired token expiration time in seconds. Defaults to0
(no expiration) if not provided. This value is not limited by theTOKEN_EXPIRES_IN
environment variable.
- Purpose: Retrieves a list of all configured email addresses and a preview of their SKs.
- HTTP Method:
POST
- URL Path:
/api/admin/list
- Request Body:
{"admin_password": "..."}
- Purpose: Adds a new email and its corresponding session key (SK) to the KV store.
- HTTP Method:
POST
- URL Path:
/api/admin/add
- Request Body:
{"admin_password": "...", "email": "...", "sk": "..."}
- Purpose: Updates an existing email and/or its session key (SK). You can use this to change an email address, update an expired SK, or both at the same time.
- HTTP Method:
POST
- URL Path:
/api/admin/update
- Request Body:
{"admin_password": "...", "email": "[email protected]", "new_email"?: "...", "new_sk"?: "..."}
- You must provide
email
to identify the record. - You must provide at least one of
new_email
ornew_sk
to perform an update.
- You must provide
- Purpose: Removes an email and its SK from the KV store.
- HTTP Method:
POST
- URL Path:
/api/admin/delete
- Request Body:
{"admin_password": "...", "email": "..."}
- Purpose: Adds or deletes multiple email-SK pairs in a single request. This is ideal for initializing or bulk-managing the KV store.
- HTTP Method:
POST
- URL Path:
/api/admin/batch
- Request Body:
{ "admin_password": "...", "actions": [ { "action": "add", "email": "[email protected]", "sk": "sk-abc..." }, { "action": "add", "email": "[email protected]", "sk": "sk-def..." }, { "action": "delete", "email": "[email protected]" } ] }
- Details:
- The
actions
array can contain any number ofadd
ordelete
operations. - For
add
, bothemail
andsk
are required. If an email already exists, its SK will be updated. - For
delete
, onlyemail
is required. - The response will provide a detailed report on the status of each action.
- The
When using the automated deployment script deploy-worker.mjs
, you might encounter some issues due to your environment or updates to the wrangler
tool. Here are some common problems and their solutions.
-
Error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'prompts'
- Cause: The
prompts
package, which the deployment script depends on, has not been installed. - Solution: Run
npm install prompts --save-dev
in your project's root directory to install this missing development dependency.
- Cause: The
-
Error:
'wrangler' is not recognized as an internal or external command...
orcommand not found: wrangler
- Cause:
wrangler
is installed as a local project dependency, and its executable path is not added to your system's PATH environment variable. Callingwrangler
directly in the terminal will cause this error. - Solution: The script has been updated to use
npx wrangler
to execute commands.npx
automatically finds and uses the version ofwrangler
installed locally in the project. If you need to runwrangler
commands manually, be sure to use thenpx wrangler ...
format.
- Cause:
-
Error:
Unknown arguments: json, kv:namespace, list
or the script gets stuck/errors after "Checking Wrangler login status"- Cause: Cloudflare's
wrangler
tool updated its command-line syntax and output format in v4. Old commands likewrangler kv namespace list --json
are no longer valid. - Solution: The
deploy-worker.mjs
script in this project has been updated forwrangler
v4+, enabling it to correctly parse the new command output format and use the new command syntax (e.g.,wrangler kv namespace list
). Please ensure you have pulled the latest code. If you still encounter issues, check yourwrangler
version (npx wrangler --version
) and ensure the commands in the script are compatible.
- Cause: Cloudflare's
-
How do I delete the API token created by the "Deploy" button?
- Cause: When you use the "Deploy with Cloudflare" button, Cloudflare automatically creates an API token with limited permissions to connect to your repository. Deleting the repository or the Worker does not automatically delete this token.
- Solution: You need to manually delete it from your Cloudflare profile:
- Go to the Cloudflare dashboard, click your profile icon in the top right, and select My Profile.
- Navigate to the API Tokens tab on the left.
- Find the token (e.g.,
your-repo-name build token
). - Click the
...
menu on the right and select Delete.
This project is licensed under the MIT License.